Skip to content

Commit

Permalink
Experimental support for SDK 3.0 for rBoot apps. (#1470)
Browse files Browse the repository at this point in the history
Warning:: Supports only rBoot applications.

In order to enable and test it one can do the following:

on Linux, MacOS and FreeBSD

```
cd $SMING_HOME
export SDK_BASE="$SMING_HOME/third-party/ESP8266_NONOS_SDK"
```

on Windows

```
cd %SMING_HOME%
set SDK_BASE="%SMING_HOME%/third-party/ESP8266_NONOS_SDK"
```

after that reset the Sming code, go to Basic_rBoot, compile it and flash it

```
make dist-clean
cd ../samples/Basic_rBoot
make
make flash
```

Inside the running application type `info` and you should see that now SDK 3.0.* is used.
  • Loading branch information
slaff authored Oct 12, 2018
1 parent 4e9b512 commit 6989cf4
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ matrix:
- os: linux
env: SDK_VERSION=2.0.0
- os: linux
env: SDK_VERSION=2.1.0
env: SDK_VERSION=3.0.0
git:
submodules: false
addons:
Expand Down Expand Up @@ -52,7 +52,7 @@ script:

- export SMING_HOME=$TRAVIS_BUILD_DIR/Sming
- export ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk
- if [ "$SDK_VERSION" == "2.1.0" ]; then export SDK_BASE=$SMING_HOME/third-party/ESP8266_NONOS_SDK;
- if [ "$SDK_VERSION" == "3.0.0" ]; then export SDK_BASE=$SMING_HOME/third-party/ESP8266_NONOS_SDK;
fi
- export PATH=$PATH:$ESP_HOME/xtensa-lx106-elf/bin:$ESP_HOME/utils/:$SMING_HOME/../.travis/tools
- cd $SMING_HOME
Expand Down
5 changes: 4 additions & 1 deletion Sming/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,11 @@ MODULES += third-party/ws_parser/
EXTRA_INCDIR += third-party/ws_parser/

# => SDK
SDK_INTERNAL = 0
ifneq (,$(findstring third-party/ESP8266_NONOS_SDK, $(SDK_BASE)))
THIRD_PARTY_DATA += third-party/ESP8266_NONOS_SDK/Makefile
CFLAGS += -DSDK_INTERNAL
SDK_INTERNAL = 1
endif

# => esp-gdbstub
Expand Down Expand Up @@ -424,7 +426,8 @@ $(USER_LIBDIR)/liblwip_%.a: third-party/esp-open-lwip/Makefile.open
endif
ifeq ($(ENABLE_CUSTOM_LWIP), 2)
$(USER_LIBDIR)/liblwip%.a: third-party/lwip2/Makefile.sming
$(Q) $(MAKE) -C third-party/lwip2/ -f Makefile.sming ENABLE_ESPCONN=$(ENABLE_ESPCONN) SDK_BASE="$(SDK_BASE)" USER_LIBDIR="$(SMING_HOME)/$(USER_LIBDIR)/" CFLAGS_EXTRA="$(EXTRA_CFLAGS_LWIP)" all
$(Q) $(MAKE) -C third-party/lwip2/ -f Makefile.sming ENABLE_ESPCONN=$(ENABLE_ESPCONN) SDK_BASE="$(SDK_BASE)" SDK_INTERNAL="$(SDK_INTERNAL)" \
USER_LIBDIR="$(SMING_HOME)/$(USER_LIBDIR)/" CFLAGS_EXTRA="$(EXTRA_CFLAGS_LWIP)" all
endif

$(APP_AR): $(OBJ)
Expand Down
33 changes: 33 additions & 0 deletions Sming/appinit/user_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,39 @@ extern "C" uint32 ICACHE_FLASH_ATTR __attribute__((weak)) user_rf_cal_sector_se
return rf_cal_sec;
}

#ifdef SDK_INTERNAL
#include <version.h>
#endif

#if defined(ESP_SDK_VERSION_MAJOR) and ESP_SDK_VERSION_MAJOR>=3

extern "C" void ICACHE_FLASH_ATTR __attribute__((weak)) user_pre_init(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
const uint32 rf_cal_addr = user_rf_cal_sector_set() * 0x1000;
const uint32 phy_data_addr = rf_cal_addr + 0x1000;
const uint32 system_param_addr = phy_data_addr + 0x1000;

// WARNING: Sming supports SDK 3.0 with rBoot enabled apps ONLY!
#define SYSTEM_PARTITION_RBOOT_CONFIG SYSTEM_PARTITION_CUSTOMER_BEGIN

static const partition_item_t partitions[] = {
{SYSTEM_PARTITION_BOOTLOADER, 0x0, 0x1000},
{SYSTEM_PARTITION_RBOOT_CONFIG, 0x1000, 0x1000},
{SYSTEM_PARTITION_RF_CAL, rf_cal_addr, 0x1000},
{SYSTEM_PARTITION_PHY_DATA, phy_data_addr, 0x1000},
{SYSTEM_PARTITION_SYSTEM_PARAMETER, system_param_addr, 0x3000},
{SYSTEM_PARTITION_CUSTOMER_BEGIN, 0x2000, 0xfdff0}, // (1M - 0x2010)
};

if(!system_partition_table_regist(partitions, sizeof(partitions) / sizeof(partitions[0]), size_map)) {
os_printf("system_partition_table_regist: failed\n");
while(1);
}
}

#endif /* defined(ESP_SDK_VERSION_MAJOR) and ESP_SDK_VERSION_MAJOR>=3 */

namespace std {
void __attribute__((weak)) __throw_bad_function_call()
{
Expand Down
2 changes: 2 additions & 0 deletions Sming/custom_heap/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void* IRAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
return calloc(1, size);
}

void* IRAM_ATTR pvPortZallocIram(size_t size, const char* file, int line) __attribute__ ((weak, alias("pvPortZalloc")));

size_t xPortGetFreeHeapSize(void)
{
return umm_free_heap_size();
Expand Down
33 changes: 22 additions & 11 deletions Sming/third-party/.patches/ESP8266_NONOS_SDK.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
diff --git a/include/osapi.h b/include/osapi.h
index 0462a9c..52ad21f 100644
--- a/include/osapi.h
+++ b/include/osapi.h
@@ -30,7 +30,7 @@
#include "user_config.h"
diff --git a/include/version.h b/include/version.h
index 3f18631..82e2e94 100644
--- a/include/version.h
+++ b/include/version.h
@@ -1,11 +1,11 @@
#ifndef ESP_SDK_VERSION_H
#define ESP_SDK_VERSION_H

void ets_bzero(void *s, size_t n);
-void ets_delay_us(uint16_t us);
+void ets_delay_us(uint32_t us);
void ets_install_putc1(void (*p)(char c));
-#define ESP_SDK_VERSION_MAJOR 2
-#define ESP_SDK_VERSION_MINOR 2
+#define ESP_SDK_VERSION_MAJOR 3
+#define ESP_SDK_VERSION_MINOR 0
#define ESP_SDK_VERSION_PATCH 0

#define os_bzero ets_bzero
-#define ESP_SDK_VERSION_NUMBER 0x020200
-#define ESP_SDK_VERSION_STRING "2.2.0"
+#define ESP_SDK_VERSION_NUMBER 0x030000
+#define ESP_SDK_VERSION_STRING "3.0.0"

#endif
diff --git a/bin/esp_init_data_default_v08.bin b/bin/esp_init_data_default.bin
similarity index 100%
rename from bin/esp_init_data_default_v08.bin
rename to bin/esp_init_data_default.bin
80 changes: 51 additions & 29 deletions Sming/third-party/.patches/esp-open-lwip.patch
Original file line number Diff line number Diff line change
Expand Up @@ -220,35 +220,6 @@ index 1e46ee5..cfc10f8 100644
ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0, \
diff --git a/include/lwip/mem.h b/include/lwip/mem.h
index af6e360..6d8cabd 100644
--- a/include/lwip/mem.h
+++ b/include/lwip/mem.h
@@ -52,19 +52,19 @@ typedef size_t mem_size_t;
*/
#ifndef MEMLEAK_DEBUG
#ifndef mem_free
-#define mem_free vPortFree
+#define mem_free(s) vPortFree(s, "", 0)
#endif
#ifndef mem_malloc
-#define mem_malloc pvPortMalloc
+#define mem_malloc(s) pvPortMalloc(s, "", 0)
#endif
#ifndef mem_calloc
-#define mem_calloc pvPortCalloc
+#define mem_calloc(s) pvPortCalloc(s, "", 0);
#endif
#ifndef mem_realloc
-#define mem_realloc pvPortRealloc
+#define mem_realloc(p, s) pvPortRealloc(p, s, "", 0)
#endif
#ifndef mem_zalloc
-#define mem_zalloc pvPortZalloc
+#define mem_zalloc(s) pvPortZalloc(s, "", 0)
#endif
#else
#ifndef mem_free
diff --git a/lwip/app/dhcpserver.c b/lwip/app/dhcpserver.c
index ddb5984..fb677c6 100644
--- a/lwip/app/dhcpserver.c
Expand Down Expand Up @@ -321,3 +292,54 @@ index c90adcd..f0c9dea 100644
#ifdef __cplusplus
}
#endif
diff --git a/include/lwip/mem.h b/include/lwip/mem.h
index af6e360..71b2178 100644
--- a/include/lwip/mem.h
+++ b/include/lwip/mem.h
@@ -52,19 +52,19 @@ typedef size_t mem_size_t;
*/
#ifndef MEMLEAK_DEBUG
#ifndef mem_free
-#define mem_free vPortFree
+#define mem_free(s) vPortFree(s, "", __LINE__)
#endif
#ifndef mem_malloc
-#define mem_malloc pvPortMalloc
+#define mem_malloc(s) pvPortMalloc(s, "", __LINE__, false)
#endif
#ifndef mem_calloc
-#define mem_calloc pvPortCalloc
+#define mem_calloc(l, s) ({void* ptr = (void*)pvPortMalloc((l) * (s), "", __LINE__,true);if(ptr){os_memset(ptr,0x0,(l) * (s));} ptr;})
#endif
#ifndef mem_realloc
-#define mem_realloc pvPortRealloc
+#define mem_realloc(p, s) pvPortRealloc(p, s, "", __LINE__)
#endif
#ifndef mem_zalloc
-#define mem_zalloc pvPortZalloc
+#define mem_zalloc(s) pvPortZalloc(s, "", __LINE__)
#endif
#else
#ifndef mem_free
@@ -75,7 +75,7 @@ do{\
}while(0)
#endif
#ifndef mem_malloc
-#define mem_malloc(s) ({const char *file = mem_debug_file; pvPortMalloc(s, file, __LINE__);})
+#define mem_malloc(s) ({const char *file = mem_debug_file; pvPortMalloc(s, file, __LINE__, false);})
#endif
#ifndef mem_calloc
#define mem_calloc(s) ({const char *file = mem_debug_file; pvPortCalloc(s, file, __LINE__);})
@@ -90,7 +90,11 @@ do{\
#endif

#ifndef os_malloc
-#define os_malloc(s) mem_malloc((s))
+#ifndef MEMLEAK_DEBUG
+#define os_malloc(s) pvPortMalloc(s, "", __LINE__,true)
+#else
+#define os_malloc(s) ({const char *file = mem_debug_file; pvPortMalloc(s, file, __LINE__, true);})
+#endif
#endif
#ifndef os_realloc
#define os_realloc(p, s) mem_realloc((p), (s))
82 changes: 60 additions & 22 deletions Sming/third-party/.patches/lwip2.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
diff --git a/Makefile.sming b/Makefile.sming
index 842f4fe..31e4b62 100644
--- a/Makefile.sming
+++ b/Makefile.sming
@@ -4,12 +4,15 @@
USER_LIBDIR ?= tweaked-
LWIP_LIB_RELEASE=$(USER_LIBDIR)liblwip2.a
LWIP_INCLUDES_RELEASE=include
+SDK_BASE ?= $(ESP_HOME)/sdk
+SDK_INTERNAL ?= 0

all: install

%:
@make -f makefiles/Makefile.build-lwip2 \
- SDK=$(ESP_HOME)/sdk \
+ SDK=$(SDK_BASE) \
+ SDK_INTERNAL=$(SDK_INTERNAL) \
LWIP_LIB=liblwip2.a \
LWIP_LIB_RELEASE=$(LWIP_LIB_RELEASE) \
LWIP_INCLUDES_RELEASE=$(LWIP_INCLUDES_RELEASE) \
diff --git a/glue-esp/include-esp/arch/cc.h b/glue-esp/include-esp/arch/cc.h
index 735e700..47413e5 100644
--- a/glue-esp/include-esp/arch/cc.h
Expand All @@ -23,43 +44,28 @@ index 63cd72d..5f100eb 100644
#ifdef LWIP_BUILD

// define LWIP_BUILD only when building LWIP
diff --git a/Makefile.sming b/Makefile.sming
index 842f4fe..7550a72 100644
--- a/Makefile.sming
+++ b/Makefile.sming
@@ -4,12 +4,13 @@
USER_LIBDIR ?= tweaked-
LWIP_LIB_RELEASE=$(USER_LIBDIR)liblwip2.a
LWIP_INCLUDES_RELEASE=include
+SDK_BASE ?= $(ESP_HOME)/sdk

all: install

%:
@make -f makefiles/Makefile.build-lwip2 \
- SDK=$(ESP_HOME)/sdk \
+ SDK=$(SDK_BASE) \
LWIP_LIB=liblwip2.a \
LWIP_LIB_RELEASE=$(LWIP_LIB_RELEASE) \
LWIP_INCLUDES_RELEASE=$(LWIP_INCLUDES_RELEASE) \
diff --git a/glue/esp-missing.h b/glue/esp-missing.h
index 0e42073..4cb5d6c 100644
index 0e42073..2846506 100644
--- a/glue/esp-missing.h
+++ b/glue/esp-missing.h
@@ -9,9 +9,9 @@
@@ -9,9 +9,13 @@

uint32_t r_rand (void);

-void* pvPortZalloc (size_t, const char*, int);
-void* pvPortMalloc (size_t xWantedSize, const char* file, int line) __attribute__((malloc, alloc_size(1)));
-void vPortFree (void *ptr, const char* file, int line);
+#if !SDK_INTERNAL
+
+void* pvPortZalloc (size_t, const char*, unsigned line);
+void* pvPortMalloc (size_t xWantedSize, const char* file, unsigned line) __attribute__((malloc, alloc_size(1)));
+void vPortFree (void *ptr, const char* file, unsigned line);
+
+#endif

struct netif* eagle_lwip_getif (int netif_index);

@@ -27,10 +27,10 @@ int ets_memcmp (const void*, const void*, size_t n);
@@ -27,10 +31,10 @@ int ets_memcmp (const void*, const void*, size_t n);
void *ets_memset (void *s, int c, size_t n);
void *ets_memcpy (void *dest, const void *src, size_t n);

Expand All @@ -74,3 +80,35 @@ index 0e42073..4cb5d6c 100644

struct ip_addr;
void wifi_softap_set_station_info (uint8_t* mac, struct ip_addr*);
diff --git a/makefiles/Makefile.build-lwip2 b/makefiles/Makefile.build-lwip2
index 928bb63..289d48f 100644
--- a/makefiles/Makefile.build-lwip2
+++ b/makefiles/Makefile.build-lwip2
@@ -29,9 +29,9 @@ $(LWIP_LIB_RELEASE): $(LWIP_LIB)

.PHONY: $(LWIP_LIB)
$(LWIP_LIB):
- make -f makefiles/Makefile.glue-esp
- make -f makefiles/Makefile.glue
- make -C lwip2-src/src -f ../../makefiles/Makefile.lwip2 BUILD=../../$(BUILD) LWIP_LIB=../../$(LWIP_LIB)
+ make -f makefiles/Makefile.glue-esp SDK_INTERNAL=$(SDK_INTERNAL)
+ make -f makefiles/Makefile.glue SDK_INTERNAL=$(SDK_INTERNAL)
+ make -C lwip2-src/src -f ../../makefiles/Makefile.lwip2 BUILD=../../$(BUILD) LWIP_LIB=../../$(LWIP_LIB) SDK_INTERNAL=$(SDK_INTERNAL)

section-show:
@for i in $(IRAM); do \
diff --git a/makefiles/Makefile.defs b/makefiles/Makefile.defs
index 7ab4f87..fb60baf 100644
--- a/makefiles/Makefile.defs
+++ b/makefiles/Makefile.defs
@@ -4,7 +4,9 @@ AR = $(TOOLS)ar
OC = $(TOOLS)objcopy
OD = $(TOOLS)objdump

+SDK_INTERNAL ?= 0
+
BUILD = build
BUILD_FLAGS = -Wall -Wextra -std=c99 -c -Os -g -Wpointer-arith -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections
-BUILD_DEFINES = -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -DLWIP_OPEN_SRC -DLWIP_BUILD -DUSE_OPTIMIZE_PRINTF
+BUILD_DEFINES = -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -DLWIP_OPEN_SRC -DLWIP_BUILD -DUSE_OPTIMIZE_PRINTF -DSDK_INTERNAL=$(SDK_INTERNAL)

2 changes: 1 addition & 1 deletion Sming/third-party/ESP8266_NONOS_SDK
Submodule ESP8266_NONOS_SDK updated 101 files

0 comments on commit 6989cf4

Please sign in to comment.