Skip to content

Commit

Permalink
Fix flashmem_get_address() to account for rBoot mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Oct 31, 2019
1 parent 1332a08 commit 4c6697f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sming/Arch/Esp8266/Components/spi_flash/component.mk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
COMPONENT_DEPENDS := esp8266
COMPONENT_DEPENDS := esp8266 rboot
10 changes: 10 additions & 0 deletions Sming/Arch/Esp8266/Components/spi_flash/flashmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "include/esp_spi_flash.h"
#include "espinc/peri.h"
#include <rboot-api.h>

extern char _flash_code_end[];

Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c6697f

Please sign in to comment.