From 13b3c916f306ab97877c5331cc9a15a6296616f7 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 7 Nov 2016 14:26:21 +0800 Subject: [PATCH 01/10] vfs: check error code returned by FS driver open function Fixes https://github.com/espressif/esp-idf/issues/78 --- components/vfs/vfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/vfs/vfs.c b/components/vfs/vfs.c index bf26968ff7..b60c60a818 100644 --- a/components/vfs/vfs.c +++ b/components/vfs/vfs.c @@ -151,6 +151,10 @@ int esp_vfs_open(struct _reent *r, const char * path, int flags, int mode) const char* path_within_vfs = translate_path(vfs, path); int ret; CHECK_AND_CALL(ret, r, vfs, open, path_within_vfs, flags, mode); + if (ret < 0) { + return ret; + } + assert(ret >= vfs->vfs.fd_offset); return ret - vfs->vfs.fd_offset + (vfs->offset << VFS_INDEX_S); } From aa0cd0ab474e6ba27dced833ef5ea440a3eabeb2 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 8 Nov 2016 09:02:30 +0800 Subject: [PATCH 02/10] spi_flash: add missing volatile qualifier for lock flags http://esp32.com/viewtopic.php?f=14&t=419&p=1901 --- components/spi_flash/cache_utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/spi_flash/cache_utils.c b/components/spi_flash/cache_utils.c index 6ae47bdb3e..904007b316 100644 --- a/components/spi_flash/cache_utils.c +++ b/components/spi_flash/cache_utils.c @@ -38,8 +38,8 @@ static uint32_t s_flash_op_cache_state[2]; #ifndef CONFIG_FREERTOS_UNICORE static SemaphoreHandle_t s_flash_op_mutex; -static bool s_flash_op_can_start = false; -static bool s_flash_op_complete = false; +static volatile bool s_flash_op_can_start = false; +static volatile bool s_flash_op_complete = false; void spi_flash_init_lock() { From 3f8d9d71e2c10e5ebdf3b07f3d527d74411bc35a Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 8 Nov 2016 09:05:05 +0800 Subject: [PATCH 03/10] lwip: fix duplicate definition of O_NONBLOCK LwIP will define O_NONBLOCK in sockets.h if it isn't defined yet. If sys/fcntl.h is included after socket.h, there will be duplicate definition. Work around by including sys/fcntl.h into lwipopts.h. https://github.com/espressif/esp-idf/issues/75 --- components/lwip/include/lwip/port/lwipopts.h | 1 + 1 file changed, 1 insertion(+) diff --git a/components/lwip/include/lwip/port/lwipopts.h b/components/lwip/include/lwip/port/lwipopts.h index f705887508..d06e756850 100755 --- a/components/lwip/include/lwip/port/lwipopts.h +++ b/components/lwip/include/lwip/port/lwipopts.h @@ -35,6 +35,7 @@ #include #include #include +#include #include "esp_task.h" #include "sdkconfig.h" From 6dd3681115668fc18a7a13624ffe7c5e60a3c513 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 8 Nov 2016 09:08:23 +0800 Subject: [PATCH 04/10] fix order of creation of standard streams With existing order, file descriptors assigned to stdin, stdout, stderr didn't match standard assignment. https://github.com/espressif/esp-idf/issues/67 --- components/esp32/cpu_start.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index 2688cd7f81..a96fdee950 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -177,9 +177,9 @@ void start_cpu0_default(void) esp_vfs_dev_uart_register(); esp_reent_init(_GLOBAL_REENT); const char* default_uart_dev = "/dev/uart/0"; + _GLOBAL_REENT->_stdin = fopen(default_uart_dev, "r"); _GLOBAL_REENT->_stdout = fopen(default_uart_dev, "w"); _GLOBAL_REENT->_stderr = fopen(default_uart_dev, "w"); - _GLOBAL_REENT->_stdin = fopen(default_uart_dev, "r"); do_global_ctors(); #if !CONFIG_FREERTOS_UNICORE esp_crosscore_int_init(); From d29935b9cefa723d977a3be8b6b0a27d1449edf6 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 8 Nov 2016 10:33:21 +0800 Subject: [PATCH 05/10] newlib: fix `_times_r` syscall implementation tms_cstime should only take system time in child processes into account, so has to be zero. https://github.com/espressif/esp-idf/issues/81 --- components/newlib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/newlib/time.c b/components/newlib/time.c index 5f60e1d7b2..0d7b6b7474 100644 --- a/components/newlib/time.c +++ b/components/newlib/time.c @@ -112,7 +112,7 @@ void esp_setup_time_syscalls() clock_t IRAM_ATTR _times_r(struct _reent *r, struct tms *ptms) { clock_t t = xTaskGetTickCount() * (portTICK_PERIOD_MS * CLK_TCK / 1000); - ptms->tms_cstime = t; + ptms->tms_cstime = 0; ptms->tms_cutime = 0; ptms->tms_stime = t; ptms->tms_utime = 0; From f142da3cede379d044a222712c6800fcdebafb94 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 8 Nov 2016 10:35:46 +0800 Subject: [PATCH 06/10] driver/gpio: fix interrupt type names in comment block https://github.com/espressif/esp-idf/issues/56 --- components/driver/include/driver/gpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/driver/include/driver/gpio.h b/components/driver/include/driver/gpio.h index 7106489d6c..1b2b758564 100644 --- a/components/driver/include/driver/gpio.h +++ b/components/driver/include/driver/gpio.h @@ -313,7 +313,7 @@ esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull); * * @param gpio_num GPIO number. * - * @param intr_type GPIO wake-up type. Only GPIO_INTR_LOLEVEL\GPIO_INTR_HILEVEL can be used + * @param intr_type GPIO wake-up type. Only GPIO_INTR_LOW_LEVEL\GPIO_INTR_HIGH_LEVEL can be used. * * @return * - ESP_OK Success From 1e4f185d29dd603e54846e1d2a9c10e16418799d Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 8 Nov 2016 11:24:44 +0800 Subject: [PATCH 07/10] wifi: use MACSTR and MAC2STR in logging statements Fixes https://github.com/espressif/esp-idf/issues/49 --- components/esp32/event_default_handlers.c | 27 ++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/components/esp32/event_default_handlers.c b/components/esp32/event_default_handlers.c index a2bb3ccea3..b41d8be055 100644 --- a/components/esp32/event_default_handlers.c +++ b/components/esp32/event_default_handlers.c @@ -22,6 +22,7 @@ #include "esp_event.h" #include "esp_event_loop.h" #include "esp_task.h" +#include "rom/ets_sys.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -196,16 +197,14 @@ static esp_err_t esp_system_event_debug(system_event_t *event) } case SYSTEM_EVENT_STA_CONNECTED: { system_event_sta_connected_t *connected = &event->event_info.connected; - ESP_LOGD(TAG, "SYSTEM_EVENT_STA_CONNECTED, ssid:%s, ssid_len:%d, bssid:%02x:%02x:%02x:%02x:%02x:%02x, channel:%d, authmode:%d", \ - connected->ssid, connected->ssid_len, connected->bssid[0], connected->bssid[0], connected->bssid[1], \ - connected->bssid[3], connected->bssid[4], connected->bssid[5], connected->channel, connected->authmode); + ESP_LOGD(TAG, "SYSTEM_EVENT_STA_CONNECTED, ssid:%s, ssid_len:%d, bssid:" MACSTR ", channel:%d, authmode:%d", \ + connected->ssid, connected->ssid_len, MAC2STR(connected->bssid), connected->channel, connected->authmode); break; } case SYSTEM_EVENT_STA_DISCONNECTED: { system_event_sta_disconnected_t *disconnected = &event->event_info.disconnected; - ESP_LOGD(TAG, "SYSTEM_EVENT_STA_DISCONNECTED, ssid:%s, ssid_len:%d, bssid:%02x:%02x:%02x:%02x:%02x:%02x, reason:%d", \ - disconnected->ssid, disconnected->ssid_len, disconnected->bssid[0], disconnected->bssid[0], disconnected->bssid[1], \ - disconnected->bssid[3], disconnected->bssid[4], disconnected->bssid[5], disconnected->reason); + ESP_LOGD(TAG, "SYSTEM_EVENT_STA_DISCONNECTED, ssid:%s, ssid_len:%d, bssid:" MACSTR ", reason:%d", \ + disconnected->ssid, disconnected->ssid_len, MAC2STR(disconnected->bssid), disconnected->reason); break; } case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: { @@ -231,23 +230,21 @@ static esp_err_t esp_system_event_debug(system_event_t *event) } case SYSTEM_EVENT_AP_STACONNECTED: { system_event_ap_staconnected_t *staconnected = &event->event_info.sta_connected; - ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STACONNECTED, mac:%02x:%02x:%02x:%02x:%02x:%02x, aid:%d", \ - staconnected->mac[0], staconnected->mac[0], staconnected->mac[1], \ - staconnected->mac[3], staconnected->mac[4], staconnected->mac[5], staconnected->aid); + ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STACONNECTED, mac:" MACSTR ", aid:%d", \ + MAC2STR(staconnected->mac), staconnected->aid); break; } case SYSTEM_EVENT_AP_STADISCONNECTED: { system_event_ap_stadisconnected_t *stadisconnected = &event->event_info.sta_disconnected; - ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STADISCONNECTED, mac:%02x:%02x:%02x:%02x:%02x:%02x, aid:%d", \ - stadisconnected->mac[0], stadisconnected->mac[0], stadisconnected->mac[1], \ - stadisconnected->mac[3], stadisconnected->mac[4], stadisconnected->mac[5], stadisconnected->aid); + ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STADISCONNECTED, mac:" MACSTR ", aid:%d", \ + MAC2STR(stadisconnected->mac), stadisconnected->aid); break; } case SYSTEM_EVENT_AP_PROBEREQRECVED: { system_event_ap_probe_req_rx_t *ap_probereqrecved = &event->event_info.ap_probereqrecved; - ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:%02x:%02x:%02x:%02x:%02x:%02x", \ - ap_probereqrecved->rssi, ap_probereqrecved->mac[0], ap_probereqrecved->mac[0], ap_probereqrecved->mac[1], \ - ap_probereqrecved->mac[3], ap_probereqrecved->mac[4], ap_probereqrecved->mac[5]); + ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:" MACSTR, \ + ap_probereqrecved->rssi, \ + MAC2STR(ap_probereqrecved->mac)); break; } default: { From 81b18aa8d588156862559e0b22a86506fc6dac1a Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 8 Nov 2016 11:25:40 +0800 Subject: [PATCH 08/10] bootloader: move some functions out of IRAM when building in bootloader mode Fixes https://github.com/espressif/esp-idf/issues/80 --- components/log/log.c | 15 ++++++++++----- components/spi_flash/spi_flash_rom_patch.c | 10 ++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/components/log/log.c b/components/log/log.c index a2b41d7e62..9670b82dfd 100644 --- a/components/log/log.c +++ b/components/log/log.c @@ -284,7 +284,15 @@ static inline void heap_swap(int i, int j) } #endif //BOOTLOADER_BUILD -IRAM_ATTR uint32_t esp_log_early_timestamp() + +#ifndef BOOTLOADER_BUILD +#define ATTR IRAM_ATTR +#else +#define ATTR +#endif // BOOTLOADER_BUILD + + +uint32_t ATTR esp_log_early_timestamp() { return xthal_get_ccount() / (CPU_CLK_FREQ_ROM / 1000); } @@ -305,9 +313,6 @@ uint32_t IRAM_ATTR esp_log_timestamp() #else -uint32_t IRAM_ATTR esp_log_timestamp() -{ - return esp_log_early_timestamp(); -} +uint32_t esp_log_timestamp() __attribute__((alias("esp_log_early_timestamp"))); #endif //BOOTLOADER_BUILD diff --git a/components/spi_flash/spi_flash_rom_patch.c b/components/spi_flash/spi_flash_rom_patch.c index 7e23beaea2..36e5bf8236 100644 --- a/components/spi_flash/spi_flash_rom_patch.c +++ b/components/spi_flash/spi_flash_rom_patch.c @@ -19,9 +19,15 @@ static const uint32_t STATUS_QIE_BIT = (1 << 9); /* Quad Enable */ #define SPI_IDX 1 #define OTH_IDX 0 +#ifndef BOOTLOADER_BUILD +#define ATTR IRAM_ATTR +#else +#define ATTR +#endif // BOOTLOADER_BUILD + extern SpiFlashChip SPI_flashchip_data; -static void IRAM_ATTR Wait_SPI_Idle(void) +static void ATTR Wait_SPI_Idle(void) { /* Wait for SPI state machine to be idle */ while((REG_READ(SPI_EXT2_REG(SPI_IDX)) & SPI_ST)) { @@ -42,7 +48,7 @@ static void IRAM_ATTR Wait_SPI_Idle(void) about interrupts, CPU coordination, flash mapping. However some of the functions in esp_spi_flash.c call it. */ -SpiFlashOpResult IRAM_ATTR SPIUnlock(void) +SpiFlashOpResult ATTR SPIUnlock(void) { uint32_t status; From c5793521a015cd061bc5b10d5bd8cc87cc3b6723 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 8 Nov 2016 12:00:38 +1100 Subject: [PATCH 09/10] build system: Fix bootloader-flash target ESP32 forum thread: http://esp32.com/viewtopic.php?f=2&t=407&p=1902#p1902 --- components/bootloader/Makefile.projbuild | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/bootloader/Makefile.projbuild b/components/bootloader/Makefile.projbuild index 50c95f9fec..0b460059e8 100644 --- a/components/bootloader/Makefile.projbuild +++ b/components/bootloader/Makefile.projbuild @@ -33,7 +33,7 @@ clean: bootloader-clean bootloader: $(BOOTLOADER_BIN) @echo "Bootloader built. Default flash command is:" - @echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)" + @echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $^" all_binaries: $(BOOTLOADER_BIN) @@ -41,7 +41,7 @@ ESPTOOL_ALL_FLASH_ARGS += 0x1000 $(BOOTLOADER_BIN) # bootloader-flash calls flash in the bootloader dummy project bootloader-flash: $(BOOTLOADER_BIN) - $(BOOTLOADER_MAKE) flash + $(ESPTOOLPY_WRITE_FLASH) 0x1000 $^ # synchronise the project level config to the bootloader's # config From cc072f1d8ab4858775fc36341fc29283765e619a Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 8 Nov 2016 20:26:12 +0800 Subject: [PATCH 10/10] wpa_supplicant: clean up unused variable warning --- components/wpa_supplicant/src/crypto/libtommath.h | 1 + 1 file changed, 1 insertion(+) diff --git a/components/wpa_supplicant/src/crypto/libtommath.h b/components/wpa_supplicant/src/crypto/libtommath.h index 31f9706593..1010f9f63f 100644 --- a/components/wpa_supplicant/src/crypto/libtommath.h +++ b/components/wpa_supplicant/src/crypto/libtommath.h @@ -668,6 +668,7 @@ mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y) } else { #endif #ifdef BN_S_MP_EXPTMOD_C + (void) dr; /* otherwise use the generic Barrett reduction technique */ return s_mp_exptmod (G, X, P, Y, 0); #else