在生成页面中选中了 恢复出厂固件引脚 功能后,即开启了出厂固件恢复功能。开发者可以将制作好的 app 固件烧录至 factory 分区中,在系统启动前按下恢复出厂固件引脚(可选择一个或者两个引脚作为固件恢复触发引脚)并保持 10S,即可从 factory 分区中恢复出厂固件到 app 分区中。) \- l9 F7 D t$ _& a: d% V
. L& N* W' R( Q* h6 r
由于恢复出厂设置是直接copy,所以编译的出厂固件其实和下载固件配置相同。& r% B5 ^% E& e. O
bootloader配置如下:
6 r4 H8 w2 ~9 f, |- `$ J
' q0 N% ?% X0 m/ w
/ {6 j/ | n K; E- n3 I8 ~; L& _; Y" x' `6 F2 a( v0 o
修改fal_cfg.h如下:2 L7 V8 \+ a$ G% h3 P9 W! R% v+ E2 C
- /*
+ ~" o5 P' l8 Y# ^2 y( Q# ` j - * Copyright (c) 2006-2018, RT-Thread Development Team$ e/ k& _& W/ x1 }
- *
4 [$ P6 U1 i& n' f - * SPDX-License-Identifier: Apache-2.00 _* Y1 V* K. U3 m& C* O
- *
. t# @+ Q, v% k2 \. n, v8 F - * Change Logs:
1 M% X3 z. C: w" _ - * Date Author Notes
3 |! @) b( y [ - * 2018-12-5 SummerGift first version3 I9 g, K3 |% `/ h& w7 z
- */3 g3 e. h3 B7 q% H, H M; T \$ Q
- # I: |" E8 y" l# q$ b; ~
- #ifndef _FAL_CFG_H_1 x% }5 c/ O" ~1 |; k
- #define _FAL_CFG_H_9 z* Y; e/ s6 z! d3 r
; u/ ?. f& t/ m/ L- #include <rtthread.h>" S6 I) W! B+ q. D: R; {
- #include <board.h>
! ~& R. R( {9 |/ G" ] Y o8 R - : r( w8 i6 U. V( j# d3 A
- #define RT_APP_PART_ADDR 0x80400005 F) d$ `# ]! }) w' [8 ]+ M; p
! |7 m: w7 D3 a, f
% ?1 B3 R) E( g) J1 B2 S- extern const struct fal_flash_dev stm32_onchip_flash;
6 h* R* h3 q: G$ ^: @ - + w7 K* s ~* b" a
- /* flash device table */' [( g2 p9 ^3 o- N9 j9 L
- #define FAL_FLASH_DEV_TABLE \
7 n; @8 n& ]- `* l/ t$ f$ t1 \" Q - { \
2 k) c% y d# J" ]- J1 T5 ?( N - &stm32_onchip_flash, \+ T1 S. s- M+ | W" U
- }
W. v; Q4 b/ j( `* @' r; }5 m V! W7 X - /* ====================== Partition Configuration ========================== */
1 l5 ~, \6 \& x' y% D- E" W% Y+ i - #ifdef FAL_PART_HAS_TABLE_CFG
8 `% F% Y+ k8 `6 }0 L - ' |) `! P5 l" A) y! j6 W
- /* partition table */
" Z! m. N% z+ [ e$ y1 O: G; J! v* Q - #define FAL_PART_TABLE \6 _0 s2 ~' V# X: _" s
- { \+ ?5 c5 I7 B4 d; @
- {FAL_PART_MAGIC_WROD, "bl", "onchip_flash", 0*128* 1024 , 128 * 1024, 0}, \
g) Y0 q& ?, o n# Z0 K - {FAL_PART_MAGIC_WROD, "download", "onchip_flash", 1*128* 1024 , 128 * 1024, 0}, \2 d! {" D* z( W& A0 \6 K! P
- {FAL_PART_MAGIC_WROD, "app", "onchip_flash", 2*128* 1024 , 128 * 1024, 0}, \
+ ~& I3 C+ g! F$ \) _" k - {FAL_PART_MAGIC_WROD, "factory", "onchip_flash", 3*128* 1024 , 128 * 1024, 0}, \) W1 a7 s- j0 v1 S; X6 x5 W
- }$ v! A- [% q& k' O' `& T6 y
- #endif /* FAL_PART_HAS_TABLE_CFG */3 l; T. Q* @4 \+ Q( V- t
- #endif /* _FAL_CFG_H_ */9 g! j1 @% k4 {
' n1 T6 t' l, L
复制代码
' z- d P7 h) i! I# M修改link.sct如下:
i% g% A9 [9 G# Y* W8 x' L- ; *************************************************************
& j6 U/ C3 g& P* o: J4 ^7 r - ; *** Scatter-Loading Description File generated by uVision ***: W3 g3 ^- D1 R" B
- ; *************************************************************0 h& q% [! U! K0 J/ Y
+ x1 M) U$ Z2 a- LR_IROM1 0x08040000 0x00080000 { ; load region size_region
- k& N |" d3 { - ER_IROM1 0x08040000 0x00080000 { ; load address = execution address5 B' z) q8 D6 W8 N+ z6 d
- *.o (RESET, +First)' O% T, c. R6 Z4 f0 D0 ^
- *(InRoot$Sections)
- l8 Z7 |& E: k5 s8 e3 p - .ANY (+RO)
# f2 W- T1 N6 k2 W' E E - }
, J, O( F7 }( i3 v! | - RW_IRAM1 0x20000000 0x00010000 { ; RW data
Z) M6 S& t7 X. ^4 d. \ - .ANY (+RW +ZI)
. m/ H% U! e7 o( O7 ] - }* i# P$ [# [7 Q# s; I
- }
1 }) }' [4 X9 N
复制代码 ; d( ?% Z5 s2 N
编译生成bin文件。
; m$ |) \1 t6 H' w- N% r- d* u4 ?/ Q9 I
此时如果直接使用st-link等工具烧录至0x8060000,会出现如下错误:
0 y" U5 A5 c( O: v+ x* V( Z- [E]Get firmware header occur CRC32(calc.crc: 43e482ba != hdr.info_crc32: 080409eb) error on 'factory' partition!
4 F, {; z& K2 F4 M: A# n
复制代码 3 Q; M+ w, i5 a
因为无论是factory还是download,在向app分区拷贝的时候,都会做一次解密算法(因为factory分区和download分区是可以放在片外spi flash的,如果不加密直接拷出来下载就能用了,而app分区在stm32内部,设置了读保护是不用担心的)。2 d2 x2 V* s. @" u! x% I
所以需要将生成的文件用打包器加密,再重新用st-link烧录。$ d& e/ Q/ k- U1 Z
7 z- v" a- S$ |% f5 h: Z5 ^
6 r) E/ I# F3 J, ]0 x
" c% ]# T0 s3 e8 b恢复出厂设置的日志如下:, ?8 G" `) C! N- K
- [SFUD]Find a Winbond flash chip. Size is 16777216 bytes.2 x a9 N1 x- F( U0 b. ~ k
- [SFUD]spi flash device is initialize success.
! y3 P9 M* e8 T. ` - + V# W. Y& Q5 S/ S8 }/ E% g5 @1 u
- __ ___ __ __ __ ___ + ?$ B3 x; _5 p3 Z9 ^
- |__) | __ |__) / \ / \ | ( P' Z( B; [/ f% P/ Z- o% ^) D- K
- | \ | |__) \__/ \__/ |
1 {9 Y4 H, n: F, J8 g* m9 L - 2006 - 2019 Copyright by rt-thread team
( l1 K" B* z- ?8 H) M& S - 0.9.1 build Oct 13 2019, F3 b1 A7 ]: `* D
- [D/FAL] (fal_flash_init:63) Flash device | onchip_flash | addr: 0x08000000 | len: 0x00080000 | blk_size: 0x00000800 |initialized finish.2 |" S* u9 T2 T- y5 l
- [D/FAL] (fal_flash_init:63) Flash device | nor_flash | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
0 }$ V# e8 W3 R, b9 W/ G2 O - [I/FAL] ==================== FAL partition table ====================/ f; I! C: e1 f1 i: N, g/ w
- [I/FAL] | name | flash_dev | offset | length |$ Y$ c: e" [1 R
- [I/FAL] -------------------------------------------------------------
8 B3 Z6 A: P" N - [I/FAL] | app | onchip_flash | 0x00040000 | 0x00020000 |
' s$ Y5 G: V% X/ o - [I/FAL] | download | onchip_flash | 0x00020000 | 0x00020000 |7 P6 n1 ~8 u8 q. M( i
- [I/FAL] | factory | onchip_flash | 0x00060000 | 0x00020000 | e& P4 B5 q7 H; l) Y
- [I/FAL] =============================================================+ n* X6 q3 U5 B' G
- [I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.
1 @' S5 `5 G0 X) W6 h. z - [I/FAL] System initialization successful.
. p( o3 ]- }0 q - [I]RT-Thread OTA package(V0.2.1) initialize success.* P, K/ o1 O, `
- [E]Get firmware header occur CRC32(calc.crc: 7b93c5c8 != hdr.info_crc32: ffffffff) error on 'download' partition!; m8 W: K0 C3 S5 i
- [E]Get OTA download partition firmware header failed!% q; i* j4 r! J! c( s1 T
- [E]Get firmware header occur CRC32(calc.crc: 7b93c5c8 != hdr.info_crc32: ffffffff) error on 'app' partition!/ W+ ~% ^" M# h$ X6 g0 `0 P
- [I]Begin to execute the program on app partition.
) S2 g( e$ _$ S9 t @/ o - [I/FAL] Find user firmware at app partition 0x08040000 successfully.
+ m+ Z8 a: P! i. C/ a2 T' H* f - [I/FAL] Bootloader jumps to user firmware now.
+ M- ?3 } N z" n7 }3 Z: Z - : I1 j8 G5 {6 p$ A+ O5 i
- \ | /4 c. ]; D& c& h
- - RT - Thread Operating System
3 h/ Q* e: J2 k8 S2 Y+ z) m/ Z - / | \ 4.0.0 build Oct 13 2019, h# u1 X7 _4 u/ d0 R
- 2006 - 2018 Copyright by rt-thread team
- i6 y8 }: I6 u9 }' V; d/ v - [D/FAL] (fal_flash_init:61) Flash device | onchip_flash | addr: 0x08000000 | len: 0x00080000 | blk_size: 0x00000800 |initialized finish." K3 o+ M- P- \0 ~5 V
- [I/FAL] ==================== FAL partition table ====================
+ C- z* C; y$ ~4 ~% M/ A0 E$ J - [I/FAL] | name | flash_dev | offset | length |- D# K; i5 G, Y6 a; u4 J
- [I/FAL] -------------------------------------------------------------
5 J0 W% L9 Z$ @. x: Q4 \' W - [I/FAL] | bl | onchip_flash | 0x00000000 | 0x00020000 |
. M' R @9 ?% \. y6 X - [I/FAL] | download | onchip_flash | 0x00020000 | 0x00020000 |( K0 {: ~% w- E1 v' \
- [I/FAL] | app | onchip_flash | 0x00040000 | 0x00020000 |
$ C' z/ A+ Z( O( v$ i) f - [I/FAL] | factory | onchip_flash | 0x00060000 | 0x00020000 |3 J5 Y% ~+ I4 Z4 ?; h1 W
- [I/FAL] =============================================================: h/ `6 s9 r3 ^
- [I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success., w/ B8 B2 Q: U6 @" `. |
- version 2.0.0 f3 D& {3 ]- P z
- msh >6 u0 \8 a1 n- y6 @' B/ Y
3 ]& i1 ]9 J1 {6 J2 V- / s+ V. a. u R7 s; G; q, v
- ( i( K1 ?3 I3 Y) c5 s' m
- [SFUD]Find a Winbond flash chip. Size is 16777216 bytes.2 B7 u/ b$ Y7 A. \
- [SFUD]spi flash device is initialize success.
) m( ^4 S4 b( |9 Z9 U - [D/FAL] (fal_flash_init:63) Flash device | onchip_flash | addr: 0x08000000 | len: 0x00080000 | blk_size: 0x00000800 |initialized finish.- u% G) [( w% K0 ]
- [D/FAL] (fal_flash_init:63) Flash device | nor_flash | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
7 I& `( ~& t9 B" X- p G& r! T - [I/FAL] ==================== FAL partition table ====================. F( a* W& ~: G u
- [I/FAL] | name | flash_dev | offset | length |
/ {8 i4 C5 N q! o* X7 d# ^ - [I/FAL] -------------------------------------------------------------
\) n, o" m- g( b6 e" }: Z6 s0 W - [I/FAL] | app | onchip_flash | 0x00040000 | 0x00020000 |
! z2 g0 y' Q( F- X" `/ i. M - [I/FAL] | download | onchip_flash | 0x00020000 | 0x00020000 |
$ P4 v/ S0 X$ _5 j* d; r) {- r' z - [I/FAL] | factory | onchip_flash | 0x00060000 | 0x00020000 |: o9 F4 P& R7 w( P1 {0 r
- [I/FAL] =============================================================
5 e5 j# K/ n [* j - [I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.
! j/ e. d( k5 o - [I]RT-Thread OTA package(V0.2.1) initialize success.; e4 W/ E# h8 d% [) `) s: N
- [I]Verify 'factory' partition(fw ver: 2.0.0, timestamp: 1570940368) success.: o/ H9 v) F& k) w2 Z2 l
- [E]Get firmware header occur CRC32(calc.crc: 7b93c5c8 != hdr.info_crc32: ffffffff) error on 'app' partition!
7 m& p$ D. l8 E% U' }6 F2 J4 K - [I]OTA firmware(app) upgrade startup./ v) B3 C+ E9 N3 S0 X
- [I]The partition 'app' is erasing.
, @9 @- {8 t1 ] - [I]The partition 'app' erase success.
3 Q# t/ X) E2 n$ o) ^& K* S- Q - [I]OTA Write: [====================================================================================================] 100%; h1 H( |2 V6 c. T7 o9 u
- [I]Verify 'app' partition(fw ver: 2.0.0, timestamp: 1570940368) success.- V5 J. C9 K* E3 v( \
- [I/FAL] Find user firmware at app partition 0x08040000 successfully.
- g/ o* P: M; e# g - [I/FAL] Bootloader jumps to user firmware now.. a8 ~& ^+ ?* n) R5 g
: I8 W6 Y g V8 q- \ | /' l' k. E4 b; V: M& t/ P
- - RT - Thread Operating System
" S9 }: [8 c9 `& o8 @: b - / | \ 4.0.0 build Oct 13 2019
+ Y* }9 K) _8 M0 k - 2006 - 2018 Copyright by rt-thread team1 ]9 O5 ~8 {% p6 B8 t
- [D/FAL] (fal_flash_init:61) Flash device | onchip_flash | addr: 0x08000000 | len: 0x00080000 | blk_size: 0x00000800 |initialized finish.
2 t; F" }' X M% F B' M - [I/FAL] ==================== FAL partition table ====================$ G. n* u# W. u) ^2 ^# w
- [I/FAL] | name | flash_dev | offset | length |
$ Z. Q" Q, o$ n: i c2 K8 D - [I/FAL] -------------------------------------------------------------
( d% M9 }. ^! r, J9 m6 p - [I/FAL] | bl | onchip_flash | 0x00000000 | 0x00020000 |
' a& f" O8 m* ?8 w/ t8 _' F - [I/FAL] | download | onchip_flash | 0x00020000 | 0x00020000 |
; D4 T; N7 j: j: D1 h - [I/FAL] | app | onchip_flash | 0x00040000 | 0x00020000 |
" a! h6 R6 N; t - [I/FAL] | factory | onchip_flash | 0x00060000 | 0x00020000 |
6 K' c, Q1 d# b: i8 V7 K( ` - [I/FAL] =============================================================& S% U% C% ^$ z1 N/ X9 [# D( i5 A
- [I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.
$ r, H6 h$ J, o; |0 \- q7 z - version 1.0.0
' K2 @' s6 \! [5 d) ` - msh >$ i( A7 i4 l( _ T# e% x% g
- / s0 H/ g/ N/ r, W( B# F% [' ^
复制代码 8 Q( T& R; |' s3 f
————————————————
9 k9 A+ G# ` i# K+ s$ _; O版权声明:小盼你最萌哒如有侵权请联系删除
' ` L0 w2 k) |3 F, R8 d; l8 t1 z5 Y& X4 X' @( N+ h
9 ?2 s( c' r+ \, _' A |