diff --git a/Makefile b/Makefile index f3e8bc45..2e3f3900 100644 --- a/Makefile +++ b/Makefile @@ -207,14 +207,14 @@ sdk_patched: sdk_extracted $(TOP_DIR)/sdk/.patched-$(SDK_VER) $(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER): $(TOP_DIR)/cache/esp_iot_sdk_v$(SDK_FILE_VER).zip mkdir -p "$(dir $@)" - (cd "$(dir $@)" && rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK && unzip $(TOP_DIR)/cache/esp_iot_sdk_v$(SDK_FILE_VER).zip ESP8266_NONOS_SDK/lib/* ESP8266_NONOS_SDK/ld/eagle.rom.addr.v6.ld ESP8266_NONOS_SDK/include/* ) + (cd "$(dir $@)" && rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK && unzip $(TOP_DIR)/cache/esp_iot_sdk_v$(SDK_FILE_VER).zip ESP8266_NONOS_SDK/lib/* ESP8266_NONOS_SDK/ld/eagle.rom.addr.v6.ld ESP8266_NONOS_SDK/include/* ESP8266_NONOS_SDK/bin/esp_init_data_default.bin) mv $(dir $@)/ESP8266_NONOS_SDK $(dir $@)/esp_iot_sdk_v$(SDK_VER) rm -f $(SDK_DIR)/lib/liblwip.a touch $@ $(TOP_DIR)/sdk/.patched-$(SDK_VER): $(TOP_DIR)/cache/esp_iot_sdk_v$(SDK_PATCH_VER).zip mkdir -p "$(dir $@)/patch" - (cd "$(dir $@)/patch" && unzip $(TOP_DIR)/cache/esp_iot_sdk_v$(SDK_PATCH_VER)*.zip *.a && mv *.a $(SDK_DIR)/lib/) + (cd "$(dir $@)/patch" && unzip $(TOP_DIR)/cache/esp_iot_sdk_v$(SDK_PATCH_VER)*.zip *.a esp_init_data_default.bin && mv *.a $(SDK_DIR)/lib/ && mv esp_init_data_default.bin $(SDK_DIR)/bin/) rmdir $(dir $@)/patch rm -f $(SDK_DIR)/lib/liblwip.a touch $@ diff --git a/app/user/Makefile b/app/user/Makefile index 50da583a..87f4be55 100644 --- a/app/user/Makefile +++ b/app/user/Makefile @@ -24,7 +24,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit # makefile at its root level - these are then overridden # for a subtree within the makefile rooted therein # -#DEFINES += +DEFINES += -DESP_INIT_DATA_DEFAULT="\"$(SDK_DIR)/bin/esp_init_data_default.bin\"" ############################################################# # Recursion Magic - Don't touch this!! diff --git a/app/user/user_main.c b/app/user/user_main.c index 5c72d53b..41fb9408 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -31,6 +31,18 @@ static task_handle_t input_sig; +/* Contents of esp_init_data_default.bin */ +extern const uint32_t init_data[]; +extern const uint32_t init_data_end[]; +__asm__( + /* Place in .text for same reason as user_start_trampoline */ + ".section \".text\"\n" + ".align 4\n" + "init_data:\n" + ".incbin \"" ESP_INIT_DATA_DEFAULT "\"\n" + "init_data_end:\n" + ".previous\n" +); /* Note: the trampoline *must* be explicitly put into the .text segment, since * by the time it is invoked the irom has not yet been mapped. This naturally @@ -68,26 +80,8 @@ void TEXT_SECTION_ATTR user_start_trampoline (void) SPIRead (init_data_addr, &init_data_hdr, sizeof (init_data_hdr)); if (init_data_hdr == 0xffffffff) { - // Note: ideally we should generate the actual init data from the - // SDK's bin/esp_init_data_default.bin during the build, and #include it - // straight into this array. E.g.: - // xxd -i esp_init_data_default | tail -n13 | head -n11 > eidd.h - static uint8_t flash_init_data[128] __attribute__((aligned(4))) = - { - 0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, - 0x05, 0x04, 0x05, 0x05, 0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0, - 0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00, 0xf8, 0xf8, 0x52, 0x4e, - 0x4a, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; SPIEraseSector (init_data_addr); - SPIWrite (init_data_addr, (const uint32_t *)flash_init_data, sizeof (flash_init_data)); + SPIWrite (init_data_addr, init_data, 4 * (init_data_end - init_data)); } call_user_start ();