From 9845219a5f87d98b3681c2b926eeb690e496e27f Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 30 Sep 2018 12:27:06 +0800 Subject: [PATCH 1/2] bootloader_support: exclude bootloader_init.c when building app Depending on link order of libraries, bootloader implementation of __assert_func could be linked instead of the one provided by newlib. --- components/bootloader_support/CMakeLists.txt | 2 +- components/bootloader_support/component.mk | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/components/bootloader_support/CMakeLists.txt b/components/bootloader_support/CMakeLists.txt index 1f2885410..a6b559285 100644 --- a/components/bootloader_support/CMakeLists.txt +++ b/components/bootloader_support/CMakeLists.txt @@ -1,7 +1,6 @@ set(COMPONENT_SRCS "src/bootloader_clock.c" "src/bootloader_common.c" "src/bootloader_flash.c" - "src/bootloader_init.c" "src/bootloader_random.c" "src/bootloader_sha.c" "src/bootloader_utility.c" @@ -17,6 +16,7 @@ if(${BOOTLOADER_BUILD}) set(COMPONENT_ADD_INCLUDEDIRS "include include_priv") set(COMPONENT_REQUIRES) set(COMPONENT_PRIV_REQUIRES spi_flash micro-ecc) + list(APPEND COMPONENT_SRCS "src/bootloader_init.c") else() set(COMPONENT_ADD_INCLUDEDIRS "include") set(COMPONENT_PRIV_INCLUDEDIRS "include_priv") diff --git a/components/bootloader_support/component.mk b/components/bootloader_support/component.mk index dc449a601..dee3ecd7f 100644 --- a/components/bootloader_support/component.mk +++ b/components/bootloader_support/component.mk @@ -9,6 +9,10 @@ endif COMPONENT_SRCDIRS := src +ifndef IS_BOOTLOADER_BUILD +COMPONENT_OBJEXCLUDE := src/bootloader_init.o +endif + # # Secure boot signing key support # From 50d4ffd22e4fe4bfd09848a1db0bde6243804fd5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 26 Sep 2018 20:46:15 +0800 Subject: [PATCH 2/2] esp32: remove ROM functions redefined in IDF from LD script In some cases, linker could choose to use ROM functions instead of the ones defined in IDF. For functions used in ROM stub table, this would lead to infinite recursion when the corresponding function was called from ROM. For crypto functions, some of these were modified in IDF, and incompatible with ROM counterparts. --- .../subproject/main/esp32.bootloader.rom.ld | 3 + components/esp32/ld/esp32.rom.ld | 49 --------------- components/esp32/ld/esp32.rom.redefined.ld | 60 +++++++++++++++++++ .../ld/esp32.rom.spiram_incompatible_fns.ld | 4 -- components/newlib/locks.c | 2 + components/newlib/syscall_table.c | 2 +- 6 files changed, 66 insertions(+), 54 deletions(-) create mode 100644 components/esp32/ld/esp32.rom.redefined.ld diff --git a/components/bootloader/subproject/main/esp32.bootloader.rom.ld b/components/bootloader/subproject/main/esp32.bootloader.rom.ld index 70f83bdf5..b39af891d 100644 --- a/components/bootloader/subproject/main/esp32.bootloader.rom.ld +++ b/components/bootloader/subproject/main/esp32.bootloader.rom.ld @@ -1 +1,4 @@ PROVIDE ( ets_update_cpu_frequency = 0x40008550 ); /* Updates g_ticks_per_us on the current CPU only; not on the other core */ +PROVIDE ( MD5Final = 0x4005db1c ); +PROVIDE ( MD5Init = 0x4005da7c ); +PROVIDE ( MD5Update = 0x4005da9c ); diff --git a/components/esp32/ld/esp32.rom.ld b/components/esp32/ld/esp32.rom.ld index fe692a796..c7e5eb2f7 100644 --- a/components/esp32/ld/esp32.rom.ld +++ b/components/esp32/ld/esp32.rom.ld @@ -3,19 +3,13 @@ ESP32 ROM address table Generated for ROM with MD5sum: ab8282ae908fe9e7a63fb2a4ac2df013 ../../rom_image/prorom.elf */ -PROVIDE ( abort = 0x4000bba4 ); PROVIDE ( Add2SelfBigHex256 = 0x40015b7c ); PROVIDE ( AddBigHex256 = 0x40015b28 ); PROVIDE ( AddBigHexModP256 = 0x40015c98 ); PROVIDE ( AddP256 = 0x40015c74 ); PROVIDE ( AddPdiv2_256 = 0x40015ce0 ); -PROVIDE ( aes_128_cbc_decrypt = 0x4005cc7c ); -PROVIDE ( aes_128_cbc_encrypt = 0x4005cc18 ); -PROVIDE ( aes_unwrap = 0x4005ccf0 ); PROVIDE ( app_gpio_arg = 0x3ffe003c ); PROVIDE ( app_gpio_handler = 0x3ffe0040 ); -PROVIDE ( base64_decode = 0x4005ced8 ); -PROVIDE ( base64_encode = 0x4005cdbc ); PROVIDE ( BasePoint_x_256 = 0x3ff97488 ); PROVIDE ( BasePoint_y_256 = 0x3ff97468 ); PROVIDE ( bigHexInversion256 = 0x400168f0 ); @@ -98,12 +92,8 @@ PROVIDE ( ets_startup_callback = 0x3ffe0404 ); PROVIDE ( exc_cause_table = 0x3ff991d0 ); PROVIDE ( _exit_r = 0x4000bd28 ); PROVIDE ( free = 0x4000beb8 ); -PROVIDE ( _free_r = 0x4000bbcc ); PROVIDE ( _fstat_r = 0x4000bccc ); PROVIDE ( __gcc_bcmp = 0x40064a70 ); -PROVIDE ( _getpid_r = 0x4000bcfc ); -PROVIDE ( __getreent = 0x4000be8c ); -PROVIDE ( _gettimeofday_r = 0x4000bc58 ); PROVIDE ( GF_Jacobian_Point_Addition256 = 0x400163a4 ); PROVIDE ( GF_Jacobian_Point_Double256 = 0x40016260 ); PROVIDE ( GF_Point_Jacobian_To_Affine256 = 0x40016b0c ); @@ -127,16 +117,9 @@ PROVIDE ( hci_evt_dbg_desc_tab = 0x3ff9750c ); PROVIDE ( hci_evt_desc_tab = 0x3ff9751c ); PROVIDE ( hci_evt_le_desc_tab = 0x3ff974b4 ); PROVIDE ( hci_fc_env = 0x3ffb9340 ); -PROVIDE ( hmac_md5 = 0x4005d264 ); -PROVIDE ( hmac_md5_vector = 0x4005d17c ); -PROVIDE ( hmac_sha1 = 0x40060acc ); -PROVIDE ( hmac_sha1_vector = 0x400609e4 ); -PROVIDE ( hmac_sha256 = 0x40060d58 ); -PROVIDE ( hmac_sha256_vector = 0x40060c84 ); PROVIDE ( jd_decomp = 0x400613e8 ); PROVIDE ( jd_prepare = 0x40060fa8 ); PROVIDE ( ke_env = 0x3ffb93cc ); -PROVIDE ( _kill_r = 0x4000bd10 ); PROVIDE ( lb_default_handler = 0x3ff982b8 ); PROVIDE ( lb_default_state_tab_p_get = 0x4001c198 ); PROVIDE ( lb_env = 0x3ffb9424 ); @@ -199,23 +182,10 @@ PROVIDE ( lm_n_page_tab = 0x3ff990e8 ); PROVIDE ( lmp_desc_tab = 0x3ff96e6c ); PROVIDE ( lmp_ext_desc_tab = 0x3ff96d9c ); PROVIDE ( lm_state = 0x3ffb9a1c ); -PROVIDE ( _lock_acquire_recursive = 0x4000be28 ); -PROVIDE ( _lock_close = 0x4000bdec ); -PROVIDE ( _lock_close_recursive = 0x4000be00 ); -PROVIDE ( _lock_init = 0x4000bdc4 ); -PROVIDE ( _lock_init_recursive = 0x4000bdd8 ); -PROVIDE ( _lock_release_recursive = 0x4000be78 ); -PROVIDE ( _lock_try_acquire = 0x4000be3c ); -PROVIDE ( _lock_try_acquire_recursive = 0x4000be50 ); PROVIDE ( _lseek_r = 0x4000bd8c ); PROVIDE ( malloc = 0x4000bea0 ); -PROVIDE ( _malloc_r = 0x4000bbb4 ); PROVIDE ( maxSecretKey_256 = 0x3ff97448 ); PROVIDE ( __mb_cur_max = 0x3ff96530 ); -PROVIDE ( MD5Final = 0x4005db1c ); -PROVIDE ( MD5Init = 0x4005da7c ); -PROVIDE ( MD5Update = 0x4005da9c ); -PROVIDE ( md5_vector = 0x4005db80 ); PROVIDE ( mmu_init = 0x400095a4 ); PROVIDE ( __month_lengths = 0x3ff9609c ); PROVIDE ( MultiplyBigHexByUint32_256 = 0x40016214 ); @@ -228,7 +198,6 @@ PROVIDE ( mz_free = 0x4005eed4 ); PROVIDE ( notEqual256 = 0x40015b04 ); PROVIDE ( one_bits = 0x3ff971f8 ); PROVIDE ( _open_r = 0x4000bd54 ); -PROVIDE ( pbkdf2_sha1 = 0x40060ba4 ); PROVIDE ( phy_get_romfuncs = 0x40004100 ); PROVIDE ( _Pri_4_HandlerAddress = 0x3ffe0648 ); PROVIDE ( _Pri_5_HandlerAddress = 0x3ffe064c ); @@ -246,7 +215,6 @@ PROVIDE ( r_bt_util_buf_sync_rx_alloc = 0x40010468 ); PROVIDE ( r_bt_util_buf_sync_rx_free = 0x4001049c ); PROVIDE ( r_bt_util_buf_sync_tx_alloc = 0x400103ec ); PROVIDE ( r_bt_util_buf_sync_tx_free = 0x40010428 ); -PROVIDE ( rc4_skip = 0x40060928 ); PROVIDE ( r_co_bdaddr_compare = 0x40014324 ); PROVIDE ( r_co_bytes_to_string = 0x400142e4 ); PROVIDE ( r_co_list_check_size_available = 0x400142c4 ); @@ -293,7 +261,6 @@ PROVIDE ( r_ea_interval_remove = 0x40015590 ); PROVIDE ( ea_conflict_check = 0x40014e9c ); PROVIDE ( ea_prog_timer = 0x40014f88 ); PROVIDE ( realloc = 0x4000becc ); -PROVIDE ( _realloc_r = 0x4000bbe0 ); PROVIDE ( r_ea_offset_req = 0x40015748 ); PROVIDE ( r_ea_sleep_check = 0x40015928 ); PROVIDE ( r_ea_sw_isr = 0x40015724 ); @@ -1318,14 +1285,9 @@ PROVIDE ( rwip_priority = 0x3ff99159 ); PROVIDE ( rwip_rf = 0x3ffbdb28 ); PROVIDE ( rwip_rf_p_get = 0x400558f4 ); PROVIDE ( r_XorKey = 0x400112c0 ); -PROVIDE ( _sbrk_r = 0x4000bce4 ); PROVIDE ( __sf_fake_stderr = 0x3ff96458 ); PROVIDE ( __sf_fake_stdin = 0x3ff96498 ); PROVIDE ( __sf_fake_stdout = 0x3ff96478 ); -PROVIDE ( sha1_prf = 0x40060ae8 ); -PROVIDE ( sha1_vector = 0x40060b64 ); -PROVIDE ( sha256_prf = 0x40060d70 ); -PROVIDE ( sha256_vector = 0x40060e08 ); PROVIDE ( sha_blk_bits = 0x3ff99290 ); PROVIDE ( sha_blk_bits_bytes = 0x3ff99288 ); PROVIDE ( sha_blk_hash_bytes = 0x3ff9928c ); @@ -1381,7 +1343,6 @@ PROVIDE ( tdefl_get_prev_return_status = 0x400608d0 ); PROVIDE ( tdefl_init = 0x40060810 ); PROVIDE ( tdefl_write_image_to_png_file_in_memory = 0x4006091c ); PROVIDE ( tdefl_write_image_to_png_file_in_memory_ex = 0x40060910 ); -PROVIDE ( _times_r = 0x4000bc40 ); PROVIDE ( _timezone = 0x3ffae0a0 ); PROVIDE ( tinfl_decompress = 0x4005ef30 ); PROVIDE ( tinfl_decompress_mem_to_callback = 0x40060090 ); @@ -1514,7 +1475,6 @@ PROVIDE ( uart_tx_flush = 0x40009258 ); PROVIDE ( uart_tx_one_char = 0x40009200 ); PROVIDE ( uart_tx_one_char2 = 0x4000922c ); PROVIDE ( uart_tx_switch = 0x40009028 ); -PROVIDE ( uart_tx_wait_idle = 0x40009278 ); /* @@ -1581,8 +1541,6 @@ PROVIDE ( ets_efuse_read_op = 0x40008600 ); PROVIDE ( ets_intr_lock = 0x400067b0 ); PROVIDE ( ets_intr_unlock = 0x400067c4 ); PROVIDE ( ets_isr_attach = 0x400067ec ); -PROVIDE ( ets_isr_mask = 0x400067fc ); -PROVIDE ( ets_isr_unmask = 0x40006808 ); PROVIDE ( ets_waiti0 = 0x400067d8 ); PROVIDE ( intr_matrix_set = 0x4000681c ); PROVIDE ( check_pos = 0x400068b8 ); @@ -1622,13 +1580,6 @@ PROVIDE ( ets_delay_us = 0x40008534 ); PROVIDE ( ets_get_cpu_frequency = 0x4000855c ); PROVIDE ( ets_get_detected_xtal_freq = 0x40008588 ); PROVIDE ( ets_get_xtal_scale = 0x4000856c ); -PROVIDE ( ets_timer_arm = 0x40008368 ); -PROVIDE ( ets_timer_arm_us = 0x400083ac ); -PROVIDE ( ets_timer_disarm = 0x400083ec ); -PROVIDE ( ets_timer_done = 0x40008428 ); -PROVIDE ( ets_timer_handler_isr = 0x40008454 ); -PROVIDE ( ets_timer_init = 0x400084e8 ); -PROVIDE ( ets_timer_setfn = 0x40008350 ); PROVIDE ( ets_update_cpu_frequency_rom = 0x40008550 ); /* Updates g_ticks_per_us on the current CPU only; not on the other core */ /* Following are static data, but can be used, not generated by script <<<<< btdm data */ diff --git a/components/esp32/ld/esp32.rom.redefined.ld b/components/esp32/ld/esp32.rom.redefined.ld new file mode 100644 index 000000000..c229640a2 --- /dev/null +++ b/components/esp32/ld/esp32.rom.redefined.ld @@ -0,0 +1,60 @@ +/* + ROM Functions defined in this file are not used in ESP-IDF as is, + and different definitions for functions with the same names are provided. + This file is not used when linking ESP-IDF and is intended for reference only +*/ + +PROVIDE ( abort = 0x4000bba4 ); +PROVIDE ( aes_128_cbc_decrypt = 0x4005cc7c ); +PROVIDE ( aes_128_cbc_encrypt = 0x4005cc18 ); +PROVIDE ( aes_unwrap = 0x4005ccf0 ); +PROVIDE ( base64_decode = 0x4005ced8 ); +PROVIDE ( base64_encode = 0x4005cdbc ); +PROVIDE ( ets_isr_mask = 0x400067fc ); +PROVIDE ( ets_isr_unmask = 0x40006808 ); +PROVIDE ( ets_timer_arm = 0x40008368 ); +PROVIDE ( ets_timer_arm_us = 0x400083ac ); +PROVIDE ( ets_timer_disarm = 0x400083ec ); +PROVIDE ( ets_timer_done = 0x40008428 ); +PROVIDE ( ets_timer_init = 0x400084e8 ); +PROVIDE ( ets_timer_handler_isr = 0x40008454 ); +PROVIDE ( ets_timer_setfn = 0x40008350 ); +PROVIDE ( _free_r = 0x4000bbcc ); +PROVIDE ( _getpid_r = 0x4000bcfc ); +PROVIDE ( __getreent = 0x4000be8c ); +PROVIDE ( _gettimeofday_r = 0x4000bc58 ); +PROVIDE ( hmac_md5 = 0x4005d264 ); +PROVIDE ( hmac_md5_vector = 0x4005d17c ); +PROVIDE ( hmac_sha1 = 0x40060acc ); +PROVIDE ( hmac_sha1_vector = 0x400609e4 ); +PROVIDE ( hmac_sha256 = 0x40060d58 ); +PROVIDE ( hmac_sha256_vector = 0x40060c84 ); +PROVIDE ( _kill_r = 0x4000bd10 ); +PROVIDE ( _lock_acquire = 0x4000be14 ); +PROVIDE ( _lock_acquire_recursive = 0x4000be28 ); +PROVIDE ( _lock_close = 0x4000bdec ); +PROVIDE ( _lock_close_recursive = 0x4000be00 ); +PROVIDE ( _lock_init = 0x4000bdc4 ); +PROVIDE ( _lock_init_recursive = 0x4000bdd8 ); +PROVIDE ( _lock_release = 0x4000be64 ); +PROVIDE ( _lock_release_recursive = 0x4000be78 ); +PROVIDE ( _lock_try_acquire = 0x4000be3c ); +PROVIDE ( _lock_try_acquire_recursive = 0x4000be50 ); +PROVIDE ( _malloc_r = 0x4000bbb4 ); +PROVIDE ( MD5Final = 0x4005db1c ); +PROVIDE ( MD5Init = 0x4005da7c ); +PROVIDE ( MD5Update = 0x4005da9c ); +PROVIDE ( md5_vector = 0x4005db80 ); +PROVIDE ( pbkdf2_sha1 = 0x40060ba4 ); +PROVIDE ( rc4_skip = 0x40060928 ); +PROVIDE ( _raise_r = 0x4000bc70 ); +PROVIDE ( _realloc_r = 0x4000bbe0 ); +PROVIDE ( _sbrk_r = 0x4000bce4 ); +PROVIDE ( sha1_prf = 0x40060ae8 ); +PROVIDE ( sha1_vector = 0x40060b64 ); +PROVIDE ( sha256_prf = 0x40060d70 ); +PROVIDE ( sha256_vector = 0x40060e08 ); +PROVIDE ( _system_r = 0x4000bc10 ); +PROVIDE ( _times_r = 0x4000bc40 ); +PROVIDE ( uart_tx_wait_idle = 0x40009278 ); + diff --git a/components/esp32/ld/esp32.rom.spiram_incompatible_fns.ld b/components/esp32/ld/esp32.rom.spiram_incompatible_fns.ld index e4899b661..17a38d355 100644 --- a/components/esp32/ld/esp32.rom.spiram_incompatible_fns.ld +++ b/components/esp32/ld/esp32.rom.spiram_incompatible_fns.ld @@ -64,8 +64,6 @@ PROVIDE ( __locale_mb_cur_max = 0x40059548 ); PROVIDE ( __locale_msgcharset = 0x40059550 ); PROVIDE ( localtime = 0x400595dc ); PROVIDE ( localtime_r = 0x400595fc ); -PROVIDE ( _lock_acquire = 0x4000be14 ); -PROVIDE ( _lock_release = 0x4000be64 ); PROVIDE ( longjmp = 0x400562cc ); PROVIDE ( memccpy = 0x4000c220 ); PROVIDE ( memchr = 0x4000c244 ); @@ -77,7 +75,6 @@ PROVIDE ( memset = 0x4000c44c ); PROVIDE ( mktime = 0x4005a5e8 ); PROVIDE ( open = 0x4000178c ); PROVIDE ( qsort = 0x40056424 ); -PROVIDE ( _raise_r = 0x4000bc70 ); PROVIDE ( rand = 0x40001058 ); PROVIDE ( rand_r = 0x400010d4 ); PROVIDE ( read = 0x400017dc ); @@ -145,7 +142,6 @@ PROVIDE ( __swbuf = 0x40058cb4 ); PROVIDE ( __swbuf_r = 0x40058bec ); PROVIDE ( __swrite = 0x40001150 ); PROVIDE ( __swsetup_r = 0x40058cc8 ); -PROVIDE ( _system_r = 0x4000bc10 ); PROVIDE ( time = 0x40001844 ); PROVIDE ( __time_load_locale = 0x4000183c ); PROVIDE ( times = 0x40001808 ); diff --git a/components/newlib/locks.c b/components/newlib/locks.c index 026d8013d..646afd72c 100644 --- a/components/newlib/locks.c +++ b/components/newlib/locks.c @@ -118,6 +118,8 @@ void IRAM_ATTR _lock_close(_lock_t *lock) { portEXIT_CRITICAL(&lock_init_spinlock); } +void IRAM_ATTR _lock_close_recursive(_lock_t *lock) __attribute__((alias("_lock_close"))); + /* Acquire the mutex semaphore for lock. wait up to delay ticks. mutex_type is queueQUEUE_TYPE_RECURSIVE_MUTEX or queueQUEUE_TYPE_MUTEX */ diff --git a/components/newlib/syscall_table.c b/components/newlib/syscall_table.c index 624ffcffa..17920852a 100644 --- a/components/newlib/syscall_table.c +++ b/components/newlib/syscall_table.c @@ -70,7 +70,7 @@ static struct syscall_stub_table s_stub_table = { ._lock_init = &_lock_init, ._lock_init_recursive = &_lock_init_recursive, ._lock_close = &_lock_close, - ._lock_close_recursive = &_lock_close, + ._lock_close_recursive = &_lock_close_recursive, ._lock_acquire = &_lock_acquire, ._lock_acquire_recursive = &_lock_acquire_recursive, ._lock_try_acquire = &_lock_try_acquire,