From 745a8c8e0e14ff7902da18e1adf396d6234a131a Mon Sep 17 00:00:00 2001 From: mikee47 Date: Thu, 31 Oct 2019 11:36:57 +0000 Subject: [PATCH 1/2] Fix `flashmem_get_address()` to account for rBoot mapping --- Sming/Arch/Esp8266/Components/spi_flash/component.mk | 2 +- Sming/Arch/Esp8266/Components/spi_flash/flashmem.c | 10 ++++++++++ .../Components/spi_flash/include/esp_spi_flash.h | 9 +++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Sming/Arch/Esp8266/Components/spi_flash/component.mk b/Sming/Arch/Esp8266/Components/spi_flash/component.mk index 5fee1d9bc1..7f9519d25d 100644 --- a/Sming/Arch/Esp8266/Components/spi_flash/component.mk +++ b/Sming/Arch/Esp8266/Components/spi_flash/component.mk @@ -1 +1 @@ -COMPONENT_DEPENDS := esp8266 +COMPONENT_DEPENDS := esp8266 rboot diff --git a/Sming/Arch/Esp8266/Components/spi_flash/flashmem.c b/Sming/Arch/Esp8266/Components/spi_flash/flashmem.c index a764b8bd54..f7549d0e05 100644 --- a/Sming/Arch/Esp8266/Components/spi_flash/flashmem.c +++ b/Sming/Arch/Esp8266/Components/spi_flash/flashmem.c @@ -17,6 +17,7 @@ #include "include/esp_spi_flash.h" #include "espinc/peri.h" +#include extern char _flash_code_end[]; @@ -40,6 +41,15 @@ static inline uint32_t min(uint32_t a, uint32_t b) return (a < b) ? a : b; } +uint32_t flashmem_get_address(const void* memptr) +{ + rboot_config config = rboot_get_config(); + uint32_t addr = config.roms[config.current_rom]; + addr -= (BOOT_CONFIG_SECTOR + 1) * INTERNAL_FLASH_SECTOR_SIZE; + addr += (uint32_t)memptr - INTERNAL_FLASH_START_ADDRESS; + return addr; +} + uint32_t flashmem_write(const void* from, uint32_t toaddr, uint32_t size) { if(IS_ALIGNED(from) && IS_ALIGNED(toaddr) && IS_ALIGNED(size)) diff --git a/Sming/Arch/Esp8266/Components/spi_flash/include/esp_spi_flash.h b/Sming/Arch/Esp8266/Components/spi_flash/include/esp_spi_flash.h index cba56c919d..6b8a1f6d41 100644 --- a/Sming/Arch/Esp8266/Components/spi_flash/include/esp_spi_flash.h +++ b/Sming/Arch/Esp8266/Components/spi_flash/include/esp_spi_flash.h @@ -66,13 +66,10 @@ typedef struct * @param memptr * @retval uint32_t Offset from start of flash memory * @note If memptr is not in valid flash memory it will return an offset which exceeds - * the internal flash memory size. This is caught by constructors using getMaxSize() - * to provide a zero-length extent. + * the internal flash memory size. + * @note The flash location is dependent on where rBoot has mapped the firmware. */ -static inline uint32_t flashmem_get_address(const void* memptr) -{ - return (uint32_t)memptr - INTERNAL_FLASH_START_ADDRESS; -} +uint32_t flashmem_get_address(const void* memptr); /** @brief Write a block of data to flash * @param from Buffer to obtain data from From cbdef5503edc6c9e4e44d6ee4c7f0fe4670481f0 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Sun, 3 Nov 2019 08:39:28 +0000 Subject: [PATCH 2/2] Revert changes and deprecate function. To be addressed more fully in a future PR. --- Sming/Arch/Esp8266/Components/spi_flash/component.mk | 2 +- Sming/Arch/Esp8266/Components/spi_flash/flashmem.c | 10 ---------- .../Components/spi_flash/include/esp_spi_flash.h | 10 +++++++--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Sming/Arch/Esp8266/Components/spi_flash/component.mk b/Sming/Arch/Esp8266/Components/spi_flash/component.mk index 7f9519d25d..5fee1d9bc1 100644 --- a/Sming/Arch/Esp8266/Components/spi_flash/component.mk +++ b/Sming/Arch/Esp8266/Components/spi_flash/component.mk @@ -1 +1 @@ -COMPONENT_DEPENDS := esp8266 rboot +COMPONENT_DEPENDS := esp8266 diff --git a/Sming/Arch/Esp8266/Components/spi_flash/flashmem.c b/Sming/Arch/Esp8266/Components/spi_flash/flashmem.c index f7549d0e05..a764b8bd54 100644 --- a/Sming/Arch/Esp8266/Components/spi_flash/flashmem.c +++ b/Sming/Arch/Esp8266/Components/spi_flash/flashmem.c @@ -17,7 +17,6 @@ #include "include/esp_spi_flash.h" #include "espinc/peri.h" -#include extern char _flash_code_end[]; @@ -41,15 +40,6 @@ static inline uint32_t min(uint32_t a, uint32_t b) return (a < b) ? a : b; } -uint32_t flashmem_get_address(const void* memptr) -{ - rboot_config config = rboot_get_config(); - uint32_t addr = config.roms[config.current_rom]; - addr -= (BOOT_CONFIG_SECTOR + 1) * INTERNAL_FLASH_SECTOR_SIZE; - addr += (uint32_t)memptr - INTERNAL_FLASH_START_ADDRESS; - return addr; -} - uint32_t flashmem_write(const void* from, uint32_t toaddr, uint32_t size) { if(IS_ALIGNED(from) && IS_ALIGNED(toaddr) && IS_ALIGNED(size)) diff --git a/Sming/Arch/Esp8266/Components/spi_flash/include/esp_spi_flash.h b/Sming/Arch/Esp8266/Components/spi_flash/include/esp_spi_flash.h index 6b8a1f6d41..ebeb897a9b 100644 --- a/Sming/Arch/Esp8266/Components/spi_flash/include/esp_spi_flash.h +++ b/Sming/Arch/Esp8266/Components/spi_flash/include/esp_spi_flash.h @@ -66,10 +66,14 @@ typedef struct * @param memptr * @retval uint32_t Offset from start of flash memory * @note If memptr is not in valid flash memory it will return an offset which exceeds - * the internal flash memory size. - * @note The flash location is dependent on where rBoot has mapped the firmware. + * the internal flash memory size. This is caught by constructors using getMaxSize() + * to provide a zero-length extent. + * @deprecated This function only works if rBoot is running from slot #0. */ -uint32_t flashmem_get_address(const void* memptr); +SMING_DEPRECATED static inline uint32_t flashmem_get_address(const void* memptr) +{ + return (uint32_t)memptr - INTERNAL_FLASH_START_ADDRESS; +} /** @brief Write a block of data to flash * @param from Buffer to obtain data from