Merge branch 'bugfix/github_issues' into 'master'

Fixes for github issues

This MR contains a bunch of small fixes for issues raised on Github and esp32.com forum:

- vfs doesn't check error code returned by open syscall
- spi_flash doesn't work when built in release mode
- duplicate definition of O_NONBLOCK when combining LwIP socket.h with sys/fcntl.h
- wrong order of creation of standard streams
- `_times_r` returning incorrect values, causing `clock`to return double of the actual time
- driver/gpio.h: comment fix
- wifi event handlers: fix incorrect MAC address printed by logging statements
- move some functions out of IRAM when compiling for bootloader

Please check commit descriptions for links to issues/forum posts and more details.


See merge request !183
This commit is contained in:
Ivan Grokhotkov 2016-11-09 10:12:25 +08:00
commit fcba7e278d
11 changed files with 43 additions and 29 deletions

View File

@ -33,7 +33,7 @@ clean: bootloader-clean
bootloader: $(BOOTLOADER_BIN) bootloader: $(BOOTLOADER_BIN)
@echo "Bootloader built. Default flash command is:" @echo "Bootloader built. Default flash command is:"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)" @echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $^"
all_binaries: $(BOOTLOADER_BIN) 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 calls flash in the bootloader dummy project
bootloader-flash: $(BOOTLOADER_BIN) bootloader-flash: $(BOOTLOADER_BIN)
$(BOOTLOADER_MAKE) flash $(ESPTOOLPY_WRITE_FLASH) 0x1000 $^
# synchronise the project level config to the bootloader's # synchronise the project level config to the bootloader's
# config # config

View File

@ -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 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 * @return
* - ESP_OK Success * - ESP_OK Success

View File

@ -177,9 +177,9 @@ void start_cpu0_default(void)
esp_vfs_dev_uart_register(); esp_vfs_dev_uart_register();
esp_reent_init(_GLOBAL_REENT); esp_reent_init(_GLOBAL_REENT);
const char* default_uart_dev = "/dev/uart/0"; 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->_stdout = fopen(default_uart_dev, "w");
_GLOBAL_REENT->_stderr = fopen(default_uart_dev, "w"); _GLOBAL_REENT->_stderr = fopen(default_uart_dev, "w");
_GLOBAL_REENT->_stdin = fopen(default_uart_dev, "r");
do_global_ctors(); do_global_ctors();
#if !CONFIG_FREERTOS_UNICORE #if !CONFIG_FREERTOS_UNICORE
esp_crosscore_int_init(); esp_crosscore_int_init();

View File

@ -22,6 +22,7 @@
#include "esp_event.h" #include "esp_event.h"
#include "esp_event_loop.h" #include "esp_event_loop.h"
#include "esp_task.h" #include "esp_task.h"
#include "rom/ets_sys.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.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: { case SYSTEM_EVENT_STA_CONNECTED: {
system_event_sta_connected_t *connected = &event->event_info.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", \ ESP_LOGD(TAG, "SYSTEM_EVENT_STA_CONNECTED, ssid:%s, ssid_len:%d, bssid:" MACSTR ", channel:%d, authmode:%d", \
connected->ssid, connected->ssid_len, connected->bssid[0], connected->bssid[0], connected->bssid[1], \ connected->ssid, connected->ssid_len, MAC2STR(connected->bssid), connected->channel, connected->authmode);
connected->bssid[3], connected->bssid[4], connected->bssid[5], connected->channel, connected->authmode);
break; break;
} }
case SYSTEM_EVENT_STA_DISCONNECTED: { case SYSTEM_EVENT_STA_DISCONNECTED: {
system_event_sta_disconnected_t *disconnected = &event->event_info.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", \ ESP_LOGD(TAG, "SYSTEM_EVENT_STA_DISCONNECTED, ssid:%s, ssid_len:%d, bssid:" MACSTR ", reason:%d", \
disconnected->ssid, disconnected->ssid_len, disconnected->bssid[0], disconnected->bssid[0], disconnected->bssid[1], \ disconnected->ssid, disconnected->ssid_len, MAC2STR(disconnected->bssid), disconnected->reason);
disconnected->bssid[3], disconnected->bssid[4], disconnected->bssid[5], disconnected->reason);
break; break;
} }
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: { 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: { case SYSTEM_EVENT_AP_STACONNECTED: {
system_event_ap_staconnected_t *staconnected = &event->event_info.sta_connected; 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", \ ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STACONNECTED, mac:" MACSTR ", aid:%d", \
staconnected->mac[0], staconnected->mac[0], staconnected->mac[1], \ MAC2STR(staconnected->mac), staconnected->aid);
staconnected->mac[3], staconnected->mac[4], staconnected->mac[5], staconnected->aid);
break; break;
} }
case SYSTEM_EVENT_AP_STADISCONNECTED: { case SYSTEM_EVENT_AP_STADISCONNECTED: {
system_event_ap_stadisconnected_t *stadisconnected = &event->event_info.sta_disconnected; 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", \ ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STADISCONNECTED, mac:" MACSTR ", aid:%d", \
stadisconnected->mac[0], stadisconnected->mac[0], stadisconnected->mac[1], \ MAC2STR(stadisconnected->mac), stadisconnected->aid);
stadisconnected->mac[3], stadisconnected->mac[4], stadisconnected->mac[5], stadisconnected->aid);
break; break;
} }
case SYSTEM_EVENT_AP_PROBEREQRECVED: { case SYSTEM_EVENT_AP_PROBEREQRECVED: {
system_event_ap_probe_req_rx_t *ap_probereqrecved = &event->event_info.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", \ ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:" MACSTR, \
ap_probereqrecved->rssi, ap_probereqrecved->mac[0], ap_probereqrecved->mac[0], ap_probereqrecved->mac[1], \ ap_probereqrecved->rssi, \
ap_probereqrecved->mac[3], ap_probereqrecved->mac[4], ap_probereqrecved->mac[5]); MAC2STR(ap_probereqrecved->mac));
break; break;
} }
default: { default: {

View File

@ -284,7 +284,15 @@ static inline void heap_swap(int i, int j)
} }
#endif //BOOTLOADER_BUILD #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); return xthal_get_ccount() / (CPU_CLK_FREQ_ROM / 1000);
} }
@ -305,9 +313,6 @@ uint32_t IRAM_ATTR esp_log_timestamp()
#else #else
uint32_t IRAM_ATTR esp_log_timestamp() uint32_t esp_log_timestamp() __attribute__((alias("esp_log_early_timestamp")));
{
return esp_log_early_timestamp();
}
#endif //BOOTLOADER_BUILD #endif //BOOTLOADER_BUILD

View File

@ -35,6 +35,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/fcntl.h>
#include "esp_task.h" #include "esp_task.h"
#include "sdkconfig.h" #include "sdkconfig.h"

View File

@ -114,7 +114,7 @@ void esp_setup_time_syscalls()
clock_t IRAM_ATTR _times_r(struct _reent *r, struct tms *ptms) clock_t IRAM_ATTR _times_r(struct _reent *r, struct tms *ptms)
{ {
clock_t t = xTaskGetTickCount() * (portTICK_PERIOD_MS * CLK_TCK / 1000); clock_t t = xTaskGetTickCount() * (portTICK_PERIOD_MS * CLK_TCK / 1000);
ptms->tms_cstime = t; ptms->tms_cstime = 0;
ptms->tms_cutime = 0; ptms->tms_cutime = 0;
ptms->tms_stime = t; ptms->tms_stime = t;
ptms->tms_utime = 0; ptms->tms_utime = 0;

View File

@ -38,8 +38,8 @@ static uint32_t s_flash_op_cache_state[2];
#ifndef CONFIG_FREERTOS_UNICORE #ifndef CONFIG_FREERTOS_UNICORE
static SemaphoreHandle_t s_flash_op_mutex; static SemaphoreHandle_t s_flash_op_mutex;
static bool s_flash_op_can_start = false; static volatile bool s_flash_op_can_start = false;
static bool s_flash_op_complete = false; static volatile bool s_flash_op_complete = false;
void spi_flash_init_lock() void spi_flash_init_lock()
{ {

View File

@ -19,9 +19,15 @@ static const uint32_t STATUS_QIE_BIT = (1 << 9); /* Quad Enable */
#define SPI_IDX 1 #define SPI_IDX 1
#define OTH_IDX 0 #define OTH_IDX 0
#ifndef BOOTLOADER_BUILD
#define ATTR IRAM_ATTR
#else
#define ATTR
#endif // BOOTLOADER_BUILD
extern SpiFlashChip SPI_flashchip_data; 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 */ /* Wait for SPI state machine to be idle */
while((REG_READ(SPI_EXT2_REG(SPI_IDX)) & SPI_ST)) { 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 about interrupts, CPU coordination, flash mapping. However some of
the functions in esp_spi_flash.c call it. the functions in esp_spi_flash.c call it.
*/ */
SpiFlashOpResult IRAM_ATTR SPIUnlock(void) SpiFlashOpResult ATTR SPIUnlock(void)
{ {
uint32_t status; uint32_t status;

View File

@ -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); const char* path_within_vfs = translate_path(vfs, path);
int ret; int ret;
CHECK_AND_CALL(ret, r, vfs, open, path_within_vfs, flags, mode); 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); return ret - vfs->vfs.fd_offset + (vfs->offset << VFS_INDEX_S);
} }

View File

@ -668,6 +668,7 @@ mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
} else { } else {
#endif #endif
#ifdef BN_S_MP_EXPTMOD_C #ifdef BN_S_MP_EXPTMOD_C
(void) dr;
/* otherwise use the generic Barrett reduction technique */ /* otherwise use the generic Barrett reduction technique */
return s_mp_exptmod (G, X, P, Y, 0); return s_mp_exptmod (G, X, P, Y, 0);
#else #else