Spritetm / libesphttpd

NOTE: THIS CODE IS UNMAINTAINED. Please take a look at https://github.com/chmorgan/libesphttpd instead.
125 stars 109 forks source link

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

Open isavitsky opened 5 years ago

isavitsky commented 5 years ago

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);
    }