Script » Historie » Version 1
Maximilian Seesslen, 29.11.2021 11:50
| 1 | 1 | Maximilian Seesslen | h1. Script |
|---|---|---|---|
| 2 | |||
| 3 | <pre><code class="shell"> |
||
| 4 | #!/bin/bash |
||
| 5 | |||
| 6 | set -e |
||
| 7 | set -u |
||
| 8 | |||
| 9 | handleError() |
||
| 10 | { |
||
| 11 | echo "Error: Something went wrong here. $1" |
||
| 12 | exit 22 |
||
| 13 | } |
||
| 14 | |||
| 15 | writeHwInfo() |
||
| 16 | { |
||
| 17 | echo "BINARY: $BINARY" |
||
| 18 | cat << EOF > .gdbinit |
||
| 19 | set arm abi AAPCS |
||
| 20 | target remote localhost:3333 |
||
| 21 | monitor reset halt |
||
| 22 | EOF |
||
| 23 | |||
| 24 | cat << EOF > gdb.txt |
||
| 25 | br main:loop |
||
| 26 | echo Waiting for application does stop at breakpoint.\n |
||
| 27 | echo If it does not stop, the given binary file is probably wrong.\n |
||
| 28 | c |
||
| 29 | # call (flash)(10,\"mmm\") |
||
| 30 | print &bringupFirmware |
||
| 31 | clear main:loop |
||
| 32 | monitor reset run |
||
| 33 | EOF |
||
| 34 | |||
| 35 | echo $GDB $BINARY -x gdb.txt |
||
| 36 | # $GDB $O/$B -x gdb.txt -batch-silent -q || handleError "Could not verify bringup firmware. Is bringup firmware flashed?" |
||
| 37 | $GDB $BINARY -x gdb.txt --batch || handleError "Could not verify bringup firmware. Is bringup firmware flashed?" |
||
| 38 | |||
| 39 | echo -n "Please enter serial number in hex or dec (e.g. 0x123): " |
||
| 40 | read serial |
||
| 41 | |||
| 42 | serial=$(printf '0x%x\n' $serial) |
||
| 43 | serialLong=$(printf '%08X\n' $serial) |
||
| 44 | |||
| 45 | # echo -n "Please enter variant in hex or dec (e.g. 0x123): " |
||
| 46 | # read serial |
||
| 47 | variant=0 |
||
| 48 | |||
| 49 | if [ -z "$serial" ]; then hanleError "You did not specify an serial number."; fi |
||
| 50 | |||
| 51 | # SEepromMain hwInfoMain |
||
| 52 | # a=$(nm $O/$B | grep hwInfoMain) || handleError "Could not find 'myStruct'" |
||
| 53 | |||
| 54 | # addr=${a%% *} |
||
| 55 | # echo "Will try x/20xb 0x$addr" |
||
| 56 | |||
| 57 | cat << EOF >gdb.txt |
||
| 58 | echo "Helllooooooo" |
||
| 59 | br main:loop |
||
| 60 | # run |
||
| 61 | echo "### Continue run" |
||
| 62 | c |
||
| 63 | echo ### Braked\n |
||
| 64 | set var \$new = (SEepromMain *)malloc(sizeof(struct SEepromMain)) |
||
| 65 | set var \$new.main.magic='H' |
||
| 66 | set var \$new.main.articleId=$articleId |
||
| 67 | set var \$new.main.boardId=$boardId |
||
| 68 | set var \$new.version.hwVersionMajor=$versionMajor |
||
| 69 | set var \$new.version.hwVersionMinor=$versionMinor |
||
| 70 | set var \$new.version.hwVersionPatch=$versionPatch |
||
| 71 | set var \$new.production.serialNumber=$serial |
||
| 72 | set var \$new.production.variant=$variant |
||
| 73 | set var \$new.production.productionDateYear=$year |
||
| 74 | set var \$new.production.productionDateMonth=$month |
||
| 75 | set var \$new.production.productionDateDay=$day |
||
| 76 | set var \$new.production.productionSite=$site |
||
| 77 | |||
| 78 | echo ### calling function\n |
||
| 79 | call (writeHwInfo)(\$new) |
||
| 80 | # monitor reset run |
||
| 81 | echo ### Read back\n |
||
| 82 | call (readHwInfo)() |
||
| 83 | |||
| 84 | print/x bringupFirmware |
||
| 85 | set logging file serial.txt |
||
| 86 | set logging overwrite |
||
| 87 | set logging on |
||
| 88 | print/x $cppObject->hwInfoMain.production.serialNumber |
||
| 89 | set logging off |
||
| 90 | set logging file all.txt |
||
| 91 | set logging overwrite |
||
| 92 | set logging on |
||
| 93 | print/x $cppObject->hwInfoMain |
||
| 94 | |||
| 95 | print &$cppObject->hwInfoMain |
||
| 96 | x/28xb \$0 |
||
| 97 | set logging off |
||
| 98 | |||
| 99 | echo ### finished\n |
||
| 100 | clear main:loop |
||
| 101 | echo "### END" |
||
| 102 | # must not continue or we stuck here |
||
| 103 | # c |
||
| 104 | EOF |
||
| 105 | echo "### Waiting for application to break to write stuff 2" |
||
| 106 | echo "### $GDB $BINARY -x gdb.txt -batch-silent -q" |
||
| 107 | $GDB $BINARY -x gdb.txt --batch || handleError "Could not write HwInfo. Is bringup firmware flashed?" |
||
| 108 | echo "### Waiting for application to break to write stuff 3" |
||
| 109 | echo -e "\n" |
||
| 110 | |||
| 111 | echo "Serial: " |
||
| 112 | |||
| 113 | a=$(cat serial.txt) |
||
| 114 | isSerial="${a##* = }" |
||
| 115 | |||
| 116 | if [ "$serial" == "$isSerial" ]; then |
||
| 117 | cat all.txt |
||
| 118 | echo "Serial is OK; $serial == $isSerial" |
||
| 119 | else |
||
| 120 | handleError "Serial is NOT OK; $serial != $isSerial" |
||
| 121 | fi |
||
| 122 | |||
| 123 | mv all.txt $opwd/hwinfo_${serialLong}.txt |
||
| 124 | } |
||
| 125 | |||
| 126 | opwd=$PWD |
||
| 127 | GDB=/opt/tcb-stm32/usr/bin/arm-none-eabi/arm-none-eabi-gdb |
||
| 128 | month=$(date +"%m") |
||
| 129 | day=$(date +"%d") |
||
| 130 | year=$(date +"%y") |
||
| 131 | |||
| 132 | |||
| 133 | #---fin------------------------------------------------------------------------ |
||
| 134 | |||
| 135 | </code></pre> |