Browse Source

SDK 3.0 tranche3 (#2761)

Force libpp.a into iRAM, and backout redundant IRAM_DATA_ATTR changes
Terry Ellison 5 years ago
parent
commit
d6980ad802

+ 1 - 1
app/esp-gdbstub/gdbstub.c

@@ -107,7 +107,7 @@ extern void xthal_set_intenable(int);
 #define OBUFLEN 32
 
 //The asm stub saves the Xtensa registers here when a debugging exception happens.
-struct XTensa_exception_frame_s IRAM_DATA_ATTR gdbstub_savedRegs;
+struct XTensa_exception_frame_s gdbstub_savedRegs;
 #if GDBSTUB_USE_OWN_STACK
 //This is the debugging exception stack.
 int exceptionStack[256];

+ 1 - 8
app/include/user_config.h

@@ -273,14 +273,7 @@ extern void luaL_dbgbreak(void);
 #define ICACHE_STORE_ATTR __attribute__((aligned(4)))
 #define ICACHE_STRING(x) ICACHE_STRING2(x)
 #define ICACHE_STRING2(x) #x
-#define ICACHE_RAM_ATTR \
-  __attribute__((section(".iram0.text." __FILE__ "." ICACHE_STRING(__LINE__))))
-#define ICACHE_FLASH_RESERVED_ATTR \
-  __attribute__((section(".irom.reserved." __FILE__ "." ICACHE_STRING(__LINE__)),\
-                 used,unused,aligned(INTERNAL_FLASH_SECTOR_SIZE)))
-#define IRAM_DATA_ATTR \
-  __attribute__((section(".iram0.data." __FILE__ "." ICACHE_STRING(__LINE__))))
-
+#define ICACHE_RAM_ATTR __attribute__((section(".iram0.text." __FILE__ "." ICACHE_STRING(__LINE__))))
 #ifdef  GPIO_SAFE_NO_INTR_ENABLE
 #define NO_INTR_CODE ICACHE_RAM_ATTR __attribute__ ((noinline))
 #else

+ 2 - 8
app/lua/lauxlib.c

@@ -918,11 +918,6 @@ static int l_check_memlimit(lua_State *L, size_t needbytes) {
   return (g->totalbytes >= limit) ? 1 : 0;
 }
 
-#ifndef LUA_CROSS_COMPILER
-#define REALLOC(p,o,n) (void *) this_realloc(p,o,n)
-#else
-#define REALLOC(p,o,n) (void *) (ptr? this_realloc(p,o,n) : c_malloc(n))
-#endif
 
 static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
   lua_State *L = (lua_State *)ud;
@@ -951,11 +946,10 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
     if(G(L)->memlimit > 0 && (mode & EGC_ON_MEM_LIMIT) && l_check_memlimit(L, nsize - osize))
       return NULL;
   }
-  nptr = REALLOC(ptr, osize, nsize);
+  nptr = (void *)this_realloc(ptr, osize, nsize);
   if (nptr == NULL && L != NULL && (mode & EGC_ON_ALLOC_FAILURE)) {
-    dbg_printf("Emergency full collection\n");  /**** DEBUG ***/
     luaC_fullgc(L); /* emergency full collection. */
-    nptr = REALLOC(ptr, osize, nsize); /* try allocation again */
+    nptr = (void *)this_realloc(ptr, osize, nsize); /* try allocation again */
   }
   return nptr;
 }

+ 1 - 6
app/lua/lrotable.c

@@ -15,11 +15,6 @@
 #define ALIGNED_STRING (__attribute__((aligned(4))) char *)
 #endif
 
-#ifdef LUA_CROSS_COMPILER
-#undef IRAM_DATA_ATTR
-#define IRAM_DATA_ATTR
-#endif
-
 #define LA_LINES 32
 #define LA_SLOTS 4
 //#define COLLECT_STATS
@@ -50,7 +45,7 @@ typedef struct {
   unsigned ndx:8;
 } cache_line_t;
 
-static cache_line_t IRAM_DATA_ATTR cache[LA_LINES][LA_SLOTS];
+static cache_line_t cache [LA_LINES][LA_SLOTS];
 
 #ifdef COLLECT_STATS
 unsigned cache_stats[3];

+ 1 - 1
app/lwip/core/dns.c

@@ -222,7 +222,7 @@ static void dns_check_entries(void);
 /* DNS variables */
 static struct udp_pcb        *dns_pcb;
 static u8_t                   dns_seqno;
-static struct dns_table_entry IRAM_DATA_ATTR dns_table[DNS_TABLE_SIZE];
+static struct dns_table_entry dns_table[DNS_TABLE_SIZE];
 static ip_addr_t              dns_servers[DNS_MAX_SERVERS];
 /** Contiguous buffer for processing responses */
 //static u8_t                   dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)];

+ 8 - 0
app/modules/file.c

@@ -703,6 +703,14 @@ LROT_END( file, NULL, 0 )
 
 
 int luaopen_file( lua_State *L ) {
+  if (!vfs_mount("/FLASH", 0)) {
+      // Failed to mount -- try reformat
+      dbg_printf("Formatting file system. Please wait...\n");
+      if (!vfs_format()) {
+          NODE_ERR( "\n*** ERROR ***: unable to format. FS might be compromised.\n" );
+          NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
+      }
+  }
   luaL_rometatable( L, "file.vol",  LROT_TABLEREF(file_vol));
   luaL_rometatable( L, "file.obj",  LROT_TABLEREF(file_obj));
   return 0;

+ 0 - 1
app/platform/platform.c

@@ -923,7 +923,6 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size )
 int platform_flash_erase_sector( uint32_t sector_id )
 {
   NODE_DBG( "flash_erase_sector(%u)\n", sector_id);
-  system_soft_wdt_feed ();
   return flash_erase( sector_id ) == SPI_FLASH_RESULT_OK ? PLATFORM_OK : PLATFORM_ERR;
 }
 

+ 14 - 27
app/spiffs/spiffs.c

@@ -28,10 +28,10 @@ static spiffs fs;
 #define MASK_1MB (0x100000-1)
 #define ALIGN (0x2000)
 
-static u8_t IRAM_DATA_ATTR spiffs_work_buf[LOG_PAGE_SIZE*2];
+static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2];
 static u8_t spiffs_fds[sizeof(spiffs_fd) * SPIFFS_MAX_OPEN_FILES];
 #if SPIFFS_CACHE
-static u8_t IRAM_DATA_ATTR myspiffs_cache[20 + (LOG_PAGE_SIZE+20)*4];
+static u8_t myspiffs_cache[20 + (LOG_PAGE_SIZE+20)*4];
 #endif
 
 static s32_t my_spiffs_read(u32_t addr, u32_t size, u8_t *dst) {
@@ -44,12 +44,18 @@ static s32_t my_spiffs_write(u32_t addr, u32_t size, u8_t *src) {
   return SPIFFS_OK;
 }
 
+static int erase_cnt = -1;  // If set to >=0 then erasing gives a ... feedback
 static s32_t my_spiffs_erase(u32_t addr, u32_t size) {
   u32_t sect_first = platform_flash_get_sector_of_address(addr);
   u32_t sect_last = sect_first;
-  while( sect_first <= sect_last )
-    if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR )
+  while( sect_first <= sect_last ) {
+    if (erase_cnt >= 0 && (erase_cnt++ & 0xF) == 0) {
+      dbg_printf(".");
+    }
+    if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR ) {
       return SPIFFS_ERR_INTERNAL;
+    }
+  }
   return SPIFFS_OK;
 }
 
@@ -152,31 +158,12 @@ int myspiffs_format( void )
   SPIFFS_unmount(&fs);
 
   NODE_DBG("Formatting: size 0x%x, addr 0x%x\n", fs.cfg.phys_size, fs.cfg.phys_addr);
+  erase_cnt = 0;
+  int status = SPIFFS_format(&fs);
+  erase_cnt = -1;
 
-  if (SPIFFS_format(&fs) < 0) {
-    return 0;
-  }
-
-  return myspiffs_mount(FALSE);
-}
-
-#if 0
-void test_spiffs() {
-  char buf[12];
-
-  // Surely, I've mounted spiffs before entering here
-
-  spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
-  if (SPIFFS_write(&fs, fd, (u8_t *)"Hello world", 12) < 0) NODE_DBG("errno %i\n", SPIFFS_errno(&fs));
-  SPIFFS_close(&fs, fd);
-
-  fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
-  if (SPIFFS_read(&fs, fd, (u8_t *)buf, 12) < 0) NODE_DBG("errno %i\n", SPIFFS_errno(&fs));
-  SPIFFS_close(&fs, fd);
-
-  NODE_DBG("--> %s <--\n", buf);
+  return status < 0 ? 0 : myspiffs_mount(FALSE);
 }
-#endif
 
 
 // ***************************************************************************

+ 4 - 14
app/user/user_main.c

@@ -92,6 +92,7 @@ static const struct defaultpt rompt IROM_PTABLE_ATTR USED_ATTR  = {
 
 static uint32_t first_time_setup(partition_item_t *pt, uint32_t n, uint32_t flash_size);
 static void phy_data_setup (partition_item_t *pt, uint32_t n);
+extern void _ResetHandler(void);
 
 /*
  * The non-OS SDK prolog has been fundamentally revised in V3.  See SDK EN document
@@ -166,7 +167,7 @@ void user_pre_init(void) {
         return;
     }
     os_printf("Invalid system partition table\n");
-    while(1); // Trigger WDT}
+    while (1) {};  
 }
 
 /*
@@ -266,7 +267,8 @@ static uint32_t first_time_setup(partition_item_t *pt, uint32_t n, uint32_t flas
     }
 
     platform_rcr_write(PLATFORM_RCR_PT, pt, newn*sizeof(partition_item_t));
-    while(1); // Trigger WDT; the new PT will be loaded on reboot
+    ets_delay_us(5000);
+    _ResetHandler(); // Trigger reset; the new PT will be loaded on reboot
 }
 
 uint32 ICACHE_RAM_ATTR user_iram_memory_is_enabled(void) {
@@ -305,18 +307,6 @@ void nodemcu_init(void) {
         NODE_DBG("Can not init platform for modules.\n");
         return;
     }
-
-#ifdef BUILD_SPIFFS
-    if (!vfs_mount("/FLASH", 0)) {
-        // Failed to mount -- try reformat
-        dbg_printf("Formatting file system. Please wait...\n");
-        if (!vfs_format()) {
-            NODE_ERR( "\n*** ERROR ***: unable to format. FS might be compromised.\n" );
-            NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
-        }
-    }
-#endif
-
     if (!task_post_low(task_get_id(start_lua),'s'))
       NODE_ERR("Failed to post the start_lua task!\n");
 }

+ 14 - 20
ld/nodemcu.ld

@@ -104,25 +104,20 @@ SECTIONS
     *(.entry.text)
     *(.init.literal)
     *(.init)
-
-    /* SDK libraries that used in bootup process, interruption handling
-     * and other ways where flash cache (iROM) is unavailable: */
-    *libmain.a:*(.literal .literal.* .text .text.*)
-    *libnet80211.a:*(.literal .text)
-    *libphy.a:*(.literal .text)
-    *libpp.a:*(.literal .text)
-    *libgcc.a:*(.literal .text)
-
-    /* Following SDK libraries have .text sections, but not included in iRAM: */
-    /* *libat.a:*(.literal .text) - not used anywhere in NodeMCU */
-    /* *libcrypto.a:*(.literal .text) - tested that safe to keep in iROM */
-    /* *libdriver.a:*(.literal .text) - not used anywhere in NodeMCU */
-    /* *libespnow.a:*(.literal .text) - not used anywhere in NodeMCU */
-    /* *liblwip_536.a:*(.literal .text) - source-based library used instead */
-    /* *libpwm.a:*(.literal .text) - our own implementation used instead */
-    /* *libwpa.a:*(.literal .text) - tested that safe to keep in iROM */
-    /* *libwps.a:*(.literal .text) - tested that safe to keep in iROM */
-
+   /*
+    * SDK libraries that used in bootup process, interruption handling
+    * and other ways where flash cache (iROM) is unavailable:
+    */
+    *libmain.a:*(    .literal .literal.* .text .text.*)
+    *libphy.a:*(     .literal .literal.* .text .text.*)
+    *libpp.a:*(      .literal .literal.* .text .text.*)
+    *libgcc.a:*(     .literal .literal.* .text .text.*)
+   /*
+    * The following SDK libraries have .literal and .text sections, but are
+    * either not used in NodeMCU or are safe to execute out of in iROM: 
+    *   libat.a libcrypto.a libdriver.a libnet80211.a libespnow.a
+    *   liblwip_536.a ibpwm.a libwpa.a ibwps.a
+    */
     *(.iram.text .iram0.text .iram0.text.*)
     *(.iram0.data.*)
 
@@ -260,7 +255,6 @@ SECTIONS
 
     /* Reserved areas, flash page aligned and last */
     . = ALIGN(4096);
-    KEEP(*(.irom.reserved .irom.reserved.*))
 
     _irom0_text_end = ABSOLUTE(.);
     _flash_used_end = ABSOLUTE(.);