你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

基于STM32 使用 Bootloader经验分享

[复制链接]
攻城狮Melo 发布时间:2023-3-14 13:34
在生成页面中选中了 恢复出厂固件引脚 功能后,即开启了出厂固件恢复功能。开发者可以将制作好的 app 固件烧录至 factory 分区中,在系统启动前按下恢复出厂固件引脚(可选择一个或者两个引脚作为固件恢复触发引脚)并保持 10S,即可从 factory 分区中恢复出厂固件到 app 分区中。

由于恢复出厂设置是直接copy,所以编译的出厂固件其实和下载固件配置相同。
bootloader配置如下:

20191013123338314.png

修改fal_cfg.h如下:
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date           Author       Notes
  8. * 2018-12-5      SummerGift   first version
  9. */

  10. #ifndef _FAL_CFG_H_
  11. #define _FAL_CFG_H_

  12. #include <rtthread.h>
  13. #include <board.h>

  14. #define RT_APP_PART_ADDR 0x8040000


  15. extern const struct fal_flash_dev stm32_onchip_flash;

  16. /* flash device table */
  17. #define FAL_FLASH_DEV_TABLE                                          \
  18. {                                                                    \
  19.     &stm32_onchip_flash,                                             \
  20. }
  21. /* ====================== Partition Configuration ========================== */
  22. #ifdef FAL_PART_HAS_TABLE_CFG

  23. /* partition table */
  24. #define FAL_PART_TABLE                                                                      \
  25. {                                                                                           \
  26.         {FAL_PART_MAGIC_WROD,    "bl",       "onchip_flash",       0*128* 1024 , 128 * 1024, 0},  \
  27.         {FAL_PART_MAGIC_WROD,    "download", "onchip_flash",       1*128* 1024 , 128 * 1024, 0},  \
  28.         {FAL_PART_MAGIC_WROD,    "app",      "onchip_flash",       2*128* 1024 , 128 * 1024, 0},  \
  29.         {FAL_PART_MAGIC_WROD,    "factory",  "onchip_flash",       3*128* 1024 , 128 * 1024, 0},  \
  30. }
  31. #endif /* FAL_PART_HAS_TABLE_CFG */
  32. #endif /* _FAL_CFG_H_ */

复制代码

修改link.sct如下:
  1. ; *************************************************************
  2. ; *** Scatter-Loading Description File generated by uVision ***
  3. ; *************************************************************

  4. LR_IROM1 0x08040000 0x00080000  {    ; load region size_region
  5.   ER_IROM1 0x08040000 0x00080000  {  ; load address = execution address
  6.    *.o (RESET, +First)
  7.    *(InRoot$Sections)
  8.    .ANY (+RO)
  9.   }
  10.   RW_IRAM1 0x20000000 0x00010000  {  ; RW data
  11.    .ANY (+RW +ZI)
  12.   }
  13. }
复制代码

编译生成bin文件。

此时如果直接使用st-link等工具烧录至0x8060000,会出现如下错误:
  1. [E]Get firmware header occur CRC32(calc.crc: 43e482ba != hdr.info_crc32: 080409eb) error on 'factory' partition!
复制代码

因为无论是factory还是download,在向app分区拷贝的时候,都会做一次解密算法(因为factory分区和download分区是可以放在片外spi flash的,如果不加密直接拷出来下载就能用了,而app分区在stm32内部,设置了读保护是不用担心的)。
所以需要将生成的文件用打包器加密,再重新用st-link烧录。

20191013124406867.png

恢复出厂设置的日志如下:
  1. [SFUD]Find a Winbond flash chip. Size is 16777216 bytes.
  2. [SFUD]spi flash device is initialize success.

  3. __  ___     __   __   __  ___
  4. |__)  |  __ |__) /  \ /  \  |  
  5. |  \  |     |__) \__/ \__/  |  
  6. 2006 - 2019 Copyright by rt-thread team
  7.                 0.9.1 build Oct 13 2019
  8. [D/FAL] (fal_flash_init:63) Flash device |             onchip_flash | addr: 0x08000000 | len: 0x00080000 | blk_size: 0x00000800 |initialized finish.
  9. [D/FAL] (fal_flash_init:63) Flash device |                nor_flash | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
  10. [I/FAL] ==================== FAL partition table ====================
  11. [I/FAL] | name     | flash_dev    |   offset   |    length  |
  12. [I/FAL] -------------------------------------------------------------
  13. [I/FAL] | app      | onchip_flash | 0x00040000 | 0x00020000 |
  14. [I/FAL] | download | onchip_flash | 0x00020000 | 0x00020000 |
  15. [I/FAL] | factory  | onchip_flash | 0x00060000 | 0x00020000 |
  16. [I/FAL] =============================================================
  17. [I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.
  18. [I/FAL] System initialization successful.
  19. [I]RT-Thread OTA package(V0.2.1) initialize success.
  20. [E]Get firmware header occur CRC32(calc.crc: 7b93c5c8 != hdr.info_crc32: ffffffff) error on 'download' partition!
  21. [E]Get OTA download partition firmware header failed!
  22. [E]Get firmware header occur CRC32(calc.crc: 7b93c5c8 != hdr.info_crc32: ffffffff) error on 'app' partition!
  23. [I]Begin to execute the program on app partition.
  24. [I/FAL] Find user firmware at app partition 0x08040000 successfully.
  25. [I/FAL] Bootloader jumps to user firmware now.

  26. \ | /
  27. - RT -     Thread Operating System
  28. / | \     4.0.0 build Oct 13 2019
  29. 2006 - 2018 Copyright by rt-thread team
  30. [D/FAL] (fal_flash_init:61) Flash device |             onchip_flash | addr: 0x08000000 | len: 0x00080000 | blk_size: 0x00000800 |initialized finish.
  31. [I/FAL] ==================== FAL partition table ====================
  32. [I/FAL] | name     | flash_dev    |   offset   |    length  |
  33. [I/FAL] -------------------------------------------------------------
  34. [I/FAL] | bl       | onchip_flash | 0x00000000 | 0x00020000 |
  35. [I/FAL] | download | onchip_flash | 0x00020000 | 0x00020000 |
  36. [I/FAL] | app      | onchip_flash | 0x00040000 | 0x00020000 |
  37. [I/FAL] | factory  | onchip_flash | 0x00060000 | 0x00020000 |
  38. [I/FAL] =============================================================
  39. [I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.
  40. version 2.0.0
  41. msh >



  42. [SFUD]Find a Winbond flash chip. Size is 16777216 bytes.
  43. [SFUD]spi flash device is initialize success.
  44. [D/FAL] (fal_flash_init:63) Flash device |             onchip_flash | addr: 0x08000000 | len: 0x00080000 | blk_size: 0x00000800 |initialized finish.
  45. [D/FAL] (fal_flash_init:63) Flash device |                nor_flash | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
  46. [I/FAL] ==================== FAL partition table ====================
  47. [I/FAL] | name     | flash_dev    |   offset   |    length  |
  48. [I/FAL] -------------------------------------------------------------
  49. [I/FAL] | app      | onchip_flash | 0x00040000 | 0x00020000 |
  50. [I/FAL] | download | onchip_flash | 0x00020000 | 0x00020000 |
  51. [I/FAL] | factory  | onchip_flash | 0x00060000 | 0x00020000 |
  52. [I/FAL] =============================================================
  53. [I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.
  54. [I]RT-Thread OTA package(V0.2.1) initialize success.
  55. [I]Verify 'factory' partition(fw ver: 2.0.0, timestamp: 1570940368) success.
  56. [E]Get firmware header occur CRC32(calc.crc: 7b93c5c8 != hdr.info_crc32: ffffffff) error on 'app' partition!
  57. [I]OTA firmware(app) upgrade startup.
  58. [I]The partition 'app' is erasing.
  59. [I]The partition 'app' erase success.
  60. [I]OTA Write: [====================================================================================================] 100%
  61. [I]Verify 'app' partition(fw ver: 2.0.0, timestamp: 1570940368) success.
  62. [I/FAL] Find user firmware at app partition 0x08040000 successfully.
  63. [I/FAL] Bootloader jumps to user firmware now.

  64. \ | /
  65. - RT -     Thread Operating System
  66. / | \     4.0.0 build Oct 13 2019
  67. 2006 - 2018 Copyright by rt-thread team
  68. [D/FAL] (fal_flash_init:61) Flash device |             onchip_flash | addr: 0x08000000 | len: 0x00080000 | blk_size: 0x00000800 |initialized finish.
  69. [I/FAL] ==================== FAL partition table ====================
  70. [I/FAL] | name     | flash_dev    |   offset   |    length  |
  71. [I/FAL] -------------------------------------------------------------
  72. [I/FAL] | bl       | onchip_flash | 0x00000000 | 0x00020000 |
  73. [I/FAL] | download | onchip_flash | 0x00020000 | 0x00020000 |
  74. [I/FAL] | app      | onchip_flash | 0x00040000 | 0x00020000 |
  75. [I/FAL] | factory  | onchip_flash | 0x00060000 | 0x00020000 |
  76. [I/FAL] =============================================================
  77. [I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.
  78. version 1.0.0
  79. msh >

复制代码

————————————————
版权声明:小盼你最萌哒如有侵权请联系删除


收藏 评论0 发布时间:2023-3-14 13:34

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版