kinetis/check-fcfield: merge hex and elf script
This commit is contained in:
parent
8fe12bc82c
commit
963bbe75ba
@ -32,7 +32,7 @@ endif
|
|||||||
export OPENOCD_CONFIG ?= $(RIOTBOARD)/common/frdm/dist/openocd-$(CPU_FAMILY).cfg
|
export OPENOCD_CONFIG ?= $(RIOTBOARD)/common/frdm/dist/openocd-$(CPU_FAMILY).cfg
|
||||||
|
|
||||||
# Check the flash configuration field before flashing
|
# Check the flash configuration field before flashing
|
||||||
export PRE_FLASH_CHECK_SCRIPT = $(RIOTCPU)/$(CPU)/dist/check-fcfield-elf.sh
|
export PRE_FLASH_CHECK_SCRIPT = $(RIOTCPU)/$(CPU)/dist/check-fcfield.sh
|
||||||
|
|
||||||
# setup serial terminal
|
# setup serial terminal
|
||||||
include $(RIOTMAKE)/tools/serial.inc.mk
|
include $(RIOTMAKE)/tools/serial.inc.mk
|
||||||
|
|||||||
@ -56,7 +56,7 @@ endif
|
|||||||
export OPENOCD_PRE_VERIFY_CMDS += \
|
export OPENOCD_PRE_VERIFY_CMDS += \
|
||||||
-c 'load_image $(RIOTCPU)/$(CPU)/dist/wdog-disable.bin 0x20000000 bin' \
|
-c 'load_image $(RIOTCPU)/$(CPU)/dist/wdog-disable.bin 0x20000000 bin' \
|
||||||
-c 'resume 0x20000000'
|
-c 'resume 0x20000000'
|
||||||
export PRE_FLASH_CHECK_SCRIPT = $(RIOTCPU)/$(CPU)/dist/check-fcfield-elf.sh
|
export PRE_FLASH_CHECK_SCRIPT = $(RIOTCPU)/$(CPU)/dist/check-fcfield.sh
|
||||||
|
|
||||||
FLASHDEPS += $(RIOTCPU)/$(CPU)/dist/wdog-disable.bin
|
FLASHDEPS += $(RIOTCPU)/$(CPU)/dist/wdog-disable.bin
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export OPENOCD_PRE_VERIFY_CMDS += \
|
|||||||
-c 'load_image $(RIOTCPU)/$(CPU)/dist/wdog-disable.bin 0x20000000 bin' \
|
-c 'load_image $(RIOTCPU)/$(CPU)/dist/wdog-disable.bin 0x20000000 bin' \
|
||||||
-c 'resume 0x20000000'
|
-c 'resume 0x20000000'
|
||||||
export OPENOCD_EXTRA_INIT
|
export OPENOCD_EXTRA_INIT
|
||||||
export PRE_FLASH_CHECK_SCRIPT = $(RIOTCPU)/$(CPU)/dist/check-fcfield-elf.sh
|
export PRE_FLASH_CHECK_SCRIPT = $(RIOTCPU)/$(CPU)/dist/check-fcfield.sh
|
||||||
|
|
||||||
export DEBUG_ADAPTER ?= dap
|
export DEBUG_ADAPTER ?= dap
|
||||||
|
|
||||||
|
|||||||
24
cpu/kinetis/dist/check-fcfield-elf.sh
vendored
24
cpu/kinetis/dist/check-fcfield-elf.sh
vendored
@ -1,24 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# Anti brick check script for Freescale Kinetis MCUs.
|
|
||||||
#
|
|
||||||
# This script is supposed to be called from RIOTs
|
|
||||||
# unified OpenOCD script (dist/tools/openocd/openocd.sh).
|
|
||||||
#
|
|
||||||
# @author Jonas Remmert <j.remmert@phytec.de>
|
|
||||||
# @author Johann Fischer <j.fischer@phytec.de>
|
|
||||||
|
|
||||||
ELFFILE=$1
|
|
||||||
ACTUAL_FCFIELD=$(arm-none-eabi-objdump -j.fcfield -s "${ELFFILE}" | awk '/^ 0400 / {print $2 $3 $4 $5}')
|
|
||||||
# Allow any FOPT flags configuration (".." in the pattern)
|
|
||||||
EXPECTED_FCFIELD="^fffffffffffffffffffffffffe..ffff$"
|
|
||||||
|
|
||||||
if ! printf '%s' "${ACTUAL_FCFIELD}" | grep -q "${EXPECTED_FCFIELD}" ; then
|
|
||||||
echo "Danger of bricking the device during flash!"
|
|
||||||
echo "Flash configuration field of ${ELFFILE}:"
|
|
||||||
arm-none-eabi-objdump -j.fcfield -s "${ELFFILE}"
|
|
||||||
echo "Abort flash procedure!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "${ELFFILE} is fine."
|
|
||||||
exit 0
|
|
||||||
37
cpu/kinetis/dist/check-fcfield-hex.sh
vendored
37
cpu/kinetis/dist/check-fcfield-hex.sh
vendored
@ -1,37 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# Flash configuration field check script for Freescale Kinetis MCUs.
|
|
||||||
#
|
|
||||||
# This script is supposed to be called from RIOTs
|
|
||||||
# unified OpenOCD script (dist/tools/openocd/openocd.sh).
|
|
||||||
#
|
|
||||||
# Syntax: check-fcfield-hex.sh $HEXFILE
|
|
||||||
#
|
|
||||||
# @author Jonas Remmert <j.remmert@phytec.de>
|
|
||||||
# @author Johann Fischer <j.fischer@phytec.de>
|
|
||||||
# @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
|
|
||||||
|
|
||||||
if [ $# -ne 1 ]; then
|
|
||||||
echo "Usage: $0 HEXFILE"
|
|
||||||
echo "Checks the flash configuration field protection bits to avoid flashing a locked image to a Kinetis MCU (protection against accidental bricking)."
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
HEXFILE="$1"
|
|
||||||
FCFIELD_START='0x400'
|
|
||||||
FCFIELD_END='0x410'
|
|
||||||
FCFIELD_AWK_REGEX='^ 0400 '
|
|
||||||
|
|
||||||
ACTUAL_FCFIELD=$(arm-none-eabi-objdump --start-address=${FCFIELD_START} --stop-address=${FCFIELD_END} ${HEXFILE} -s | awk -F' ' "/${FCFIELD_AWK_REGEX}/ { print \$2 \$3 \$4 \$5; }")
|
|
||||||
# Allow any FOPT flags configuration (".." in the pattern)
|
|
||||||
EXPECTED_FCFIELD="^fffffffffffffffffffffffffe..ffff$"
|
|
||||||
|
|
||||||
if ! printf '%s' "${ACTUAL_FCFIELD}" | grep -q "${EXPECTED_FCFIELD}"; then
|
|
||||||
echo "Danger of bricking the device during flash!"
|
|
||||||
echo "Flash configuration field of ${HEXFILE}:"
|
|
||||||
arm-none-eabi-objdump --start-address=${FCFIELD_START} --stop-address=${FCFIELD_END} ${HEXFILE} -s
|
|
||||||
echo "Abort flash procedure!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "${HEXFILE} is not locked."
|
|
||||||
exit 0
|
|
||||||
58
cpu/kinetis/dist/check-fcfield.sh
vendored
Executable file
58
cpu/kinetis/dist/check-fcfield.sh
vendored
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Flash configuration field check script for Freescale Kinetis MCUs.
|
||||||
|
#
|
||||||
|
# This script is supposed to be called from RIOTs
|
||||||
|
# unified OpenOCD script (dist/tools/openocd/openocd.sh).
|
||||||
|
#
|
||||||
|
# Syntax: check-fcfield.sh $FLASHFILE
|
||||||
|
#
|
||||||
|
# @author Jonas Remmert <j.remmert@phytec.de>
|
||||||
|
# @author Johann Fischer <j.fischer@phytec.de>
|
||||||
|
# @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
|
||||||
|
# @author Francisco Molina <francisco.molina@inria.fr>
|
||||||
|
|
||||||
|
# Elf or Hex file to flash
|
||||||
|
FLASHFILE="$1"
|
||||||
|
|
||||||
|
# FCFIELD goes from 0x400-0x40f
|
||||||
|
FCFIELD_START='0x400'
|
||||||
|
FCFIELD_END='0x410'
|
||||||
|
FCFIELD_AWK_REGEX='^ 0400 '
|
||||||
|
|
||||||
|
# The following fcfield places the flash in a unsecure state which is the default
|
||||||
|
# FCF code for Freescale Kinetis MCUs, see /cpu/kinetis/fcfield.c.
|
||||||
|
EXPECTED_FCFIELD="^fffffffffffffffffffffffffe..ffff$"
|
||||||
|
|
||||||
|
get_fc_field()
|
||||||
|
{
|
||||||
|
if [ ${1##*.} = elf ]; then
|
||||||
|
arm-none-eabi-objdump -j.fcfield -s "${1}"
|
||||||
|
elif [ ${1##*.} = hex ]; then
|
||||||
|
arm-none-eabi-objdump --start-address=${FCFIELD_START} --stop-address=${FCFIELD_END} ${1} -s
|
||||||
|
else
|
||||||
|
echo "Unkown file extension: ${1##*.}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
filter_fc_field()
|
||||||
|
{
|
||||||
|
get_fc_field "${1}" | awk -F' ' "/${2}/ { print \$2 \$3 \$4 \$5; }"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ $# -ne 1 ]; then
|
||||||
|
echo "Usage: $0 FLASHFILE"
|
||||||
|
echo "Checks the flash configuration field protection bits to avoid flashing a locked image to a Kinetis MCU (protection against accidental bricking)."
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! filter_fc_field ${FLASHFILE} ${FCFIELD_AWK_REGEX} | grep -q "${EXPECTED_FCFIELD}"; then
|
||||||
|
echo "Danger of bricking the device during flash!"
|
||||||
|
echo "Flash configuration field of ${FLASHFILE}:"
|
||||||
|
get_fc_field ${FLASHFILE}
|
||||||
|
echo "Abort flash procedure!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "${FLASHFILE} is not locked."
|
||||||
|
exit 0
|
||||||
Loading…
x
Reference in New Issue
Block a user