From 4c6697fc92a78b4a73b39e9248f60f74fb1ffec1 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Thu, 31 Oct 2019 11:36:57 +0000 Subject: [PATCH] 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