@@ -34,9 +34,10 @@ struct sketch_header_v1 {
3434 uint8_t flags ; // @ 0x0e
3535} __attribute__((packed ));
3636
37- #define SKETCH_FLAG_DEBUG 0x01
38- #define SKETCH_FLAG_LINKED 0x02
39- #define SKETCH_FLAG_IMMEDIATE 0x04
37+ #define SKETCH_FLAG_DEBUG 0x01
38+ #define SKETCH_FLAG_LINKED 0x02
39+ #define SKETCH_FLAG_IMMEDIATE 0x04
40+ #define SKETCH_FLAG_WAIT_FOR_APP 0x08
4041
4142#define SKETCH_RAM_BUFFER_LEN 131072
4243
@@ -110,6 +111,11 @@ __attribute__((retain)) const uintptr_t sketch_max_size = DT_REG_SIZE(DT_NODELAB
110111#endif
111112__attribute__((retain )) const uintptr_t loader_max_size = LOADER_MAX_SIZE ;
112113
114+ struct backup_store {
115+ uint32_t wait_for_app_magic ;
116+ };
117+ volatile __stm32_backup_sram_section struct backup_store backup ;
118+
113119static int loader (const struct shell * sh ) {
114120 const struct flash_area * fa ;
115121 int rc ;
@@ -194,6 +200,8 @@ static int loader(const struct shell *sh) {
194200 char buf_loop ;
195201 } ;
196202
203+ backup .wait_for_app_magic = 0 ;
204+
197205 uintptr_t bootanimation_addr = DT_REG_ADDR (DT_GPARENT (DT_NODELABEL (bootanimation ))) +
198206 DT_REG_ADDR (DT_NODELABEL (bootanimation ));
199207
@@ -213,17 +221,6 @@ static int loader(const struct shell *sh) {
213221
214222 gpio_pin_configure_dt (& spec , GPIO_INPUT | GPIO_PULL_DOWN );
215223 k_sleep (K_MSEC (200 ));
216- uint8_t * ram_firmware = NULL ;
217- uint32_t * ram_start = (uint32_t * )0x20000000 ;
218- if (!sketch_valid ) {
219- ram_firmware = (uint8_t * )malloc (SKETCH_RAM_BUFFER_LEN );
220- if (!ram_firmware ) {
221- printk ("Failed to allocate RAM for firmware\n" );
222- return - ENOMEM ;
223- }
224- memset (ram_firmware , 0 , SKETCH_RAM_BUFFER_LEN );
225- * ram_start = (uint32_t )& ram_firmware [0 ];
226- }
227224 if (gpio_pin_get_dt (& spec ) == 0 ) {
228225 matrixBegin ();
229226 matrixSetGrayscaleBits (8 );
@@ -236,15 +233,10 @@ static int loader(const struct shell *sh) {
236233 k_sleep (K_MSEC (10 ));
237234 matrixEnd ();
238235 }
239- while (!sketch_valid ) {
240- __asm__("bkpt" );
241- // poll the first bytes, if filled try to use them for booting
242- sketch_hdr = (struct sketch_header_v1 * )(ram_firmware + 7 );
243- if (sketch_hdr -> ver == 0x1 && sketch_hdr -> magic == 0x2341 ) {
244- // Found valid data, use it for booting
245- base_addr = (uintptr_t )ram_firmware ;
246- * ram_start = 0 ;
247- sketch_valid = true;
236+
237+ if (sketch_hdr -> flags & SKETCH_FLAG_WAIT_FOR_APP ) {
238+ while (backup .wait_for_app_magic == 0 ) {
239+ k_sleep (K_MSEC (100 ));
248240 }
249241 }
250242 }
0 commit comments