aboutsummaryrefslogtreecommitdiffstats
path: root/demos/NRF51/OSHCHIP_V1.0/patch_hex.sh
blob: 81f7c32d33ae02b4c0cb0f7aa2cc6ebca8376b3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

# The official [OSHChip CMSIS-DAP programmer] provides also
# a MBED-type Mass Storage flashing mechanism - copying
# a hex file to the external "drive" flashes the firmware
# to the attached OSHChip.

# However this MSD flasher expect the hex file to begin with the
# "Extended Linear Address" (e.g. ":020000040000FA"); this happens
# automatically if the firmware is >= 64kB, but MBED online compiler
# does this always. ARM GCC suite does not. Hence this script.

# [OSHChip CMSIS-DAP programmer]: http://oshchip.org/products/OSHChip_CMSIS_DAP_V1.0_Product.html

DIR=build
FILEBASE=ch
FILEEXT=hex
FILE="${FILEBASE}.${FILEEXT}"

if [ ! -f "${DIR}/${FILE}" ]; then
  echo "Build the firmware first."
  exit 1
fi

if $(head "${DIR}/${FILE}" | grep -q ":02000004") ; then
	echo "The format of ${DIR}/${FILE} is already good."
	exit 2
fi

echo ":020000040000FA" > "${DIR}/${FILEBASE}_patched.hex"
cat "${DIR}/${FILE}" >> "${DIR}/${FILEBASE}_patched.hex"