Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alistair23
Copy link
Contributor

@alistair23 alistair23 commented May 13, 2020

Pull Request Overview

This PR updates the current HiFive1 to board in tock to use the revB version instead.

Testing Strategy

Tested by running on a revB board. UART does work, but only when GDB is connected, so something still seems wrong with the UART.

I tried to run an app and it looks like it didn't work.

TODO or Help Wanted

  • Get UART working reliably
  • Update QEMU to support the revB
  • Get apps working
    • Update libtock-rs

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make formatall.

@alistair23 alistair23 requested a review from bradjc May 13, 2020 00:59
@bradjc
Copy link
Contributor

bradjc commented May 13, 2020

I got uart working by:

  1. enabling interrupts later in the main.rs file
  2. disabling and ignoring interrupt numbers >31
  3. using the clock as setup by the bootloader (24 MHz I think)

@alistair23
Copy link
Contributor Author

@bradjc

  1. I think this is because the RTC interrupts are no longer correctly disabled in revB by what Tock was doing. I have fully disabled them in this PR so this shouldn't be required.
  2. Same but PWM
  3. I thought it was still 16MHz, I'll try 24MHz. I see the first 10 characters no problems, I just have trouble seeing all future characters, so I don't think it's a UART clock issue.

Now that I think about it maybe I'm always getting some other non-UART interrupt. I'll dig more into that today.

@bradjc
Copy link
Contributor

bradjc commented May 13, 2020

Yeah that is definitely an interrupt-related issue. handle_interrupt in the uart is never getting called, so only the first 10 print.

@alistair23
Copy link
Contributor Author

Ah, figured it out. It looks like interrupts aren't correctly re-enabled after being globally disabled.

@alistair23 alistair23 force-pushed the alistair/hifive-revb branch 4 times, most recently from 7c3dc5b to 2867f8c Compare May 13, 2020 21:08
@alistair23
Copy link
Contributor Author

The Travis failure is because it's QEMU cache is out of date.

@bradjc
Copy link
Contributor

bradjc commented May 13, 2020

I tried running libtock-c/blink. I get:

␛[1F␛[0J␛[?25h␛[0;39;49mBench Clock Reset Complete

ATE0-->ATE0
OK
AT+BLEINIT=0-->OK
AT+CWMODE=0-->OK

HiFive1 initialization complete.
Entering main loop.


Kernel panic at <::core::macros::panic macros>:5:
	"Process blink had a fault"
	Kernel version release-1.5-143-g2dfebdd92

---| No debug queue found. You can set it with the DebugQueue component.

---| RISC-V Machine State |---
Cause (mcause): Store/AMO access fault (interrupt=false, exception code=

with this libtock-c diff from the riscv branch:

diff --git a/Configuration.mk b/Configuration.mk
index 6a9fee7..786d1e9 100644
--- a/Configuration.mk
+++ b/Configuration.mk
@@ -39,6 +39,7 @@ ifndef ELF2TAB_EXISTS
 endif
 ELF2TAB_ARGS += -n $(PACKAGE_NAME)
 ELF2TAB_ARGS += --stack $(STACK_SIZE) --app-heap $(APP_HEAP_SIZE) --kernel-heap $(KERNEL_HEAP_SIZE)
+ELF2TAB_ARGS += --fixed-address-ram 0x80002400 --fixed-address-flash 0x20040040

 # Special extra flag for RISC-V since it does not have PIC support.
 ELF2TAB_ARGS += --protected-region-size=64
diff --git a/userland_generic.ld b/userland_generic.ld
index bf69caa..bd12da1 100644
--- a/userland_generic.ld
+++ b/userland_generic.ld
@@ -15,8 +15,8 @@ ENTRY(_start)
  * actual location in flash where the app is placed.
  */
 MEMORY {
-    FLASH (rx) : ORIGIN = 0x4043003c, LENGTH = PROG_LENGTH
-    SRAM (RWX) : ORIGIN = 0x80004000, LENGTH = RAM_LENGTH
+    FLASH (rx) : ORIGIN = 0x20040040, LENGTH = PROG_LENGTH
+    SRAM (RWX) : ORIGIN = 0x80002400, LENGTH = RAM_LENGTH
 }

 SECTIONS {

this make command:

make APP_HEAP_SIZE=1 STACK_SIZE=1000

and this tock diff:

diff --git a/boards/hifive1/src/main.rs b/boards/hifive1/src/main.rs
index e38b29c99..268dc7187 100644
--- a/boards/hifive1/src/main.rs
+++ b/boards/hifive1/src/main.rs
@@ -36,7 +36,7 @@ const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultRespons

 // RAM to be shared by all application processes.
 #[link_section = ".app_memory"]
-static mut APP_MEMORY: [u8; 5 * 1024] = [0; 5 * 1024];
+static mut APP_MEMORY: [u8; (10* 1024)-3072] = [0; (10 * 1024)-3072];

 /// Dummy buffer that causes the linker to reserve enough space for the stack.
 #[no_mangle]

The fixed-addresses stuff if WIP, but it's just for checking and can be ignored. I also merged pr #1845 into this PR branch.

@alistair23
Copy link
Contributor Author

Thanks @bradjc . Just to clarify are you saying that apps work (with libtock changes)?

If so I think this is ready to merge.

On the OpenOCD front I have sent patches to OpenOCD, the RISC-V fork of OpenOCD and libjaylink to add support. Once they are merged OpenOCD should be working.

@alistair23
Copy link
Contributor Author

I can't get the apps to fit. Event the blinky or hello_world libtock-rs apps are too big.

@alistair23 alistair23 force-pushed the alistair/hifive-revb branch from ba32b30 to 2de9723 Compare May 14, 2020 00:28
@alistair23
Copy link
Contributor Author

Got it! I have pushed the working version.

  • Changed all the addresses to match revB
  • Disable PWM and RTC
  • Fixup interrupt handling
  • Fixup OpenOCD commands (OpenOCD fixes pending in upstream repos)
  • Enable PMP
  • Add the LED capsule
  • Increase app size

I have tested on libtock-rs and will send the patches once this is merged. All I need is an address change and reduce the app stack size to fit.

@bradjc I forced pushed over your readme update. Can you apply it again. Sorry about that.

@alistair23 alistair23 marked this pull request as ready for review May 14, 2020 00:32
@bradjc
Copy link
Contributor

bradjc commented May 14, 2020

My status:

  • I still can't get libtock-c/blink to run. I didn't correctly update the linker file before, but I think I have fixed that now. What I am seeing is a lot of issues with string formatting. On a panic I see:
␛[1F␛[0J␛[?25h␛[0;39;49mBench Clock Reset Complete

ATE0--> Send Flag error: #0 #0 #0 #0 AT+BLEINIT=0-->AT+BLEINIT=0
OK
AT+CWMODE=0-->AT+CWMODE=0
OK

HiFive1 initialization complete.
Entering main loo

Kernel panic at <::core::macros::panic macros>:5:
	"Process blink had a fault"
	Kernel version release-1.5-136-gafe47d3b3

---| Debug buffer not empty. Flushing. May repeat some of last message(s):


---| No debug queue found. You can set it with the DebugQueue component.

---| RISC-V Machine State |---
Cause (mcause): Store/AMO access fault (interrupt=false, exception code=␁

If I switch to today's nightly, I get:

␛[1F␛[0J␛[?25h␛[0;39;49mBench Clock Reset Complete

ATE0-->ATE0
OK
AT+BLEINIT=0-->OK
AT+CWMODE=0-->OK

HiFive1 initialization complete.
Entering main loop.
Pidx 41
Pidx

Kernel panic at /Users/bradjc/.rustup/toolchains/nightly-2020-05-14-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/macros/mod.rs:16:
	"Process blink had a fault"
	Kernel version release-1.5-136-gafe47d3b3

---| Debug buffer not empty. Flushing. May repeat some of last message(s):

Pidx 46
Pidx 47
Pidx 49
Pidx 50

---| No debug queue found. You can set it with the DebugQueue component.

---| RISC-V Machine State |---
Cause (mcause): Machine external interrupt (interrupt=true, exception code=11)
Value (mtval):  0x00000000

System register dump:
 mepc:    0x200118F8    mstatus:     0x00000088
 mcycle:  0x01F213F8    minstret:    0x00BFDFC2
 mtvec:   0x20010100
 mstatus:
  uie:    false
  sie:    false
  mie:    true
  upie:   false
  spie:   false
  mpie:   true
  spp:    false
 mie:   0x00000088   mip:   0x00000800
  usoft:  false               false
  ssoft:  false               false
  msoft:  true                false
  utimer: false               false
  stimer: false               false
  mtimer: true                false
  uext:   false               false
  sext:   false               false
  mext:   false               true

---| App Status |---
App: blink   -   [Fault]
 Events Queued: 0   Syscall Count: 3   Dropped Callback Count: 0
 Restart Count: 0
 Last Syscall: Some(MEMOP { operand:

And if I make a custom syscall formatter I can get the full print out (sometimes):

␛[1F␛[0J␛[?25h␛[0;39;49mBench Clock Reset Complete

ATE0-->ATE0
OK
AT+BLEINIT=0-->OK
AT+CWMODE=0-->OK

HiFive1 initialization complete.
Entering main loop.
Pidx 48
Pidx

Kernel panic at /Users/bradjc/.rustup/toolchains/nightly-2020-05-14-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/macros/mod.rs:16:
	"Process blink had a fault"
	Kernel version release-1.5-136-gafe47d3b3

---| No debug queue found. You can set it with the DebugQueue component.

---| RISC-V Machine State |---
Cause (mcause): Machine external interrupt (interrupt=true, exception code=11)
Value (mtval):  0x00000000

System register dump:
 mepc:    0x200118F8    mstatus:     0x00000088
 mcycle:  0x023353A4    minstret:    0x00D30022
 mtvec:   0x20010100
 mstatus:
  uie:    false
  sie:    false
  mie:    true
  upie:   false
  spie:   false
  mpie:   true
  spp:    false
 mie:   0x00000088   mip:   0x00000800
  usoft:  false               false
  ssoft:  false               false
  msoft:  true                false
  utimer: false               false
  stimer: false               false
  mtimer: true                false
  uext:   false               false
  sext:   false               false
  mext:   false               true

---| App Status |---
App: blink   -   [Fault]
 Events Queued: 0   Syscall Count: 3   Dropped Callback Count: 0
 Restart Count: 0
 Last Syscall: Some(yay
)

 ╔═══════════╤══════════════════════════════════════════╗
 ║  Address  │ Region Name    Used | Allocated (bytes)  ║
 ╚0x80003B14═╪══════════════════════════════════════════╝
             │ ▼ Grant        1012 |   1012
  0x80003720 ┼───────────────────────────────────────────
             │ Unused
  0x80003000 ┼───────────────────────────────────────────
             │ ▲ Heap            ? |      ?               S
  ?????????? ┼─────────────────────────────────────────── R
             │ Data              ? |      ?               A
  0x800027E8 ┼─────────────────────────────────────────── M
             │ ▼ Stack          16 |   1000
  0x800027D8 ┼───────────────────────────────────────────
             │ Unused
  0x80002400 ┴───────────────────────────────────────────
             .....
  0x20042000 ┬─────────────────────────────────────────── F
             │ App Flash      8128                        L
  0x20040040 ┼─────────────────────────────────────────── A
             │ Protected        64                        S
  0x20040000 ┴─────────────────────────────────────────── H

 R0 : 0x00000000    R16: 0x00000000
 R1 : 0x200402F6    R17: 0x00000000
 R2 : 0x800027D8    R18: 0x00000000
 R3 : 0x00000000    R19: 0x00000000
 R4 : 0x00000000    R20: 0x00000000
 R5 : 0x80002EEC    R21: 0x00000000
 R6 : 0x00000000    R22: 0x00000000
 R7 : 0x00000000    R23: 0x00000000
 R8 : 0x20040040    R24: 0x00000000
 R9 : 0x800027E8    R25: 0x00000000
 R10: 0x80000BE8    R26: 0x00000000
 R11: 0x200407E4    R27: 0x00000000
 R12: 0x80001578    R28: 0x00000000
 R13: 0x80001598    R29: 0x00000000
 R14: 0x80001598    R30: 0x80002FBC
 R15: 0x80000BE8    R31: 0x80002F54
 PC : 0x20040530
 SP:  0x800027D8

To debug, run `make debug RAM_START=0x80002400 FLASH_INIT=0x20040068`
in the app's folder and open the .lst file.

Othertimes it gets stuck here:

 ║  Address  │ Region Name    Used | Allocated (bytes)  ║
 ╚

I'm not sure what is going on there.

@bradjc
Copy link
Contributor

bradjc commented May 14, 2020

Also I seem to get different behavior sometimes, or immediately after flashing the kernel, or after unplugging and replugging the board.

@alistair23
Copy link
Contributor Author

Hmm... It seems like you are getting strange interrupt as well.

@alistair23
Copy link
Contributor Author

Maybe try disabling PMP? See if that helps

bradjc and others added 10 commits May 14, 2020 13:02
Signed-off-by: Alistair Francis <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
Re-write the interrupt handling logic to follow what the Ibex chip does.
This is a simpler implemenation and fixes cases where interrupts aren't
re-enabled after being disabled.

Signed-off-by: Alistair Francis <[email protected]>
This is already turned off in OpenOCD, plus the current way in Tock
doesn't work, so let's remove it.

Signed-off-by: Alistair Francis <[email protected]>
The SiFive FE310-G002 chip supports PMP with 8 regions and a 4 byte
granularity, enable it for the chip.

Signed-off-by: Alistair Francis <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
Use a fork of QEMU (patches are pending on the mailing list) that
supports the hifve1 and OpenTitan.

Signed-off-by: Alistair Francis <[email protected]>
@alistair23 alistair23 force-pushed the alistair/hifive-revb branch from afe47d3 to 6f349c4 Compare May 14, 2020 20:37
@alistair23
Copy link
Contributor Author

Draft PR send to libtock-rs: tock/libtock-rs#179

@bradjc Two things I noticed.

  1. Sometimes the prints will just hang on the board and QEMU with the Tock release build. Try the debug build. I just reduced the app space (pushed to this PR) to allow debug builds to work again.

  2. Try to run it in QEMU. Use the version built by this PR. If you can reproduce the failure in QEMU it's easier to test.

@bradjc
Copy link
Contributor

bradjc commented May 15, 2020

It's actually blinking on the board! Using the debug build was the trick.

@alistair23
Copy link
Contributor Author

alistair23 commented May 15, 2020

Awesome!

I can't login to Travis, would someone mind clearing the cache: Is it ok if I clear the Travis cache? https://docs.travis-ci.com/user/caching/#clearing-caches

Then we should be able to merge this

@alistair23 alistair23 force-pushed the alistair/hifive-revb branch from 6f349c4 to 82b16d5 Compare May 15, 2020 15:55
alistair23 and others added 2 commits May 15, 2020 10:26
Increase the app memory size to allow more/bigger apps to fit.

Signed-off-by: Alistair Francis <[email protected]>
@alistair23 alistair23 force-pushed the alistair/hifive-revb branch from 82b16d5 to efd0489 Compare May 15, 2020 17:35
@alistair23
Copy link
Contributor Author

Cleared the Travis cache, the build is passing now :)

@bradjc
Copy link
Contributor

bradjc commented May 15, 2020

Should we change the makefile to /debug/ rather than /release/? Something about LTO breaks things for me (I think LTO is the only difference...), and I've only gotten this to work with the debug version.

@alistair23
Copy link
Contributor Author

I don't think so, the release version works with libtock-rs and it's so space constrained that the debug build makes a substantial difference.

@bradjc
Copy link
Contributor

bradjc commented May 15, 2020

I wonder why libtock-rs would be different. I can't get libtock-rs to work at the moment. Is it easy to trigger a fault? Does the fault message print with the release kernel build?

@alistair23
Copy link
Contributor Author

If you set a stack size that is too large it will fault. The fault messages aren't printed fully in the release build.

Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's definitely still something wrong that ends up with print formatting breaking and other weird issues, but this is overall a good step towards hifive1b support.

One other note: the 16k RAM is very limiting. This isn't really a suitable Tock board, and hopefully other easily available RISC-V hardware will continue to come out and we can replace this with something.

@bradjc
Copy link
Contributor

bradjc commented May 18, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented May 18, 2020

Build failed:

@alistair23
Copy link
Contributor Author

Argh! It looks like Bors has it's own Travis cache. Can that be cleared?

@ppannuto
Copy link
Member

bors retry

just did

@bors bors bot merged commit 152189f into tock:master May 18, 2020
@alistair23 alistair23 deleted the alistair/hifive-revb branch May 18, 2020 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants