stm32 工厂引导加载程序可能被 openocd 覆盖?
stm32 factory bootloader possibly overwritten with openocd?
tl;dr:将固件刷写到 0x00000000 而不是 0x08000000,我迷路了吗?
您好,
我的设备基于 STM32F103CBTx,它带有专有固件并开启了读出保护。
我用连接到 PA13 和 PA14 的 ST-Link v2 SWDIO 和 SWCLK 连接到它,这个命令:
sudo openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg
我不记得我是如何删除闪存保护的,但它起作用了,因为原始固件不再起作用了。然后我创建了一个简单的 hello world 固件,它拉上拉下三个 gpios 并刷新它。 gpios 以 700 毫秒的间隔上拉和下拉。
刷完之后openocd连不上了。我忘了指定偏移量,手册上说偏移量默认为 0 并且在它工作时,我想我该死的 hello world 而不是引导加载程序正在愉快地上下拉一些随机引脚……这可能吗?我发现的所有其他线程都说引导加载程序是写保护的。
这是我最后一次联系:
> halt
halt
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x01000003 pc: 0xfffffffe msp: 0xffffffdc
> flash write_image erase fw.hex
flash write_image erase fw.hex
auto erase enabled
target halted due to breakpoint, current mode: Handler HardFault
xPSR: 0x61000003 pc: 0x2000003a msp: 0xffffffdc
wrote 4096 bytes from file fw.hex in 0.285697s (14.001 KiB/s)
> reset
reset
jtag status contains invalid mode value - communication failure
Polling target stm32f1x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
非常感谢任何指示。
编辑:
我现在得到的,还尝试了另一个 st-link:
% sudo openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.244356
Error: init mode failed (unable to connect to the target)
in procedure 'init'
in procedure 'ocd_bouncer'
flashed firmware to 0x00000000 instead of 0x08000000, am I lost?
不,根本没关系,它们是一样的。
复位后,MCU 在SP
中加载地址0
的字,在PC
中加载地址4
的下一个字。 BOOT0
和 BOOT1
引脚控制哪个内存映射到 0x00000000
。通常,BOOT0
被拉低,0x08000000
处的闪存被映射到 0x00000000
。
instead of the boot loader my shitty hello world is pulling up and down some random pins happily… Is this possible? All other threads I found say the boot loader is write protected.
工厂引导加载程序确实是写保护的,openocd无法覆盖它。
但是,您的应用程序可以通过在 GPIOA->CRH
或 AFIO->MAPR
中写入错误值来重新配置 SWD
引脚,从而阻止 openocd 工作。这是导致此问题的最常见原因。
幸运的是,有办法恢复。
重置后连接
如果在启动 openocd 时控制器的复位引脚保持低电平一段时间,应用程序将无法启动,并弄乱 GPIO 配置。
Openocd 可以自动执行此操作,当
- 它被告知要这样做,
reset_config srst_only srst_nogate
行出现在配置脚本的某处。
- MCU 复位引脚连接到调试器硬件,官方 ST-Link/V2 上的引脚 15。
或者您可以通过您的开发板提供的任何方式手动完成。如果你幸运的话,它有一个复位按钮,如果没有,你必须想办法以某种方式将 MCU 复位引脚接地。
- 将复位引脚拉低
- 启动openocd
- 等待
Info : Target voltage
行出现。也许再长一秒钟。
- 释放重置引脚。
这需要一些反复试验,你会通过练习变得更好。
然后您可以刷新改进后的应用程序,这会小心避免重新配置 SWD 引脚。
tl;dr:将固件刷写到 0x00000000 而不是 0x08000000,我迷路了吗?
您好,
我的设备基于 STM32F103CBTx,它带有专有固件并开启了读出保护。 我用连接到 PA13 和 PA14 的 ST-Link v2 SWDIO 和 SWCLK 连接到它,这个命令:
sudo openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg
我不记得我是如何删除闪存保护的,但它起作用了,因为原始固件不再起作用了。然后我创建了一个简单的 hello world 固件,它拉上拉下三个 gpios 并刷新它。 gpios 以 700 毫秒的间隔上拉和下拉。
刷完之后openocd连不上了。我忘了指定偏移量,手册上说偏移量默认为 0 并且在它工作时,我想我该死的 hello world 而不是引导加载程序正在愉快地上下拉一些随机引脚……这可能吗?我发现的所有其他线程都说引导加载程序是写保护的。
这是我最后一次联系:
> halt halt target halted due to debug-request, current mode: Handler HardFault xPSR: 0x01000003 pc: 0xfffffffe msp: 0xffffffdc > flash write_image erase fw.hex flash write_image erase fw.hex auto erase enabled target halted due to breakpoint, current mode: Handler HardFault xPSR: 0x61000003 pc: 0x2000003a msp: 0xffffffdc wrote 4096 bytes from file fw.hex in 0.285697s (14.001 KiB/s) > reset reset jtag status contains invalid mode value - communication failure Polling target stm32f1x.cpu failed, trying to reexamine Examination failed, GDB will be halted. Polling again in 100ms
非常感谢任何指示。
编辑: 我现在得到的,还尝试了另一个 st-link:
% sudo openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg Open On-Chip Debugger 0.10.0 Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '. Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD adapter speed: 1000 kHz adapter_nsrst_delay: 100 none separate Info : Unable to match requested speed 1000 kHz, using 950 kHz Info : Unable to match requested speed 1000 kHz, using 950 kHz Info : clock speed 950 kHz Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748 Info : using stlink api v2 Info : Target voltage: 3.244356 Error: init mode failed (unable to connect to the target) in procedure 'init' in procedure 'ocd_bouncer'
flashed firmware to 0x00000000 instead of 0x08000000, am I lost?
不,根本没关系,它们是一样的。
复位后,MCU 在SP
中加载地址0
的字,在PC
中加载地址4
的下一个字。 BOOT0
和 BOOT1
引脚控制哪个内存映射到 0x00000000
。通常,BOOT0
被拉低,0x08000000
处的闪存被映射到 0x00000000
。
instead of the boot loader my shitty hello world is pulling up and down some random pins happily… Is this possible? All other threads I found say the boot loader is write protected.
工厂引导加载程序确实是写保护的,openocd无法覆盖它。
但是,您的应用程序可以通过在 GPIOA->CRH
或 AFIO->MAPR
中写入错误值来重新配置 SWD
引脚,从而阻止 openocd 工作。这是导致此问题的最常见原因。
幸运的是,有办法恢复。
重置后连接
如果在启动 openocd 时控制器的复位引脚保持低电平一段时间,应用程序将无法启动,并弄乱 GPIO 配置。
Openocd 可以自动执行此操作,当
- 它被告知要这样做,
reset_config srst_only srst_nogate
行出现在配置脚本的某处。 - MCU 复位引脚连接到调试器硬件,官方 ST-Link/V2 上的引脚 15。
或者您可以通过您的开发板提供的任何方式手动完成。如果你幸运的话,它有一个复位按钮,如果没有,你必须想办法以某种方式将 MCU 复位引脚接地。
- 将复位引脚拉低
- 启动openocd
- 等待
Info : Target voltage
行出现。也许再长一秒钟。 - 释放重置引脚。
这需要一些反复试验,你会通过练习变得更好。
然后您可以刷新改进后的应用程序,这会小心避免重新配置 SWD 引脚。