Now we will test restoring the binary image that we earlier got from dumping the original contents of the flash memory.
Our unique flash bank looks as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
> flash info 0 #0 : stm32f2x at 0x08000000, size 0x00100000, buswidth 0, chipwidth 0 # 0: 0x00000000 (0x4000 16kB) not protected # 1: 0x00004000 (0x4000 16kB) not protected # 2: 0x00008000 (0x4000 16kB) not protected # 3: 0x0000c000 (0x4000 16kB) not protected # 4: 0x00010000 (0x10000 64kB) not protected # 5: 0x00020000 (0x20000 128kB) not protected # 6: 0x00040000 (0x20000 128kB) not protected # 7: 0x00060000 (0x20000 128kB) not protected # 8: 0x00080000 (0x20000 128kB) not protected # 9: 0x000a0000 (0x20000 128kB) not protected # 10: 0x000c0000 (0x20000 128kB) not protected # 11: 0x000e0000 (0x20000 128kB) not protected STM32F4xx - Rev: Z |
We can first verify the image file:
1 2 3 4 5 |
> verify_image flash_orig_dump.bin target state: halted target halted due to breakpoint, current mode: Thread xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000c2c verified 1048576 bytes in 1.205177s (849.668 KiB/s) |
We can then naively test to restore the image without first erasing the bank:
1 2 3 4 5 6 |
> flash write_image flash_orig_dump.bin 0x08000000 timeout waiting for algorithm, a target reset is recommended error executing stm32x flash write algorithm flash write failed = 00000040 error writing to flash at address 0x08000000 at offset 0x00000000 in procedure 'flash' |
This is not surprising, although I have seen it go through without an error message before (I am not sure what really happened in that case).
Lets now try to first erase the whole bank.
We check the contents of the first word:
1 2 |
> mdw 0x08000000 0x08000000: 20000c80 |
We recognize the first word from earlier. Now we erase the whole bank (i.e. the whole flash memory):
1 2 3 4 5 6 7 8 9 10 11 12 |
> flash erase_address 0x08000000 0x00100000 erased address 0x08000000 (length 1048576) in 16.923704s (60.507 KiB/s) > mdw 0x08000000 0x08000000: ffffffff > mdw 0x08000004 0x08000004: ffffffff > mdw 0x08000008 0x08000008: ffffffff > mdw 0x08000200 0x08000200: ffffffff > mdw 0x0800422c 0x0800422c: ffffffff |
It does look like the flash memory is erased. Now lets restore the original image:
1 2 3 4 5 6 7 8 9 10 |
> flash write_image flash_orig_dump.bin 0x08000000 target state: halted target halted due to breakpoint, current mode: Handler HardFault xPSR: 0x61000003 pc: 0x20000042 msp: 0xffffffd8 wrote 1048576 bytes from file flash_orig_dump.bin in 21.252260s (48.183 KiB/s) > mdw 0x08000000 0x08000000: 20000c80 > mdw 0x08000004 0x08000004: 0800422d > reset |
This worked too! After the reset, the LEDs are flashing as they did before, instead of staying unlit when I run reset
just after the erasing.
Leave a Reply