2929 * process.
3030 */
3131
32- static char * flashAddr ;
32+ static const char * flashAddr ;
3333static uint32_t flashSize ;
3434static uint32_t flashAddrPhys ;
3535static uint32_t flashSector ;
@@ -106,20 +106,20 @@ LUA_API void dumpStrings(lua_State *L) {
106106 * writes are suppressed if the global writeToFlash is false. This is used in
107107 * phase I where the pass is used to size the structures in flash.
108108 */
109- static char * flashPosition (void ){
109+ static const char * flashPosition (void ){
110110 return flashAddr + curOffset ;
111111}
112112
113113
114- static char * flashSetPosition (uint32_t offset ){
114+ static const char * flashSetPosition (uint32_t offset ){
115115 NODE_DBG ("flashSetPosition(%04x)\n" , offset );
116116 curOffset = offset ;
117117 return flashPosition ();
118118}
119119
120120
121- static char * flashBlock (const void * b , size_t size ) {
122- void * cur = flashPosition ();
121+ static const char * flashBlock (const void * b , size_t size ) {
122+ const void * cur = flashPosition ();
123123 NODE_DBG ("flashBlock((%04x),%p,%04x)\n" , curOffset ,b ,size );
124124 lua_assert (ALIGN_BITS (b ) == 0 && ALIGN_BITS (size ) == 0 );
125125 platform_flash_write (b , flashAddrPhys + curOffset , size );
@@ -137,6 +137,10 @@ static void flashErase(uint32_t start, uint32_t end){
137137 platform_flash_erase_sector ( flashSector + i );
138138}
139139
140+ static int loadLFS (lua_State * L );
141+ static int loadLFSgc (lua_State * L );
142+ static void procFirstPass (void );
143+
140144/* =====================================================================================
141145 * luaN_init() is exported via lflash.h.
142146 * The first is the startup hook used in lstate.c and the last two are
@@ -171,7 +175,7 @@ LUAI_FUNC void luaN_init (lua_State *L) {
171175 }
172176
173177 if ((fh -> flash_sig & (~FLASH_SIG_ABSOLUTE )) != FLASH_SIG ) {
174- NODE_ERR ("Flash sig not correct: 0x%08x vs 0x%08x \n" ,
178+ NODE_ERR ("LFS sig not correct: 0x%x vs expected 0x%x \n" ,
175179 fh -> flash_sig & (~FLASH_SIG_ABSOLUTE ), FLASH_SIG );
176180 return ;
177181 }
@@ -208,6 +212,7 @@ LUALIB_API void luaL_lfsreload (lua_State *L) {
208212 return ;
209213 }
210214
215+
211216 /*
212217 * Do a protected call of loadLFS.
213218 *
@@ -346,13 +351,13 @@ static void put_byte (uint8_t value) {
346351}
347352
348353
349- static uint8_t recall_byte (unsigned offset ) {
354+ static uint8_t recall_byte (uint32_t offset ) {
350355 if (offset > DICTIONARY_WINDOW || offset >= out -> ndx )
351356 flash_error ("invalid dictionary offset on inflate" );
352357 /* ndx starts at 1. Need relative to 0 */
353- unsigned n = out -> ndx - offset ;
354- unsigned pos = n % WRITE_BLOCKSIZE ;
355- unsigned blockNo = out -> ndx / WRITE_BLOCKSIZE - n / WRITE_BLOCKSIZE ;
358+ uint32_t n = out -> ndx - offset ;
359+ uint32_t pos = n % WRITE_BLOCKSIZE ;
360+ uint32_t blockNo = out -> ndx / WRITE_BLOCKSIZE - n / WRITE_BLOCKSIZE ;
356361 return out -> block [blockNo ]-> byte [pos ];
357362}
358363
@@ -386,7 +391,7 @@ void procFirstPass (void) {
386391 fh -> flash_size > flashSize ||
387392 out -> flagsLen != 1 + (out -> flashLen /WORDSIZE - 1 ) / BITS_PER_WORD )
388393 flash_error ("LFS length mismatch" );
389- out -> flags = luaM_newvector (out -> L , out -> flagsLen , unsigned );
394+ out -> flags = luaM_newvector (out -> L , out -> flagsLen , uint32_t );
390395 }
391396
392397 /* update running CRC */
@@ -412,7 +417,7 @@ void procSecondPass (void) {
412417 (out -> flashLen % WRITE_BLOCKSIZE ) / WORDSIZE :
413418 WRITE_BLOCKSIZE / WORDSIZE ;
414419 uint32_t * buf = (uint32_t * ) out -> buffer .byte ;
415- uint32_t flags = 0 ;
420+ uint32_t flags = 0 ;
416421 /*
417422 * Relocate all the addresses tagged in out->flags. This can't be done in
418423 * place because the out->blocks are still in use as dictionary content so
@@ -423,7 +428,7 @@ void procSecondPass (void) {
423428 if ((i & 31 )== 0 )
424429 flags = out -> flags [out -> flagsNdx ++ ];
425430 if (flags & 1 )
426- buf [i ] = WORDSIZE * buf [i ] + cast (uint32_t , flashAddr );
431+ buf [i ] = WORDSIZE * buf [i ] + cast (uint32_t , flashAddr ); // mapped, not phys
427432 }
428433 /*
429434 * On first block, set the flash_sig has the in progress bit set and this
@@ -468,7 +473,7 @@ static int loadLFS (lua_State *L) {
468473 in -> len = vfs_size (in -> fd );
469474 if (in -> len <= 200 || /* size of an empty luac output */
470475 vfs_lseek (in -> fd , in -> len - 4 , VFS_SEEK_SET ) != in -> len - 4 ||
471- vfs_read (in -> fd , & out -> len , sizeof (unsigned )) != sizeof (unsigned ))
476+ vfs_read (in -> fd , & out -> len , sizeof (uint32_t )) != sizeof (uint32_t ))
472477 flash_error ("read error on LFS image file" );
473478 vfs_lseek (in -> fd , 0 , VFS_SEEK_SET );
474479
0 commit comments