From d2a37caf9c00f8b0de7a7a307ff5b1f40a49b0c0 Mon Sep 17 00:00:00 2001 From: Alexandru Radovici Date: Sat, 15 Jan 2022 21:12:32 +0200 Subject: [PATCH 1/5] add microbit_v2 layout --- runtime/layouts/microbit_v2.ld | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 runtime/layouts/microbit_v2.ld diff --git a/runtime/layouts/microbit_v2.ld b/runtime/layouts/microbit_v2.ld new file mode 100644 index 00000000..23c7dd10 --- /dev/null +++ b/runtime/layouts/microbit_v2.ld @@ -0,0 +1,11 @@ +/* Layout for the micro:bit v2 board, used by the examples in this repository. */ + +MEMORY { + FLASH (rx) : ORIGIN = 0x00040000, LENGTH = 256K + RAM (rwx) : ORIGIN = 0x20004000, LENGTH = 112K +} + +MPU_MIN_ALIGN = 8K; + +TBF_HEADER_SIZE = 0x48; +INCLUDE libtock_layout.ld From ff632c693ec4e3ebd29073362f3a1547352bdb6a Mon Sep 17 00:00:00 2001 From: Alexandru Radovici Date: Sat, 15 Jan 2022 21:18:12 +0200 Subject: [PATCH 2/5] add to makefile --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index b052f4d5..344e9828 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ usage: @echo "libtock-rs currently includes support for the following platforms:" @echo " - hail" @echo " - nrf52840" + @echo " - microbit_v2" @echo " - nucleo_f429zi" @echo " - nucleo_f446re" @echo " - opentitan" @@ -153,6 +154,14 @@ hail: flash-hail: PLATFORM=hail cargo run $(release) --target=thumbv7em-none-eabi --example $(EXAMPLE) $(features) +.PHONY: microbit_v2 +microbit_v2: + PLATFORM=microbit_v2 cargo build $(release) --target=thumbv7em-none-eabi --examples $(features) + +.PHONY: flash-microbit_v2 +flash-microbit_v2: + PLATFORM=microbit_v2 cargo run $(release) --target=thumbv7em-none-eabi --example $(EXAMPLE) $(features) + .PHONY: nucleo_f429zi nucleo_f429zi: PLATFORM=nucleo_f429zi cargo build $(release) --target=thumbv7em-none-eabi --examples $(features) From fb10cb77db2c230b1faabac360e97ec8be1a1b48 Mon Sep 17 00:00:00 2001 From: Alexandru Radovici Date: Sat, 15 Jan 2022 21:29:13 +0200 Subject: [PATCH 3/5] make flash work with both versions of libtock --- tools/flash.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/flash.sh b/tools/flash.sh index 48bf4866..5460e6b8 100755 --- a/tools/flash.sh +++ b/tools/flash.sh @@ -2,6 +2,8 @@ set -eux +TBF_HEADER=64 + artifact="$(basename $1)" rust_target_folder="$(cd $(dirname $1)/../.. && pwd -P)" if [ -z $APP_HEAP_SIZE ]; then @@ -14,12 +16,24 @@ if [ -z $KERNEL_HEAP_SIZE ]; then exit 1 fi +if [ ! -z $LIBTOCK_PLATFORM ]; then + # we are using libtock2 + PLATFORM=$LIBTOCK_PLATFORM + TBF_HEADER=72 + KERNEL_VERSION="--kernel-major 2 --kernel-minor 0" +fi + case "${PLATFORM}" in "apollo3") tockloader_flags="" binary_name=cortex-m4.elf tockload=n ;; + "microbit_v2") + tockloader_flags="--bundle-apps" + binary_name=cortex-m4.elf + tockload=y + ;; "nucleo_f429zi"|"nucleo_f446re") tockloader_flags="" binary_name=cortex-m4.elf @@ -70,7 +84,7 @@ cp "$1" "${elf_file_name}" STACK_SIZE=$(nm --print-size --size-sort --radix=d "${elf_file_name}" | grep STACK_MEMORY | cut -d " " -f 2) -elf2tab -n "${artifact}" -o "${tab_file_name}" "${elf_file_name}" --stack ${STACK_SIZE} --app-heap $APP_HEAP_SIZE --kernel-heap $KERNEL_HEAP_SIZE --protected-region-size=64 +elf2tab -n "${artifact}" -o "${tab_file_name}" "${elf_file_name}" --stack ${STACK_SIZE} --app-heap $APP_HEAP_SIZE --kernel-heap $KERNEL_HEAP_SIZE --protected-region-size=$TBF_HEADER $KERNEL_VERSION if [ $tockload == "n" ]; then echo "Skipping flashing for platform \"${PLATFORM}\"" From 5d4a70023f4fbe7dafc7925b04f490fef49dca5b Mon Sep 17 00:00:00 2001 From: Alexandru Radovici Date: Sat, 15 Jan 2022 22:07:58 +0200 Subject: [PATCH 4/5] avoid the unbound variable error --- tools/flash.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/flash.sh b/tools/flash.sh index 5460e6b8..97d6f430 100755 --- a/tools/flash.sh +++ b/tools/flash.sh @@ -1,8 +1,16 @@ #!/usr/bin/env bash -set -eux - TBF_HEADER=64 +KERNEL_VERSION="" + +if [ ! -z $LIBTOCK_PLATFORM ]; then + # we are using libtock2 + PLATFORM=$LIBTOCK_PLATFORM + TBF_HEADER=72 + KERNEL_VERSION="--kernel-major 2 --kernel-minor 0" +fi + +set -eux artifact="$(basename $1)" rust_target_folder="$(cd $(dirname $1)/../.. && pwd -P)" @@ -16,13 +24,6 @@ if [ -z $KERNEL_HEAP_SIZE ]; then exit 1 fi -if [ ! -z $LIBTOCK_PLATFORM ]; then - # we are using libtock2 - PLATFORM=$LIBTOCK_PLATFORM - TBF_HEADER=72 - KERNEL_VERSION="--kernel-major 2 --kernel-minor 0" -fi - case "${PLATFORM}" in "apollo3") tockloader_flags="" From 253e4a8c68439da89e767dfd060d2425936f108a Mon Sep 17 00:00:00 2001 From: Alexandru Radovici Date: Sun, 16 Jan 2022 10:59:51 +0200 Subject: [PATCH 5/5] updated layout file to use X and W --- runtime/layouts/microbit_v2.ld | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/layouts/microbit_v2.ld b/runtime/layouts/microbit_v2.ld index 23c7dd10..bf571bfc 100644 --- a/runtime/layouts/microbit_v2.ld +++ b/runtime/layouts/microbit_v2.ld @@ -1,11 +1,9 @@ /* Layout for the micro:bit v2 board, used by the examples in this repository. */ MEMORY { - FLASH (rx) : ORIGIN = 0x00040000, LENGTH = 256K - RAM (rwx) : ORIGIN = 0x20004000, LENGTH = 112K + FLASH (X) : ORIGIN = 0x00040000, LENGTH = 256K + RAM (W) : ORIGIN = 0x20004000, LENGTH = 112K } -MPU_MIN_ALIGN = 8K; - TBF_HEADER_SIZE = 0x48; INCLUDE libtock_layout.ld