29
29
* process.
30
30
*/
31
31
32
- static char * flashAddr ;
32
+ static const char * flashAddr ;
33
33
static uint32_t flashSize ;
34
34
static uint32_t flashAddrPhys ;
35
35
static uint32_t flashSector ;
@@ -106,20 +106,20 @@ LUA_API void dumpStrings(lua_State *L) {
106
106
* writes are suppressed if the global writeToFlash is false. This is used in
107
107
* phase I where the pass is used to size the structures in flash.
108
108
*/
109
- static char * flashPosition (void ){
109
+ static const char * flashPosition (void ){
110
110
return flashAddr + curOffset ;
111
111
}
112
112
113
113
114
- static char * flashSetPosition (uint32_t offset ){
114
+ static const char * flashSetPosition (uint32_t offset ){
115
115
NODE_DBG ("flashSetPosition(%04x)\n" , offset );
116
116
curOffset = offset ;
117
117
return flashPosition ();
118
118
}
119
119
120
120
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 ();
123
123
NODE_DBG ("flashBlock((%04x),%p,%04x)\n" , curOffset ,b ,size );
124
124
lua_assert (ALIGN_BITS (b ) == 0 && ALIGN_BITS (size ) == 0 );
125
125
platform_flash_write (b , flashAddrPhys + curOffset , size );
@@ -137,6 +137,10 @@ static void flashErase(uint32_t start, uint32_t end){
137
137
platform_flash_erase_sector ( flashSector + i );
138
138
}
139
139
140
+ static int loadLFS (lua_State * L );
141
+ static int loadLFSgc (lua_State * L );
142
+ static void procFirstPass (void );
143
+
140
144
/* =====================================================================================
141
145
* luaN_init() is exported via lflash.h.
142
146
* 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) {
171
175
}
172
176
173
177
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" ,
175
179
fh -> flash_sig & (~FLASH_SIG_ABSOLUTE ), FLASH_SIG );
176
180
return ;
177
181
}
@@ -208,6 +212,7 @@ LUALIB_API void luaL_lfsreload (lua_State *L) {
208
212
return ;
209
213
}
210
214
215
+
211
216
/*
212
217
* Do a protected call of loadLFS.
213
218
*
@@ -346,13 +351,13 @@ static void put_byte (uint8_t value) {
346
351
}
347
352
348
353
349
- static uint8_t recall_byte (unsigned offset ) {
354
+ static uint8_t recall_byte (uint32_t offset ) {
350
355
if (offset > DICTIONARY_WINDOW || offset >= out -> ndx )
351
356
flash_error ("invalid dictionary offset on inflate" );
352
357
/* 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 ;
356
361
return out -> block [blockNo ]-> byte [pos ];
357
362
}
358
363
@@ -386,7 +391,7 @@ void procFirstPass (void) {
386
391
fh -> flash_size > flashSize ||
387
392
out -> flagsLen != 1 + (out -> flashLen /WORDSIZE - 1 ) / BITS_PER_WORD )
388
393
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 );
390
395
}
391
396
392
397
/* update running CRC */
@@ -412,7 +417,7 @@ void procSecondPass (void) {
412
417
(out -> flashLen % WRITE_BLOCKSIZE ) / WORDSIZE :
413
418
WRITE_BLOCKSIZE / WORDSIZE ;
414
419
uint32_t * buf = (uint32_t * ) out -> buffer .byte ;
415
- uint32_t flags = 0 ;
420
+ uint32_t flags = 0 ;
416
421
/*
417
422
* Relocate all the addresses tagged in out->flags. This can't be done in
418
423
* place because the out->blocks are still in use as dictionary content so
@@ -423,7 +428,7 @@ void procSecondPass (void) {
423
428
if ((i & 31 )== 0 )
424
429
flags = out -> flags [out -> flagsNdx ++ ];
425
430
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
427
432
}
428
433
/*
429
434
* 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) {
468
473
in -> len = vfs_size (in -> fd );
469
474
if (in -> len <= 200 || /* size of an empty luac output */
470
475
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 ))
472
477
flash_error ("read error on LFS image file" );
473
478
vfs_lseek (in -> fd , 0 , VFS_SEEK_SET );
474
479
0 commit comments