Skip to content

Commit f010487

Browse files
committed
build.sh: require board argument, print list of targets
This commit updates the build.sh script to require a board argument, and print a list of available targets when no argument is given. The script also updates the README.md file to document this change. Signed-off-by: Luca Burelli <[email protected]>
1 parent fa2d2f6 commit f010487

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

README.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,24 @@ Download and install the Zephyr SDK for your OS from [here](https://github.com/z
126126
127127
### Build the Loader
128128

129-
To build the loader, run the following commands:
129+
The loader is compiled for each board by running the `./extra/build.sh` script.
130+
The target can be specified either with the Arduino board name (as defined in
131+
boards.txt), or with the Zephyr board name and any additional arguments that
132+
may be required by the Zephyr build system.
133+
134+
For example, to build for the Arduino Portenta H7, you can run either:
130135
```bash
131-
export ZEPHYR_SDK_INSTALL_DIR=$folder_where_you_installed_the_sdk
132-
./extra/build.sh $zephyr_board_name $arduino_variant_board_name
136+
./extra/build.sh portentah7
133137
```
134-
Replace `$zephyr_board_name` and `$arduino_variant_board_name` with the appropriate names for your board.
135138

136-
Example for Arduino Portenta H7:
139+
or:
140+
137141
```bash
138-
./extra/build.sh arduino_portenta_h7//m7 arduino_portenta_h7
142+
./extra/build.sh arduino_portenta_h7//m7
139143
```
140144

141-
The firmwares will be copied to [firmwares](/firmwares) folder.
145+
The firmwares will be copied to [firmwares](/firmwares) folder, and the
146+
associated variant will be updated.
142147

143148
### Flash the Loader
144149

extra/build.sh

+32-13
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,43 @@ if [ x$ZEPHYR_SDK_INSTALL_DIR == x"" ]; then
88
echo "ZEPHYR_SDK_INSTALL_DIR not set and no SDK found"
99
exit 1
1010
fi
11-
echo "ZEPHYR_SDK_INSTALL_DIR not set, using $SDK_PATH"
1211
export ZEPHYR_SDK_INSTALL_DIR=${SDK_PATH}
1312
fi
1413

15-
if [[ $# -eq 0 ]]; then
16-
first_board=$(extra/get_board_details.sh | jq -cr '.[0]')
17-
target=$(jq -cr '.target' <<< "$first_board")
18-
args=$(jq -cr '.args' <<< "$first_board")
14+
if [ $# -eq 0 ] || [ x$1 == x"-h" ] || [ x$1 == x"--help" ]; then
15+
cat << EOF
16+
Usage:
17+
$0 <arduino_board>
18+
$0 <zephyr_board> [<west_args>]
19+
Build the loader for the given target.
20+
21+
When given an <arduino_board> defined in 'boards.txt' (e.g. 'giga'), the actual
22+
Zephyr board target and arguments are taken from that definition.
23+
24+
When given a <zephyr_board>, it is passed as the '-b' argument to 'west build'.
25+
Additional <west_args> are passed as-is at the end of the command line.
26+
27+
Available targets, as defined in 'boards.txt':
28+
29+
EOF
30+
extra/get_board_details.sh |
31+
jq -r 'sort_by(.variant) | .[] | "\t\(.board)\t\(.target) \(.args)"' |
32+
column -ts$'\t'
33+
echo
34+
exit 0
35+
fi
36+
37+
# try to find the board in boards.txt
38+
chosen_board=$(extra/get_board_details.sh | jq -cr ".[] | select(.board == \"$1\") // empty")
39+
if ! [ -z "$chosen_board" ]; then
40+
# found, use the target and args from there
41+
target=$(jq -cr '.target' <<< "$chosen_board")
42+
args=$(jq -cr '.args' <<< "$chosen_board")
1943
else
44+
# expect Zephyr-compatible target and args
2045
target=$1
21-
chosen_board=$(extra/get_board_details.sh | jq -cr ".[] | select(.board == \"$target\") // empty")
22-
if ! [ -z "$chosen_board" ]; then
23-
target=$(jq -cr '.target' <<< "$chosen_board")
24-
args=$(jq -cr '.args' <<< "$chosen_board")
25-
else
26-
shift
27-
args="$*"
28-
fi
46+
shift
47+
args="$*"
2948
fi
3049

3150
echo

0 commit comments

Comments
 (0)