blob: 2ac28679032c3f2fe4ffc4e81cec291b37ebe3f5 [file] [log] [blame]
Woyten860e0bc2020-01-29 21:17:14 +01001#!/usr/bin/env bash
2
3set -eux
4
5artifact="$(basename $1)"
Pat Pannutob554e9b2020-06-16 10:01:11 -04006rust_target_folder="$(cd $(dirname $1)/../.. && pwd -P)"
Laura Abbottbb8c8d12020-02-24 15:04:54 -05007if [ -z $APP_HEAP_SIZE ]; then
8 echo "Set APP_HEAP_SIZE to a value"
9 exit 1
10fi
Laura Abbotte0e9eab2020-02-19 16:46:03 -050011
Laura Abbotte9f3b9f2020-02-25 12:23:46 -050012if [ -z $KERNEL_HEAP_SIZE ]; then
13 echo "Set KERNEL_HEAP_SIZE to a value"
14 exit 1
15fi
16
Laura Abbotte0e9eab2020-02-19 16:46:03 -050017case "${PLATFORM}" in
Alistair Francis7ca0c452020-05-19 19:33:08 -070018 "apollo3")
19 tockloader_flags=""
20 binary_name=cortex-m4.elf
21 tockload=n
22 ;;
Alexandru Radovicic0a7cc22020-06-06 17:40:36 +030023 "nucleo_f429zi"|"nucleo_f446re")
24 tockloader_flags=""
25 binary_name=cortex-m4.elf
26 tockload=n
27 ;;
Laura Abbotte0e9eab2020-02-19 16:46:03 -050028 "nrf52"|"nrf52840")
29 tockloader_flags="--jlink --arch cortex-m4 --board nrf52dk --jtag-device nrf52"
30 binary_name=cortex-m4.elf
31 tockload=y
32 ;;
33 "hail")
34 tockloader_flags=""
35 binary_name=cortex-m4.elf
36 tockload=y
37 ;;
Alistair Francisb3f213d2020-03-09 16:58:05 -070038 "hifive1")
Laura Abbotte0e9eab2020-02-19 16:46:03 -050039 tockloader_flags=""
40 binary_name=rv32imac.elf
41 tockload=n
42 ;;
Vochescu Alexandrud5609772020-06-06 17:13:36 +030043 "imxrt1050")
44 tockloader_flags=""
45 binary_name=cortex-m7.elf
46 tockload=n
47 ;;
hotschif6cd66b2020-08-07 14:52:04 +020048 "msp432")
49 tockloader_flags=""
50 binary_name=cortex-m4.elf
51 tockload=n
52 ;;
Laura Abbotte0e9eab2020-02-19 16:46:03 -050053 "opentitan")
54 tockloader_flags=""
55 binary_name=rv32imc.elf
56 tockload=n
57 ;;
58 *)
59 echo "Unknown platform \"${PLATFORM}\""
60 exit 1
61 ;;
62esac
63
Woyten860e0bc2020-01-29 21:17:14 +010064libtock_target_path="${rust_target_folder}/tab/${PLATFORM}/${artifact}"
Laura Abbotte0e9eab2020-02-19 16:46:03 -050065elf_file_name="${libtock_target_path}/${binary_name}"
Woyten860e0bc2020-01-29 21:17:14 +010066tab_file_name="${libtock_target_path}.tab"
67
68mkdir -p "${libtock_target_path}"
69cp "$1" "${elf_file_name}"
70
Laura Abbotte9f3b9f2020-02-25 12:23:46 -050071elf2tab -n "${artifact}" -o "${tab_file_name}" "${elf_file_name}" --stack 2048 --app-heap $APP_HEAP_SIZE --kernel-heap $KERNEL_HEAP_SIZE --protected-region-size=64
Woyten860e0bc2020-01-29 21:17:14 +010072
Laura Abbotte0e9eab2020-02-19 16:46:03 -050073if [ $tockload == "n" ]; then
74 echo "Skipping flashing for platform \"${PLATFORM}\""
75 exit 0
76fi
Woyten860e0bc2020-01-29 21:17:14 +010077
Alistair Francis87518f92020-06-25 09:17:13 -070078if ! [ -x "$(command -v tockloader)" ]; then
79 echo "Skipping flashing as tockloader isn't installed"
80 exit 0
81fi
82
Woyten860e0bc2020-01-29 21:17:14 +010083tockloader uninstall ${tockloader_flags} || true
84tockloader install ${tockloader_flags} "${tab_file_name}"