Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtock-rs apps don't really fit on the HiFive1 #156

Open
alistair23 opened this issue Feb 24, 2020 · 1 comment
Open

libtock-rs apps don't really fit on the HiFive1 #156

alistair23 opened this issue Feb 24, 2020 · 1 comment

Comments

@alistair23
Copy link
Collaborator

Currently libtock-rs apps barely fit on the HiFive1 board.

Build the libtock-rs examples

PLATFORM=riscv32 cargo build --target=riscv32imac-unknown-none-elf --examples

Create a tbf file for the hello_world example

/scratch/alistair/software/tock/elf2tab/target/debug/elf2tab -o ./Tock-app.tab ./target/riscv32imac-unknown-none-elf/debug/examples/hello_world --stack 2048 --app-heap 1024 --kernel-heap 1024 -v --protected-region-size=64

Run the TBF file with master Tock (c94059d3e25dc635e682facff4894ef43b9aca0e and no debug) and QEMU:

/scratch/alistair/software/qemu/build/riscv32-softmmu/qemu-system-riscv32 -m 1G -M sifive_e -kernel /scratch/alistair/software/tock/tock/boards/hifive1/target/riscv32imac-unknown-none-elf/release/hifive1 -device loader,file=/scratch/alistair/software/tock/libtock-rs/target/riscv32imac-unknown-none-elf/debug/examples/hello_world.tbf,addr=0x20430000 -nographic
HiFive1 initialization complete. Entering main loop
Hello Tock World

It works and runs correctly :)

Now try to run the timer app

/scratch/alistair/software/tock/elf2tab/target/debug/elf2tab -o ./Tock-app.tab ./target/riscv32imac-unknown-none-elf/debug/examples/timer --stack 2048 --app-heap 1024 --kernel-heap 1024 -v --protected-region-size=64
/scratch/alistair/software/qemu/build/riscv32-softmmu/qemu-system-riscv32 -m 1G -M sifive_e -kernel /scratch/alistair/software/tock/tock/boards/hifive1/target/riscv32imac-unknown-none-elf/release/hifive1 -device loader,file=/scratch/alistair/software/tock/libtock-rs/target/riscv32imac-unknown-none-elf/debug/examples/timer.tbf,addr=0x20430000 -nographic

and you will see this:

HiFive1 initialization complete. Entering main loop
...
---| App Status |---
App:    -   [Running]
 Events Queued: 0   Syscall Count: 5   Dropped Callback Count: 0
 Restart Count: 0
 Last Syscall: None

 ╔═══════════╤══════════════════════════════════════════╗
 ║  Address  │ Region Name    Used | Allocated (bytes)  ║
 ╚0x800036F8═╪══════════════════════════════════════════╝
             │ ▼ Grant         756 |    756          
  0x80003404 ┼───────────────────────────────────────────
             │ Unused
  0x80003004 ┼───────────────────────────────────────────
             │ ▲ Heap         1024 |   2048               S
  0x80002C04 ┼─────────────────────────────────────────── R
             │ Data              4 |      4               A
  0x80002C00 ┼─────────────────────────────────────────── M
             │ ▼ Stack        3136 |   2048 EXCEEDED!
  0x80001FC0 ┼───────────────────────────────────────────
             │ Unused
  0x80002400 ┴───────────────────────────────────────────
             .....
  0x20440000 ┬─────────────────────────────────────────── F
             │ App Flash     65472                        L
  0x20430040 ┼─────────────────────────────────────────── A
             │ Protected        64                        S
  0x20430000 ┴─────────────────────────────────────────── H
...

If you enable debug options for the Tock kernel you will see this:

HiFive1 initialization complete. Entering main loop
Loading processes from flash=0x20430000 into sram=[0x80002400:0x80003800]
Loaded process[0] from flash=[0x20430000:0x20440000] into sram=[0x80002400:0x800036F8] = Some("")
[!] flash=0x20440000 - not a valid TBF header
Loaded process[1] from flash=[0x20440000:0x20440000] into sram=[0x800036F8:0x800036F8] = None


Kernel panic at /scratch/alistair/software/tock/tock/chips/e310x/src/chip.rs:152:
	"load fault 10
"
	Kernel version release-1.4-627-gc94059d3

---| RISC-V Machine State |---
Cause (mcause): Load access fault (interrupt=false, exception code=5)
Value (mtval):  0x00000010
...

If you enable PMP on Tock then you can't even load the app

HiFive1 initialization complete. Entering main loop
Loading processes from flash=0x20430000 into sram=[0x80002400:0x80003800]
[!] flash=[0x20430000:0x20440000] process=Some("") - couldn't allocate memory region of size >= 0x13A0
Loaded process[0] from flash=[0x20430000:0x20440000] into sram=[0x80002400:0x80002400] = None
[!] flash=0x20440000 - not a valid TBF header
Loaded process[1] from flash=[0x20440000:0x20440000] into sram=[0x80002400:0x80002400] = None

Basically it's really hard to fit the libtock-rs apps with Tock for the HiFive1. As it's the only board supported in QEMU this is a pain. It might be worth looking at trying to shrink the app sizes.

@alistair23
Copy link
Collaborator Author

Increasing the RAM size (in QEMU and Tock) and then the application size and Tock stack size fixes all of the memory issues, but that won't work on HW.

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

No branches or pull requests

1 participant