44#include "configkeys.h"
55#include "flash_nrf5x.h"
66#include <string.h>
7+ #include <stdio.h>
78
89#include "bootloader_settings.h"
910#include "bootloader.h"
@@ -67,13 +68,12 @@ struct TextFile {
6768#define STR0 (x ) #x
6869#define STR (x ) STR0(x)
6970
70- const char infoUf2File [] = //
71+ char infoUf2File [128 * 3 ] =
7172 "UF2 Bootloader " UF2_VERSION "\r\n"
7273 "Model: " UF2_PRODUCT_NAME "\r\n"
73- "Board-ID: " UF2_BOARD_ID "\r\n"
74- "Date: " __DATE__ "\r\n" ;
74+ "Board-ID: " UF2_BOARD_ID "\r\n" ;
7575
76- const char indexFile [] = //
76+ const char indexFile [] =
7777 "<!doctype html>\n"
7878 "<html>"
7979 "<body>"
@@ -83,17 +83,17 @@ const char indexFile[] = //
8383 "</body>"
8484 "</html>\n" ;
8585
86- // WARNING -- code presumes only one NULL .content for .UF2 file
87- // and requires it be the last element of the array
8886static struct TextFile const info [] = {
8987 {.name = "INFO_UF2TXT" , .content = infoUf2File },
9088 {.name = "INDEX HTM" , .content = indexFile },
91- {.name = "CURRENT UF2" },
89+
90+ // current.uf2 must be the last element and its content must be NULL
91+ {.name = "CURRENT UF2" , .content = NULL },
9292};
9393
94- // WARNING -- code presumes each non-UF2 file content fits in single sector
95- // Cannot programmatically statically assert .content length
96- // for each element above.
94+ // code presumes each non-UF2 file content fits in single sector
95+ // Cannot programmatically statically assert .content length
96+ // for each element above.
9797STATIC_ASSERT (ARRAY_SIZE (indexFile ) < 512 );
9898
9999
@@ -180,7 +180,24 @@ static inline bool in_uicr_space(uint32_t addr)
180180
181181void uf2_init (void )
182182{
183- // nothing to do
183+ strcat (infoUf2File , "SoftDevice: " );
184+
185+ if ( is_sd_existed () )
186+ {
187+ uint32_t const sd_id = SD_ID_GET (MBR_SIZE );
188+ uint32_t const sd_version = SD_VERSION_GET (MBR_SIZE );
189+
190+ uint32_t const ver1 = sd_version / 1000000 ;
191+ uint32_t const ver2 = (sd_version % 1000000 )/1000 ;
192+ uint32_t const ver3 = sd_version % 1000 ;
193+
194+ sprintf (infoUf2File + strlen (infoUf2File ), "S%lu version %lu.%lu.%lu\r\n" , sd_id , ver1 , ver2 , ver3 );
195+ }else
196+ {
197+ strcat (infoUf2File , "not found\r\n" );
198+ }
199+
200+ strcat (infoUf2File , "Date: " __DATE__ "\r\n" );
184201}
185202
186203/*------------------------------------------------------------------*/
@@ -258,9 +275,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
258275 d -> updateTime = __DOSTIME__ ;
259276 d -> updateDate = __DOSDATE__ ;
260277 d -> startCluster = startCluster & 0xFF ;
261- // WARNING -- code presumes only one NULL .content for .UF2 file
262- // and requires it be the last element of the array
263- d -> size = inf -> content ? strlen (inf -> content ) : UF2_SIZE ;
278+ d -> size = (inf -> content ? strlen (inf -> content ) : UF2_SIZE );
264279 }
265280
266281 } else {
0 commit comments