Update flash.sh to better handle RISC-V targets The current flash.sh script doesn't handle RISC-V targets which means that even if you build with cargo, the actual tbf binaries don't get built. Update the flash.sh script to handle this case. As part of this work, also update the linker scripts for RISC-V targets. These need to be updated to work the protected region argument in elf2tab
diff --git a/flash.sh b/flash.sh index a67312c..b241a7a 100755 --- a/flash.sh +++ b/flash.sh
@@ -4,8 +4,36 @@ artifact="$(basename $1)" rust_target_folder="$(readlink -f $(dirname $1)/../..)" + +case "${PLATFORM}" in + "nrf52"|"nrf52840") + tockloader_flags="--jlink --arch cortex-m4 --board nrf52dk --jtag-device nrf52" + binary_name=cortex-m4.elf + tockload=y + ;; + "hail") + tockloader_flags="" + binary_name=cortex-m4.elf + tockload=y + ;; + "riscv32") + tockloader_flags="" + binary_name=rv32imac.elf + tockload=n + ;; + "opentitan") + tockloader_flags="" + binary_name=rv32imc.elf + tockload=n + ;; + *) + echo "Unknown platform \"${PLATFORM}\"" + exit 1 + ;; +esac + libtock_target_path="${rust_target_folder}/tab/${PLATFORM}/${artifact}" -elf_file_name="${libtock_target_path}/cortex-m4.elf" +elf_file_name="${libtock_target_path}/${binary_name}" tab_file_name="${libtock_target_path}.tab" mkdir -p "${libtock_target_path}" @@ -13,18 +41,10 @@ elf2tab -n "${artifact}" -o "${tab_file_name}" "${elf_file_name}" --stack 2048 --app-heap 1024 --kernel-heap 1024 --protected-region-size=64 -case "${PLATFORM}" in - "nrf52"|"nrf52840") - tockloader_flags="--jlink --arch cortex-m4 --board nrf52dk --jtag-device nrf52" - ;; - "hail") - tockloader_flags="" - ;; - *) - echo "Tockloader flags unknown for platform \"${PLATFORM}\"" - exit 1 - ;; -esac +if [ $tockload == "n" ]; then + echo "Skipping flashing for platform \"${PLATFORM}\"" + exit 0 +fi tockloader uninstall ${tockloader_flags} || true tockloader install ${tockloader_flags} "${tab_file_name}"
diff --git a/layout_opentitan.ld b/layout_opentitan.ld index ab475fc..db48eef 100644 --- a/layout_opentitan.ld +++ b/layout_opentitan.ld
@@ -1,9 +1,16 @@ /* Layout for the RISC-V 32 boards, used by the examples in this repository. */ MEMORY { - /* The TBF header region is 32 bytes (0x20) */ - FLASH (rx) : ORIGIN = 0x20030020, LENGTH = 32M - SRAM (rwx) : ORIGIN = 0x10000000, LENGTH = 512K + /* + * The TBF header can change in size so use 0x40 combined with + * --protected-region-size with elf2tab to cover a header upto that + * size. + * + * Note that the SRAM address may need to be changed depending on + * the kernel binary, check for the actual address of APP_MEMORY! + */ + FLASH (rx) : ORIGIN = 0x20030040, LENGTH = 32M + SRAM (rwx) : ORIGIN = 0x10002800, LENGTH = 512K } /*
diff --git a/layout_riscv32.ld b/layout_riscv32.ld index e3aba2c..df7d4b6 100644 --- a/layout_riscv32.ld +++ b/layout_riscv32.ld
@@ -1,9 +1,16 @@ /* Layout for the RISC-V 32 boards, used by the examples in this repository. */ MEMORY { - /* The TBF header region is 32 bytes (0x20) */ - FLASH (rx) : ORIGIN = 0x20430020, LENGTH = 32M - SRAM (rwx) : ORIGIN = 0x80000000, LENGTH = 512K + /* + * The TBF header can change in size so use 0x40 combined with + * --protected-region-size with elf2tab to cover a header upto that + * size. + * + * Note that the SRAM address may need to be changed depending on + * the kernel binary, check for the actual address of APP_MEMORY! + */ + FLASH (rx) : ORIGIN = 0x20430040, LENGTH = 32M + SRAM (rwx) : ORIGIN = 0x80002400, LENGTH = 512K } /*