Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise system headers / enforce c11 #1695

Merged
merged 7 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Sming/Arch/Esp8266/Components/axtls-8266/axtls-8266.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff -Nuar a/replacements/libc.c b/replacements/libc.c
--- a/replacements/libc.c 1970-01-01 01:00:00.000000000 +0100
+++ b/replacements/libc.c 2016-11-21 11:03:47.152184514 +0100
@@ -0,0 +1,29 @@
@@ -0,0 +1,28 @@
+/*
+ libc_replacements.c - replaces libc functions with functions
+ from Espressif SDK
Expand All @@ -21,8 +21,7 @@ diff -Nuar a/replacements/libc.c b/replacements/libc.c
+ Modified 03 April 2015 by Markus Sattler
+ */
+
+#include <stdint.h>
+#include "espinc/c_types_compatible.h"
+#include <c_types.h>
+#include <stdarg.h>
+
+extern int ets_putc(int);
Copy link
Contributor

@slaff slaff May 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR make dist-clean did not clean the axtls directory and the new patch was not applied cleanly. Any idea why is that happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try make dist-clean ENABLE_SSL=1

Copy link
Contributor Author

@mikee47 mikee47 May 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have these optional custom libraries which get built:

pwm_open
mainmm
lwip_full
lwip_open
lwip2
axtls
mqttc

Behaviour is that the library only gets cleaned if the relevant flags are defined, ditto for submodule updating. It would be better of course if they all got cleaned regardless. I can look at this in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better of course if they all got cleaned regardless. I can look at this in another PR.

Absolutely. It will also match the current default behaviour.

Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Esp8266/Components/esp8266/crash_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern void __custom_crash_callback( struct rst_info * rst_info, uint32_t stack,
extern void custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) __attribute__ ((weak, alias("__custom_crash_callback")));

void __wrap_system_restart_local() {
register uint32_t sp_reg asm("a1");
register uint32_t sp_reg __asm__("a1");
uint32_t sp = sp_reg;

struct rst_info rst_info = {0};
Expand Down
3 changes: 3 additions & 0 deletions Sming/Arch/Esp8266/Components/esp8266/esp_cplusplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "include/esp_cplusplus.h"
#include <stdlib.h>

extern void (*__init_array_start)();
extern void (*__init_array_end)();

////////////////////////////////////////////////////////////////////////

// Just do it! :)
Expand Down
40 changes: 40 additions & 0 deletions Sming/Arch/Esp8266/Components/esp8266/include/c_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2010 - 2011 Espressif System
*
*/

// Overrides c_types.h for all SDK versions

#ifndef _C_TYPES_H_
#define _C_TYPES_H_

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

#define BOOL bool
#define TRUE true
#define FALSE false

typedef uint8_t uint8;
typedef uint8_t u8;
typedef int8_t sint8;
typedef int8_t int8;
typedef int8_t s8;
typedef uint16_t uint16;
typedef uint16_t u16;
typedef int16_t sint16;
typedef int16_t s16;
typedef uint32_t uint32;
typedef unsigned int u_int;
typedef uint32_t u32;
typedef int32_t sint32;
typedef int32_t s32;
typedef int32_t int32;
typedef int64_t sint64;
typedef uint64_t uint64;
typedef uint64_t u64;
typedef float real32;
typedef double real64;

#endif /* _C_TYPES_H_ */
25 changes: 25 additions & 0 deletions Sming/Arch/Esp8266/Components/esp8266/include/esp_attr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ESP8266 attribute definitions (previously in c_types.h)
#pragma once

#define IRAM_ATTR __attribute__((section(".iram.text")))
#define STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))
#define STORE_ATTR __attribute__((aligned(4)))

#define DMEM_ATTR __attribute__((section(".bss")))
#define SHMEM_ATTR

#ifdef ICACHE_FLASH
#define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text")))
#define ICACHE_RODATA_ATTR __attribute__((section(".irom.text")))
#else
#define ICACHE_FLASH_ATTR
#define ICACHE_RODATA_ATTR
#endif

#define STORE_ATTR __attribute__((aligned(4)))

#ifdef ENABLE_GDB
#define GDB_IRAM_ATTR IRAM_ATTR
#else
#define GDB_IRAM_ATTR
#endif
11 changes: 0 additions & 11 deletions Sming/Arch/Esp8266/Components/esp8266/include/esp_cplusplus.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,4 @@

#pragma once

#ifdef __cplusplus
extern "C" {
#endif
#include "esp_systemapi.h"
#ifdef __cplusplus
}
#endif

extern void (*__init_array_start)(void);
extern void (*__init_array_end)(void);

void cpp_core_initialize();
65 changes: 35 additions & 30 deletions Sming/Arch/Esp8266/Components/esp8266/include/esp_systemapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,52 @@

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

// ESP SDK config
#define LWIP_OPEN_SRC
#define USE_US_TIMER

// Default types
#define __CORRECT_ISO_CPP_STDLIB_H_PROTO
#include <limits.h>
#include "c_types.h"

// Remove buggy espconn
#define _NO_ESPCON_

/* Omitted from early SDK versions, in c_types.h in later versions (note: we don't use the SDK c_types.h) */
typedef enum {
OK = 0,
FAIL,
PENDING,
BUSY,
CANCEL,
} STATUS;

#include <sming_attr.h>
#include "esp_attr.h"
#include <ets_sys.h>
#include <osapi.h>
#include <gpio.h>
#include <os_type.h>
#include <user_interface.h>
#include <spi_flash.h>
#include <espconn.h>
#include "espinc/spi_register.h"

#include <stdarg.h>

#include <user_config.h>

#include "m_printf.h"
#include "debug_progmem.h"
#include "stringutil.h"

#define __ESP8266_EX__ // System definition ESP8266 SOC

#define IRAM_ATTR __attribute__((section(".iram.text")))
#define __forceinline __attribute__((always_inline)) inline
#define STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))
#define STORE_ATTR __attribute__((aligned(4)))

/*
* Use this definition in the cases where a function or a variable is meant to be possibly unused. GCC will not produce a warning for it.
*/
#define SMING_UNUSED __attribute__((unused))
#define LOCAL static

/*
* Flags a compiler warning when Sming framework methods, functions or types are changed
*/
#define SMING_DEPRECATED __attribute__((deprecated))
#define BIT(nr) (1UL << (nr))

#ifdef ENABLE_GDB
#define GDB_IRAM_ATTR IRAM_ATTR
#else
#define GDB_IRAM_ATTR
#endif
#define REG_SET_BIT(_r, _b) (*(volatile uint32_t*)(_r) |= (_b))
#define REG_CLR_BIT(_r, _b) (*(volatile uint32_t*)(_r) &= ~(_b))

#undef assert
#ifdef SMING_RELEASE
Expand Down Expand Up @@ -100,12 +107,6 @@ extern int os_printf_plus(const char *format, ...) __attribute__ ((format (prin
extern int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
extern int ets_vsnprintf(char * s, size_t n, const char * format, va_list arg) __attribute__ ((format (printf, 3, 0)));

extern void *pvPortMalloc(size_t xWantedSize, const char *file, uint32 line);
extern void *pvPortZalloc(size_t xWantedSize, const char *file, uint32 line);
extern void pvPortFree(void *ptr);
extern void vPortFree(void *ptr, const char *file, uint32 line);
extern void *vPortMalloc(size_t xWantedSize);

extern void ets_intr_lock();
extern void ets_intr_unlock();

Expand All @@ -123,3 +124,7 @@ extern void xt_enable_interrupts();

extern void ets_isr_mask(unsigned intr);
extern void ets_isr_unmask(unsigned intr);

#ifdef __cplusplus
}
#endif

This file was deleted.

23 changes: 23 additions & 0 deletions Sming/Arch/Esp8266/Components/esp8266/include/mem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#ifndef SDK_INTERNAL

// Missing from early SDK versions
extern void *pvPortMalloc(size_t xWantedSize, const char *file, uint32 line);
extern void *pvPortZalloc(size_t xWantedSize, const char *file, uint32 line);
extern void pvPortFree(void *ptr);
extern void vPortFree(void *ptr, const char *file, uint32 line);
extern void *vPortMalloc(size_t xWantedSize);

#endif

#include_next <mem.h>

#ifdef __cplusplus
}
#endif

11 changes: 6 additions & 5 deletions Sming/Arch/Esp8266/Components/esp8266/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#include "Platform/System.h"
#include <driver/uart.h>
#include <gdb/gdb_hooks.h>
#include <esp_cplusplus.h>

extern void init();

extern "C" void __attribute__((weak)) user_init(void)
extern "C" void WEAK_ATTR user_init(void)
{
// We want high resolution timing - see HardwareTimer class
system_timer_reinit();
Expand All @@ -40,7 +41,7 @@ extern "C" void __attribute__((weak)) user_init(void)
}

// For compatibility with SDK v1.1
extern "C" void __attribute__((weak)) user_rf_pre_init(void)
extern "C" void WEAK_ATTR user_rf_pre_init(void)
{
// RTC startup fix, author pvvx
volatile uint32 * ptr_reg_rtc_ram = (volatile uint32 *)0x60001000;
Expand All @@ -50,7 +51,7 @@ extern "C" void __attribute__((weak)) user_rf_pre_init(void)
}
}

extern "C" uint32 ICACHE_FLASH_ATTR __attribute__((weak)) user_rf_cal_sector_set(void)
extern "C" uint32 ICACHE_FLASH_ATTR WEAK_ATTR user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
Expand Down Expand Up @@ -88,7 +89,7 @@ extern "C" uint32 ICACHE_FLASH_ATTR __attribute__((weak)) user_rf_cal_sector_se

#if defined(ESP_SDK_VERSION_MAJOR) and ESP_SDK_VERSION_MAJOR>=3

extern "C" void ICACHE_FLASH_ATTR __attribute__((weak)) user_pre_init(void)
extern "C" void ICACHE_FLASH_ATTR WEAK_ATTR user_pre_init(void)
{
const uint32_t MAX_PROGRAM_SECTORS = 0x100000 / SPI_FLASH_SEC_SIZE; // 1MB addressable

Expand Down Expand Up @@ -128,7 +129,7 @@ extern "C" void ICACHE_FLASH_ATTR __attribute__((weak)) user_pre_init(void)
#endif /* defined(ESP_SDK_VERSION_MAJOR) and ESP_SDK_VERSION_MAJOR>=3 */

namespace std {
void __attribute__((weak)) __throw_bad_function_call()
void WEAK_ATTR __throw_bad_function_call()
{
while(1);
};
Expand Down
Loading