Skip to content

Commit bde81be

Browse files
committed
Automate an524 application image update
The python script `Arm/MPS3_AN524/tools/flash.py` updates an application image onto the Arm MPS3 FPGA Prototyping Board. The build script `Arm/MPS3_AN524/tools/rebuild.sh` accepts the MCC serial port to reboot the connected board. Signed-off-by: Devaraj Ranganna <devaraj.ranganna@linaro.org>
1 parent fe4ee52 commit bde81be

File tree

3 files changed

+118
-1
lines changed

3 files changed

+118
-1
lines changed

Arm/MPS3_AN524/readme.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ image that can be run on the MPS3 FPGA prototyping board or in QEMU.
2121

2222
> * The [Arm MPS3 FPGA Prototyping Board](https://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps3) (MPS3)
2323
> * The [AN524 SSE-200 FPGA image for MPS3](https://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/download-fpga-images)
24+
* We've automated the process of [updating application image onto the Arm MPS3
25+
FPGA Prototyping Board](#updating-application-image). If you wish to use this
26+
, then `pyserial` python module should be installed:
27+
> * pip3 install pyserial
2428
2529
## System Setup
2630

@@ -77,6 +81,21 @@ and the `srec_cat` utility, which is commonly part of the `srecord` packace on l
7781
distributions. Build the sample with the provided `rebuild.sh` tool.
7882

7983
```bash
80-
$ cd ARM/MPS3_AN524
84+
$ cd Arm/MPS3_AN524
8185
$ tools/rebuild.sh
8286
```
87+
88+
## Updating application image
89+
> This has only been tested on OS X, some modifications might be needed to make
90+
`Arm/MPS3_AN524/tools/flash.py` to work in Windows/Linux environments.
91+
92+
The python script `Arm/MPS3_AN524/tools/flash.py` automates steps needed to
93+
update an application image onto the Arm MPS3 FPGA Prototyping Board. if you
94+
wish to use this, then add `-f` command line option while invoking `rebuild.sh`.
95+
If `-f` option is used then FPGA MCC serial port must be provided using `-p`
96+
option.
97+
98+
```bash
99+
$ cd Arm/MPS3_AN524
100+
$ tools/rebuild.sh -f -p /dev/tty.usbserial-14543100
101+
```

Arm/MPS3_AN524/tools/flash.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2021 Linaro Limited.
2+
3+
import pathlib
4+
import serial
5+
import shutil
6+
import sys
7+
import time
8+
9+
# Serial baudrate
10+
SERIAL_BAUDRATE = 115200
11+
12+
# Path to image file
13+
BIN_FILE = pathlib.Path(__file__).parent.absolute().parent / "build" / "app" / "mps3_524.bin"
14+
# Path where image file should be copied
15+
BIN_DEST_PATH = "/Volumes/V2M-MPS3/SOFTWARE"
16+
17+
def initiate_reboot(port):
18+
try:
19+
serial_port = serial.Serial(port, SERIAL_BAUDRATE, exclusive=False)
20+
except serial.SerialException:
21+
print("ERROR: Unable to update application image onto FPGA board")
22+
print(f"ERROR: Unable to open serial port {port}")
23+
sys.exit(1)
24+
else:
25+
# Send reboot command to mcc terminal
26+
# Wring the string `reboot\n` is causing data loss. Therefore send
27+
# individual characters and introduce 100ms delay between each
28+
# character.
29+
serial_port.write(b'r')
30+
time.sleep(0.1)
31+
serial_port.write(b'e')
32+
time.sleep(0.1)
33+
serial_port.write(b'b')
34+
time.sleep(0.1)
35+
serial_port.write(b'o')
36+
time.sleep(0.1)
37+
serial_port.write(b'o')
38+
time.sleep(0.1)
39+
serial_port.write(b't')
40+
time.sleep(0.1)
41+
serial_port.write(b'\n')
42+
43+
def copy_application_image():
44+
try:
45+
shutil.copy2(BIN_FILE, BIN_DEST_PATH, follow_symlinks=False)
46+
except OSError as e:
47+
print("ERROR: Unable to update application image onto FPGA board")
48+
print(f"ERROR: {e.strerror} : {e.filename}")
49+
sys.exit(1)
50+
51+
if __name__ == '__main__':
52+
# Copy application image onto USB drive
53+
copy_application_image()
54+
# Initiate reboot
55+
initiate_reboot(sys.argv[1])

Arm/MPS3_AN524/tools/rebuild.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,44 @@
33

44
#!/bin/bash
55

6+
# Check if user wishes to auto update application image onto connected board
7+
# after successful build.
8+
HELP_STR="
9+
Usage: rebuild.sh [-f] [-p=serial port] \n \
10+
Build Azure RTOS application image \n \
11+
Optional: \n \
12+
\t-f : Update generated image onto connected board \n \
13+
\t-p=serial port : MCC Serial port name, mandatory with -f option
14+
"
15+
16+
flash_option=false
17+
while getopts "hfp:" option; do
18+
case ${option} in
19+
f )
20+
flash_option=true
21+
;;
22+
p )
23+
if [ "$flash_option" = false ]; then
24+
echo "ERROR: -p option can only be used with -f option"
25+
exit 1
26+
fi
27+
serial_port=$OPTARG
28+
;;
29+
h )
30+
echo $HELP_STR
31+
exit 1
32+
;;
33+
\? )
34+
echo $HELP_STR
35+
exit 1
36+
esac
37+
done
38+
# shift $((OPTIND -1))
39+
if [ "$flash_option" = true ] && [ "$serial_port" = "" ]; then
40+
echo "ERROR: -p option is mandatory when -f option is used"
41+
exit 1
42+
fi
43+
644
# Use paths relative to this script's location
745
SCRIPT=$(realpath "$0")
846
SCRIPTDIR=$(dirname "$SCRIPT")
@@ -23,3 +61,8 @@ cmake -B"$BUILDDIR" -GNinja -DCMAKE_BUILD_TYPE=$BUILDTYPE $BASEDIR
2361

2462
# And then do the build
2563
cmake --build $BUILDDIR
64+
65+
# Check if build succeeded
66+
if [ $? -eq 0 ] && [ "$flash_option" = true ]; then
67+
python3 $SCRIPTDIR/flash.py $serial_port
68+
fi

0 commit comments

Comments
 (0)