From a3fcefa34ae18bf627e78644bb74ec3e03ea05e4 Mon Sep 17 00:00:00 2001 From: Christoph Metz Date: Thu, 15 Feb 2018 02:06:00 +0100 Subject: [PATCH 1/2] added a new way to check whether a new firmware needs to programmend into the sam3 - sam3s_rpi_sysfs_check.cfg does a flash verify_bank against ch.bin - sam3-program.bash greps the result of the verify after 'contents differ' - reduced the retry counter from 30 to 5, if the program fails - added a short sleep of 1 sec at the end of try_program to be sure everything is fine (not sure if it's needed) --- cfg/sam3s_rpi_sysfs_check.cfg | 43 +++++++++++++++++++++++++++++++++++ sam3-program.bash | 20 ++++++++-------- 2 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 cfg/sam3s_rpi_sysfs_check.cfg diff --git a/cfg/sam3s_rpi_sysfs_check.cfg b/cfg/sam3s_rpi_sysfs_check.cfg new file mode 100644 index 0000000..d9fbfc8 --- /dev/null +++ b/cfg/sam3s_rpi_sysfs_check.cfg @@ -0,0 +1,43 @@ +source [find interface/matrix-creator.cfg] +transport select jtag +adapter_khz 128 + + +jtag newtap em358 cpu \ + -irlen 4\ + -ircapture 0x1\ + -irmask 0xf \ + -expected-id 0x3ba00477 + +jtag newtap em357 bs \ + -irlen 4 \ + -ircapture 0x0e \ + -irmask 0xf \ + -expected-id 0x069AA62B + +jtag newtap xc6sxl4.fpga fpga \ + -irlen 6 \ + -ircapture 0x35 \ + -irmask 0x3f \ + -expected-id 0x24000093 + +jtag newtap sam3n.cpu cpu \ + -irlen 4\ + -ircapture 0x1\ + -irmask 0xf \ + -expected-id 0x4ba00477 + +target create sam3n.cpu cortex_m -endian little -chain-position 3 +flash bank flash0 at91sam3 0x00400000 0 0 0 sam3n.cpu + +#source at91sam3nXX.cfg +init +halt +wait_halt +sleep 10 +at91sam3 gpnvm set 1 +flash info 0 +flash probe 0 +flash verify_bank 0 blob/ch.bin 0 +reset run +shutdown diff --git a/sam3-program.bash b/sam3-program.bash index 7733be8..2ae5df8 100755 --- a/sam3-program.bash +++ b/sam3-program.bash @@ -62,7 +62,8 @@ function try_program() { echo $RES sleep 0.5 - reset_mcu + reset_mcu + sleep 1 } function enable_program() { @@ -73,13 +74,14 @@ function enable_program() { } function check_firmware() { - COMPARE_VERSION=$(diff <(./firmware_info) <(cat mcu_firmware.version)|wc -l) - - if [ "$COMPARE_VERSION" == "0" ];then - echo 1 - else #failed - echo 0 - fi + FIRMWARE_DIFFERS=$(openocd -f cfg/sam3s_rpi_sysfs_check.cfg 2>&1 | grep -c 'contents differ') + if [ "$FIRMWARE_DIFFERS" == "1" ]; then + # new or no firmware + echo 0 + else + # same firmware + echo 1 + fi } for i in 4 17 18 19 20 22 23 27 @@ -103,7 +105,7 @@ then fi enable_program count=0 -while [ $count -lt 30 ]; do +while [ $count -lt 5 ]; do TEST=$(try_program) if [ "$TEST" == "1" ];then CHECK=$(check_firmware) From f1004480a38f7c3d34fa6ec5314a8b1c8f52c78a Mon Sep 17 00:00:00 2001 From: Christoph Metz Date: Fri, 16 Feb 2018 19:48:48 +0100 Subject: [PATCH 2/2] fixed the behavior from "setting boot mode" to "checking boot mode", while running the firmware check of the sam3 --- cfg/sam3s_rpi_sysfs_check.cfg | 2 +- sam3-program.bash | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cfg/sam3s_rpi_sysfs_check.cfg b/cfg/sam3s_rpi_sysfs_check.cfg index d9fbfc8..aedfe05 100644 --- a/cfg/sam3s_rpi_sysfs_check.cfg +++ b/cfg/sam3s_rpi_sysfs_check.cfg @@ -35,7 +35,7 @@ init halt wait_halt sleep 10 -at91sam3 gpnvm set 1 +at91sam3 gpnvm show all flash info 0 flash probe 0 flash verify_bank 0 blob/ch.bin 0 diff --git a/sam3-program.bash b/sam3-program.bash index 2ae5df8..0eff3ec 100755 --- a/sam3-program.bash +++ b/sam3-program.bash @@ -74,14 +74,17 @@ function enable_program() { } function check_firmware() { - FIRMWARE_DIFFERS=$(openocd -f cfg/sam3s_rpi_sysfs_check.cfg 2>&1 | grep -c 'contents differ') - if [ "$FIRMWARE_DIFFERS" == "1" ]; then + local result=1 + local output=$(openocd -f cfg/sam3s_rpi_sysfs_check.cfg 2>&1) + if [[ "$output" == *"sam3-gpnvm1: 0"* ]]; then + # wrong bootmode + result=0 + fi + if [[ "$output" == *"contents differ"* ]]; then # new or no firmware - echo 0 - else - # same firmware - echo 1 + result=0 fi + echo "$result" } for i in 4 17 18 19 20 22 23 27 @@ -103,7 +106,9 @@ then echo "SAM3 MCU was programmed before. Not programming it again." exit 0 fi + enable_program + count=0 while [ $count -lt 5 ]; do TEST=$(try_program)