From 35ee995327b7f4afb46ad7c264a4b796d494e98c Mon Sep 17 00:00:00 2001 From: Dong Heng Date: Tue, 7 Aug 2018 13:00:43 +0800 Subject: [PATCH] fix(components): Fix all components's compile warning and enable warning checking --- .../subproject/main/bootloader_start.c | 3 +- .../src/bootloader_common.c | 3 +- .../bootloader_support/src/bootloader_flash.c | 4 +- .../bootloader_support/src/bootloader_init.c | 45 ++++++++++--------- .../src/bootloader_utility.c | 10 +++-- .../bootloader_support/src/flash_partitions.c | 3 +- components/esp8266/Makefile.projbuild | 6 --- components/esp8266/driver/uart.c | 1 + components/freertos/port/esp8266/panic.c | 3 ++ components/lwip/apps/dhcpserver/dhcpserver.c | 7 +-- components/lwip/component.mk | 1 + .../lwip/port/esp8266/include/lwipopts.h | 2 +- .../ssl/axtls/include/ssl/ssl_os_port.h | 20 ++++++--- .../ssl/axtls/source/crypto/ssl_crypto_misc.c | 5 ++- components/ssl/axtls/source/ssl/ssl_loader.c | 6 ++- components/ssl/axtls/source/ssl/ssl_os_port.c | 4 +- .../ssl/axtls/source/ssl/ssl_platform.c | 8 ++-- .../ssl/axtls/source/ssl/ssl_tls1_svr.c | 3 +- components/ssl/axtls/source/ssl/ssl_x509.c | 2 +- 19 files changed, 81 insertions(+), 55 deletions(-) diff --git a/components/bootloader/subproject/main/bootloader_start.c b/components/bootloader/subproject/main/bootloader_start.c index 75d3744f..b5c68ea3 100644 --- a/components/bootloader/subproject/main/bootloader_start.c +++ b/components/bootloader/subproject/main/bootloader_start.c @@ -14,9 +14,10 @@ #include "sdkconfig.h" +#include #include "bootloader_config.h" #include "bootloader_init.h" - +#include "bootloader_utility.h" #include "esp_image_format.h" #include "esp_log.h" diff --git a/components/bootloader_support/src/bootloader_common.c b/components/bootloader_support/src/bootloader_common.c index c85085f8..1772a978 100644 --- a/components/bootloader_support/src/bootloader_common.c +++ b/components/bootloader_support/src/bootloader_common.c @@ -167,11 +167,10 @@ bool bootloader_common_erase_part_type_data(const char *list_erase, bool ota_dat #include "esp_err.h" #include "esp_log.h" +#include "crc.h" #include "bootloader_config.h" -static const char* TAG = "boot_comm"; - uint32_t bootloader_common_ota_select_crc(const esp_ota_select_entry_t *s) { return crc32_le(UINT32_MAX, (uint8_t*)&s->ota_seq, 4); diff --git a/components/bootloader_support/src/bootloader_flash.c b/components/bootloader_support/src/bootloader_flash.c index c1a43825..bb835cdc 100644 --- a/components/bootloader_support/src/bootloader_flash.c +++ b/components/bootloader_support/src/bootloader_flash.c @@ -264,6 +264,9 @@ esp_err_t bootloader_flash_erase_sector(size_t sector) #include "esp_err.h" #include "esp_log.h" +extern void Cache_Read_Disable(); +extern void Cache_Read_Enable(uint8_t map, uint8_t p, uint8_t v); + static const char *TAG = "bootloader_flash"; typedef enum { SPI_FLASH_RESULT_OK = 0, @@ -335,7 +338,6 @@ esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size, bool a esp_err_t bootloader_flash_write(size_t dest_addr, void *src, size_t size, bool write_encrypted) { - esp_err_t err; size_t alignment = write_encrypted ? 32 : 4; if ((dest_addr % alignment) != 0) { ESP_LOGE(TAG, "bootloader_flash_write dest_addr 0x%x not %d-byte aligned", dest_addr, alignment); diff --git a/components/bootloader_support/src/bootloader_init.c b/components/bootloader_support/src/bootloader_init.c index c867be74..c876f0f4 100644 --- a/components/bootloader_support/src/bootloader_init.c +++ b/components/bootloader_support/src/bootloader_init.c @@ -545,6 +545,7 @@ void __assert_func(const char *file, int line, const char *func, const char *exp #include "esp_image_format.h" #include "esp_flash_partitions.h" +#include "bootloader_flash.h" extern int _bss_start; extern int _bss_end; @@ -589,28 +590,28 @@ static esp_err_t bootloader_main() static void update_flash_config(const esp_image_header_t* pfhdr) { - uint32_t size; - switch(pfhdr->spi_size) { - case ESP_IMAGE_FLASH_SIZE_1MB: - size = 1; - break; - case ESP_IMAGE_FLASH_SIZE_2MB: - case ESP_IMAGE_FLASH_SIZE_2MB_C1: - size = 2; - break; - case ESP_IMAGE_FLASH_SIZE_4MB: - case ESP_IMAGE_FLASH_SIZE_4MB_C1: - size = 4; - break; - case ESP_IMAGE_FLASH_SIZE_8MB: - size = 8; - break; - case ESP_IMAGE_FLASH_SIZE_16MB: - size = 16; - break; - default: - size = 2; - } + // uint32_t size; + // switch(pfhdr->spi_size) { + // case ESP_IMAGE_FLASH_SIZE_1MB: + // size = 1; + // break; + // case ESP_IMAGE_FLASH_SIZE_2MB: + // case ESP_IMAGE_FLASH_SIZE_2MB_C1: + // size = 2; + // break; + // case ESP_IMAGE_FLASH_SIZE_4MB: + // case ESP_IMAGE_FLASH_SIZE_4MB_C1: + // size = 4; + // break; + // case ESP_IMAGE_FLASH_SIZE_8MB: + // size = 8; + // break; + // case ESP_IMAGE_FLASH_SIZE_16MB: + // size = 16; + // break; + // default: + // size = 2; + // } // Set flash chip size // esp_rom_spiflash_config_param(g_rom_flashchip.device_id, size * 0x100000, 0x10000, 0x1000, 0x100, 0xffff); diff --git a/components/bootloader_support/src/bootloader_utility.c b/components/bootloader_support/src/bootloader_utility.c index b7d2b359..a1b4b2de 100644 --- a/components/bootloader_support/src/bootloader_utility.c +++ b/components/bootloader_support/src/bootloader_utility.c @@ -482,9 +482,12 @@ static void set_cache_and_start_app( #include #include +#include #include "bootloader_config.h" #include "bootloader_utility.h" +#include "bootloader_flash.h" +#include "bootloader_common.h" #include "esp_err.h" #include "esp_log.h" @@ -536,7 +539,7 @@ bool bootloader_utility_load_partition_table(bootloader_state_t* bs) esp_partition_info_t partiton_local; esp_partition_info_t *partition = &partiton_local; - memcpy(&partiton_local, (intptr_t)partitions + i * sizeof(esp_partition_info_t), sizeof(esp_partition_info_t)); + memcpy(&partiton_local, (void *)((intptr_t)partitions + i * sizeof(esp_partition_info_t)), sizeof(esp_partition_info_t)); ESP_LOGD(TAG, "load partition table entry 0x%x", (intptr_t)partition); ESP_LOGD(TAG, "type=%x subtype=%x", partition->type, partition->subtype); @@ -774,6 +777,9 @@ bool bootloader_utility_load_boot_image(const bootloader_state_t *bs, int start_ void bootloader_utility_load_image(const esp_image_metadata_t* image_data) { + void (*user_start)(size_t start_addr, size_t map); + extern void Cache_Read_Enable(uint8_t map, uint8_t p, uint8_t v); + #if defined(CONFIG_SECURE_BOOT_ENABLED) || defined(CONFIG_FLASH_ENCRYPTION_ENABLED) esp_err_t err; #endif @@ -834,8 +840,6 @@ void bootloader_utility_load_image(const esp_image_metadata_t* image_data) Cache_Read_Enable(map, 0, 0); - void (*user_start)(size_t start_addr, size_t map); - user_start = (void *)image_data->image.entry_addr; user_start(image_data->start_addr, map); #endif /* BOOTLOADER_UNPACK_APP */ diff --git a/components/bootloader_support/src/flash_partitions.c b/components/bootloader_support/src/flash_partitions.c index 2e450ac0..f258ca64 100644 --- a/components/bootloader_support/src/flash_partitions.c +++ b/components/bootloader_support/src/flash_partitions.c @@ -94,6 +94,7 @@ esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition #ifdef CONFIG_TARGET_PLATFORM_ESP8266 #include +#include #include "bootloader_config.h" @@ -115,7 +116,7 @@ esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition esp_partition_info_t part_local; esp_partition_info_t *part = &part_local;//partition_table[num_parts]; - memcpy(&part_local, (intptr_t)partition_table + num_parts * sizeof(esp_partition_info_t), sizeof(esp_partition_info_t)); + memcpy(&part_local, (void *)((intptr_t)partition_table + num_parts * sizeof(esp_partition_info_t)), sizeof(esp_partition_info_t)); if (part->magic == ESP_PARTITION_MAGIC) { const esp_partition_pos_t *pos = &part->pos; diff --git a/components/esp8266/Makefile.projbuild b/components/esp8266/Makefile.projbuild index e8bf4bdf..cdc8067e 100644 --- a/components/esp8266/Makefile.projbuild +++ b/components/esp8266/Makefile.projbuild @@ -66,9 +66,3 @@ endif # global CFLAGS for ESP8266 CFLAGS += -DMEMLEAK_DEBUG -DICACHE_FLASH - -# void compiler error, we should remove these later -CFLAGS += -Wno-error=char-subscripts -Wno-error=unknown-pragmas -Wno-error=implicit-function-declaration \ - -Wno-error=pointer-sign -Wno-error=switch -Wno-error=maybe-uninitialized -Wno-error=format= \ - -Wno-error=unused-value -Wno-error=address -Wno-error=return-type -Wno-error=format-extra-args \ - -Wno-error=format-zero-length -Wno-error=unused-label -Wno-error=sizeof-pointer-memaccess diff --git a/components/esp8266/driver/uart.c b/components/esp8266/driver/uart.c index 269940b2..f4b4f333 100644 --- a/components/esp8266/driver/uart.c +++ b/components/esp8266/driver/uart.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "esp8266/pin_mux_register.h" #include "esp8266/uart_register.h" diff --git a/components/freertos/port/esp8266/panic.c b/components/freertos/port/esp8266/panic.c index 6e2614af..57719aea 100644 --- a/components/freertos/port/esp8266/panic.c +++ b/components/freertos/port/esp8266/panic.c @@ -12,10 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "stdlib.h" + #include "esp_attr.h" #include "esp_libc.h" #include "esp8266/eagle_soc.h" +#include "esp8266/rom_functions.h" #include "rom/ets_sys.h" #include "esp_err.h" diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c index dc0f2886..be20ea86 100644 --- a/components/lwip/apps/dhcpserver/dhcpserver.c +++ b/components/lwip/apps/dhcpserver/dhcpserver.c @@ -27,6 +27,7 @@ #include "lwip/pbuf.h" #include "lwip/udp.h" #include "lwip/mem.h" +#include "lwip/timeouts.h" #include "dhcpserver/dhcpserver.h" #include "dhcpserver/dhcpserver_options.h" @@ -1154,7 +1155,7 @@ void dhcps_start(struct netif *netif, ip4_addr_t ip) udp_bind(pcb_dhcps, &netif->ip_addr, DHCPS_SERVER_PORT); udp_recv(pcb_dhcps, handle_dhcp, NULL); - sys_timeout(1000, dhcps_coarse_tmr, NULL); + sys_timeout(1000, (sys_timeout_handler)dhcps_coarse_tmr, NULL); #if DHCPS_DEBUG DHCPS_LOG("dhcps:dhcps_start->udp_recv function Set a receive callback handle_dhcp for UDP_PCB pcb_dhcps\n"); #endif @@ -1176,7 +1177,7 @@ void dhcps_stop(struct netif *netif) return; } - sys_untimeout(dhcps_coarse_tmr, NULL); + sys_untimeout((sys_timeout_handler)dhcps_coarse_tmr, NULL); if (pcb_dhcps != NULL) { udp_disconnect(pcb_dhcps); @@ -1273,7 +1274,7 @@ void dhcps_coarse_tmr(void) /*Do not restart timer when dhcp server is stopped*/ if (pcb_dhcps != NULL) { - sys_timeout(1000, dhcps_coarse_tmr, NULL); + sys_timeout(1000, (sys_timeout_handler)dhcps_coarse_tmr, NULL); } } diff --git a/components/lwip/component.mk b/components/lwip/component.mk index 6d0265b3..96de04b3 100644 --- a/components/lwip/component.mk +++ b/components/lwip/component.mk @@ -20,6 +20,7 @@ COMPONENT_SRCDIRS += apps/dhcpserver \ CFLAGS += -Wno-address #lots of LWIP source files evaluate macros that check address of stack variables lwip/src/apps/sntp/sntp.o: CFLAGS += -Wno-implicit-function-declaration +lwip/src/core/ipv4/ip4.o: CFLAGS += -Wno-implicit-function-declaration ifdef CONFIG_LWIP_SOCKET_MULTITHREAD COMPONENT_OBJEXCLUDE := lwip/src/api/sockets.o diff --git a/components/lwip/port/esp8266/include/lwipopts.h b/components/lwip/port/esp8266/include/lwipopts.h index aaa9c1f3..e9c8b14e 100644 --- a/components/lwip/port/esp8266/include/lwipopts.h +++ b/components/lwip/port/esp8266/include/lwipopts.h @@ -1900,7 +1900,7 @@ void *memp_malloc_ll(size_t type); --------------------------------------- */ -#define LWIP_HOOK_IP4_ROUTE_SRC ip4_route_src_hook +#define LWIP_HOOK_IP4_ROUTE_SRC(d, s) (void *)ip4_route_src_hook(d, s) /** * @defgroup lwip_opts_hooks Hooks diff --git a/components/ssl/axtls/include/ssl/ssl_os_port.h b/components/ssl/axtls/include/ssl/ssl_os_port.h index 84d350d3..2626b8c5 100644 --- a/components/ssl/axtls/include/ssl/ssl_os_port.h +++ b/components/ssl/axtls/include/ssl/ssl_os_port.h @@ -42,6 +42,12 @@ extern "C" { #endif #include +#include +#include +#include +#include + +#include "rom/ets_sys.h" #if 0 #define ssl_printf(fmt, args...) printf(fmt,## args) @@ -49,6 +55,10 @@ extern "C" { #define ssl_printf(fmt, args...) #endif +void *zalloc(size_t n); +uint32_t system_get_data_of_array_8(const uint8_t*, uint8_t); +void system_get_string_from_flash(const char *, char *, size_t n); + #define STDCALL #define EXP_FUNC @@ -89,11 +99,11 @@ static __inline__ uint64_t be64toh(uint64_t __x) {return (((uint64_t)be32toh(__x #endif #ifdef MEMLEAK_DEBUG -#define SSL_MALLOC(size) ax_malloc(size, __FILE__, __LINE__) -#define SSL_REALLOC(mem_ref,size) ax_realloc(mem_ref, size, __FILE__, __LINE__) -#define SSL_CALLOC(element, size) ax_calloc(element, size, __FILE__, __LINE__) -#define SSL_ZALLOC(size) ax_zalloc(size, __FILE__, __LINE__) -#define SSL_FREE(mem_ref) ax_free(mem_ref, __FILE__, __LINE__) +#define SSL_MALLOC(size) os_malloc(size) +#define SSL_REALLOC(mem_ref,size) os_realloc(mem_ref, size) +#define SSL_CALLOC(element, size) os_calloc(element, size) +#define SSL_ZALLOC(size) os_zalloc(size) +#define SSL_FREE(mem_ref) os_free(mem_ref) #else #define SSL_MALLOC(size) malloc(size) #define SSL_REALLOC(mem_ref,size) realloc(mem_ref, size) diff --git a/components/ssl/axtls/source/crypto/ssl_crypto_misc.c b/components/ssl/axtls/source/crypto/ssl_crypto_misc.c index 1bcb1a1e..a933af19 100644 --- a/components/ssl/axtls/source/crypto/ssl_crypto_misc.c +++ b/components/ssl/axtls/source/crypto/ssl_crypto_misc.c @@ -266,6 +266,7 @@ int get_random_NZ(int num_rand_bytes, uint8_t *rand_data) int hex_finish; int hex_index; +#if 0 static void print_hex_init(int finish) { hex_finish = finish; @@ -297,6 +298,7 @@ static void print_hex(uint8_t hex) ssl_printf("\n"); } } +#endif /** * Spit out a blob of data for diagnostics. The data is is a nice column format @@ -402,8 +404,9 @@ EXP_FUNC int STDCALL base64_decode(const char *in, int len, error: #ifdef CONFIG_SSL_FULL_MODE - if (ret < 0) + if (ret < 0) { ssl_printf("Error: Invalid base64\n"); //TTY_FLUSH(); + } #endif //TTY_FLUSH(); SSL_FREE(base64_map); diff --git a/components/ssl/axtls/source/ssl/ssl_loader.c b/components/ssl/axtls/source/ssl/ssl_loader.c index 135536e8..6b0d56de 100644 --- a/components/ssl/axtls/source/ssl/ssl_loader.c +++ b/components/ssl/axtls/source/ssl/ssl_loader.c @@ -224,6 +224,8 @@ static int pem_decrypt(const char *where, const char *end, MD5_CTX md5_ctx; AES_CTX aes_ctx; uint8_t key[32]; /* AES256 size */ + char *aes_str_0_ram = NULL; + char *aes_str_1_ram = NULL; if (password == NULL || strlen(password) == 0) { @@ -233,8 +235,8 @@ static int pem_decrypt(const char *where, const char *end, goto error; } - char *aes_str_0_ram = (char *)SSL_MALLOC(24); - char *aes_str_1_ram = (char *)SSL_MALLOC(24); + aes_str_0_ram = (char *)SSL_MALLOC(24); + aes_str_1_ram = (char *)SSL_MALLOC(24); system_get_string_from_flash(aes_str[0], aes_str_0_ram, 24); system_get_string_from_flash(aes_str[1], aes_str_1_ram, 24); diff --git a/components/ssl/axtls/source/ssl/ssl_os_port.c b/components/ssl/axtls/source/ssl/ssl_os_port.c index a8a96a44..fbc37d35 100644 --- a/components/ssl/axtls/source/ssl/ssl_os_port.c +++ b/components/ssl/axtls/source/ssl/ssl_os_port.c @@ -88,14 +88,14 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size) } #endif -static const char * out_of_mem_str = "out of memory %s %d\n"; +//static const char * out_of_mem_str = "out of memory %s %d\n"; #define exit_now printf //#define SSL_LOG #ifdef SSL_LOG #define debug_now printf #else -#define debug_now +#define debug_now(fmt, ...) #endif #if 0 diff --git a/components/ssl/axtls/source/ssl/ssl_platform.c b/components/ssl/axtls/source/ssl/ssl_platform.c index 9f4f4e35..0ca2ef48 100644 --- a/components/ssl/axtls/source/ssl/ssl_platform.c +++ b/components/ssl/axtls/source/ssl/ssl_platform.c @@ -184,6 +184,8 @@ EXP_FUNC int STDCALL esp_base64_encode(uint8_t *dst, size_t dlen, size_t *olen, return 0; } + + return 0; } static char *key_password = NULL; @@ -1098,11 +1100,11 @@ void esp_ssl_sleep(uint16_t mseconds) vTaskDelay(mseconds / portTICK_RATE_MS); } -esp_ssl_CTX_set_client_cert_cb(){} +void esp_ssl_CTX_set_client_cert_cb(){} -esp_ssl_CTX_set_mode(){} +void esp_ssl_CTX_set_mode(){} -esp_ssl_pending() +void esp_ssl_pending() { } diff --git a/components/ssl/axtls/source/ssl/ssl_tls1_svr.c b/components/ssl/axtls/source/ssl/ssl_tls1_svr.c index 090e829a..253431cd 100644 --- a/components/ssl/axtls/source/ssl/ssl_tls1_svr.c +++ b/components/ssl/axtls/source/ssl/ssl_tls1_svr.c @@ -54,8 +54,9 @@ EXP_FUNC SSL * STDCALL ssl_server_new(SSL_CTX *ssl_ctx, int client_fd) ssl->next_state = HS_CLIENT_HELLO; #ifdef CONFIG_SSL_FULL_MODE - if (ssl_ctx->chain_length == 0) + if (ssl_ctx->chain_length == 0) { ssl_printf("Warning - no server certificate defined\n"); //TTY_FLUSH(); + } #endif return ssl; diff --git a/components/ssl/axtls/source/ssl/ssl_x509.c b/components/ssl/axtls/source/ssl/ssl_x509.c index 861e5388..0e4fd656 100644 --- a/components/ssl/axtls/source/ssl/ssl_x509.c +++ b/components/ssl/axtls/source/ssl/ssl_x509.c @@ -491,7 +491,7 @@ end_verify: /** * Used for diagnostics. */ -static const char *not_part_of_cert = ""; +//static const char *not_part_of_cert = ""; void x509_print(const X509_CTX *cert, CA_CERT_CTX *ca_cert_ctx) { if (cert == NULL)