From c57af8972ff84e305623b240281d6f55e8962c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Mon, 26 Dec 2016 14:17:57 +0100 Subject: [PATCH] Rework support for >4MB modules: place SPIFFS after SDK data (#1646) --- app/platform/flash_api.c | 6 ++++++ app/spiffs/spiffs.c | 10 ++++++++-- app/user/user_main.c | 21 +++++++++++++++------ docs/en/flash.md | 2 ++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index 72d0aff4..bee2149c 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -35,6 +35,12 @@ uint32_t flash_safe_get_size_byte(void) if (flash_size == 0) { flash_size = flash_detect_size_byte(); +#if !defined(FLASH_SAFE_API) + // clip maximum flash size to 4MByte if "SAFE API" is not used + if (flash_size > FLASH_SIZE_4MBYTE) { + flash_size = FLASH_SIZE_4MBYTE; + } +#endif } return flash_size; } diff --git a/app/spiffs/spiffs.c b/app/spiffs/spiffs.c index 3b71cc03..4670abd3 100644 --- a/app/spiffs/spiffs.c +++ b/app/spiffs/spiffs.c @@ -53,8 +53,14 @@ static bool myspiffs_set_location(spiffs_config *cfg, int align, int offset, int #ifdef SPIFFS_FIXED_LOCATION cfg->phys_addr = (SPIFFS_FIXED_LOCATION + block_size - 1) & ~(block_size-1); #else - cfg->phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL ) + offset; - cfg->phys_addr = (cfg->phys_addr + align - 1) & ~(align - 1); + if (flash_safe_get_size_byte() <= FLASH_SIZE_4MBYTE) { + // 256kByte - 4MByte modules: SPIFFS partition starts right after firmware image + cfg->phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL ) + offset; + cfg->phys_addr = (cfg->phys_addr + align - 1) & ~(align - 1); + } else { + // > 4MByte modules: SPIFFS partition starts after SDK data + cfg->phys_addr = flash_rom_get_size_byte(); + } #endif #ifdef SPIFFS_SIZE_1M_BOUNDARY cfg->phys_size = ((0x100000 - (SYS_PARAM_SEC_NUM * INTERNAL_FLASH_SECTOR_SIZE) - ( ( u32_t )cfg->phys_addr )) & ~(block_size - 1)) & 0xfffff; diff --git a/app/user/user_main.c b/app/user/user_main.c index da37ffa7..7af00ecc 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -122,17 +122,26 @@ void nodemcu_init(void) return; } -#if defined(FLASH_SAFE_API) - if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) { - NODE_ERR("Self adjust flash size.\n"); - // Fit hardware real flash size. - flash_rom_set_size_byte(flash_safe_get_size_byte()); + if( flash_safe_get_size_byte() <= FLASH_SIZE_4MBYTE ) { + if( flash_safe_get_size_byte() != flash_rom_get_size_byte() ) { + NODE_ERR("Self adjust flash size.\n"); + // Fit hardware real flash size. + flash_rom_set_size_byte(flash_safe_get_size_byte()); + + system_restart (); + // Don't post the start_lua task, we're about to reboot... + return; + } + } else if( (flash_rom_get_size_byte() < FLASH_SIZE_1MBYTE) || + (flash_rom_get_size_byte() > FLASH_SIZE_4MBYTE) ) { + NODE_ERR("Locking flash size for SDK to 1MByte.\n"); + // SDK/ROM can't handle flash size > 4MByte, ensure a minimum of 1MByte for firmware image + flash_rom_set_size_byte(FLASH_SIZE_1MBYTE); system_restart (); // Don't post the start_lua task, we're about to reboot... return; } -#endif // defined(FLASH_SAFE_API) #if defined ( CLIENT_SSL_ENABLE ) && defined ( SSL_BUFFER_SIZE ) espconn_secure_set_size(ESPCONN_CLIENT, SSL_BUFFER_SIZE); diff --git a/docs/en/flash.md b/docs/en/flash.md index ed1807e0..da41c296 100644 --- a/docs/en/flash.md +++ b/docs/en/flash.md @@ -32,6 +32,8 @@ Run the following command to flash an *aggregated* binary as is produced for exa - esptool.py is under heavy development. It's advised you run the latest version (check with `esptool.py version`). Since this documentation may not have been able to keep up refer to the [esptool flash modes documentation](https://github.com/themadinventor/esptool#flash-modes) for current options and parameters. - In some uncommon cases, the [SDK init data](#sdk-init-data) may be invalid and NodeMCU may fail to boot. The easiest solution is to fully erase the chip before flashing: `esptool.py --port erase_flash` +- Modules with flash chips larger than 4 MByte (e.g. WeMos D1 mini pro) need to be manually configured to at least 1 MByte: Firmware image and SDK init data occupy the first MByte, while the remaining 7/15 MByte of the flash are used for SPIFFS: +`esptool.py --port write_flash -fm -fs 8m 0x00000 .bin` ### NodeMCU Flasher > A firmware Flash tool for NodeMCU...We are working on next version and will use QT framework. It will be cross platform and open-source.