libesphttpd icon indicating copy to clipboard operation
libesphttpd copied to clipboard

ESP8266 espfs.c espFsInit() flashAddress calculated incorrectly for user2.bin OTA

Open isavitsky opened this issue 5 years ago • 0 comments

When system boots into user2.bin in espFsInit() the flashAddress is been always calculated to user1.bin location in the following prtion of code in espfs.c:

	if((uint32_t)flashAddress > 0x40000000) {
		flashAddress = (void*)((uint32_t)flashAddress-FLASH_BASE_ADDR);
	}

The following part of code can be added after the above to correct this:

    uint32_t shift;
    if ( system_get_userbin_addr() > 0x01000 )
    { // user2.bin
        uint8_t map = system_get_flash_size_map();
        switch ( map )
        {
            case FLASH_SIZE_4M_MAP_256_256:
                shift = 256*1024; // 256kB
                break;
            case FLASH_SIZE_8M_MAP_512_512:
            case FLASH_SIZE_16M_MAP_512_512:
            case FLASH_SIZE_32M_MAP_512_512:
                shift = 512*1024; // 512kB
                break;
            case FLASH_SIZE_16M_MAP_1024_1024:
            case FLASH_SIZE_32M_MAP_1024_1024:
            case FLASH_SIZE_64M_MAP_1024_1024:
            case FLASH_SIZE_128M_MAP_1024_1024:
                shift = 1024*1024; // 1MB
                break;
            default:
                shift = 512*1024;
        }
        flashAddress = (void *)((uint32_t)flashAddress + shift);
    }

isavitsky avatar Nov 03 '19 18:11 isavitsky