Unverified Commit 9a471079 authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

SDK 3.0 release (#2692)

* Rebaseline firmware to non-OS SDK version 3.0
* Note that SDK version 3.0 introduces the concept of a Flash Partition Table(PT).  This is located at Flash offset 0x10000 in our firmware build.
* The firmware is now PT aware with both LFS and SPIFFS taking their partition size and location from the PT
* A new tool `tools/nodemcu-partition.py` is now used to initialise these data and can also download LFS and SPIFFS images to these partitions.
parent b6cd2c3e
...@@ -5,20 +5,14 @@ ...@@ -5,20 +5,14 @@
TOOLCHAIN_VERSION:=20181106.0 TOOLCHAIN_VERSION:=20181106.0
# SDK base version, as released by Espressif # SDK base version, as released by Espressif
SDK_BASE_VER:=2.2.1 SDK_BASE_VER:=3.0
# no patch: SDK_VER equals SDK_BASE_VER and sdk dir depends on sdk_extracted
SDK_VER:=$(SDK_BASE_VER) SDK_VER:=$(SDK_BASE_VER)
SDK_DIR_DEPENDS:=sdk_extracted SDK_DIR_DEPENDS:=sdk_extracted
# with patch: SDK_VER differs from SDK_BASE_VER and sdk dir depends on sdk_patched
#SDK_PATCH_VER:=f8f27ce
#SDK_VER:=$(SDK_BASE_VER)-$(SDK_PATCH_VER)
#SDK_DIR_DEPENDS:=sdk_patched
SDK_FILE_VER:=$(SDK_BASE_VER) SDK_FILE_VER:=$(SDK_BASE_VER)
SDK_FILE_SHA1:=48f2242d5895823709f222bf0fffce9d525996c8 SDK_FILE_SHA1:=029fc23fe87e03c9852de636490b2d7b9e07f01a
# SDK_PATCH_SHA1:=0bc21ec77b08488f04d3e1c9d161b711d07201a8 ESPTOOL_VER:=2.6
# Ensure we search "our" SDK before the tool-chain's SDK (if any) # Ensure we search "our" SDK before the tool-chain's SDK (if any)
TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST)))) TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
SDK_REL_DIR=sdk/esp_iot_sdk_v$(SDK_VER) SDK_REL_DIR=sdk/esp_iot_sdk_v$(SDK_VER)
...@@ -109,6 +103,7 @@ else ...@@ -109,6 +103,7 @@ else
CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E
OBJCOPY = xtensa-lx106-elf-objcopy OBJCOPY = xtensa-lx106-elf-objcopy
FIRMWAREDIR = ../bin/ FIRMWAREDIR = ../bin/
WGET = wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux) ifeq ($(UNAME_S),Linux)
# LINUX # LINUX
...@@ -128,8 +123,12 @@ else ...@@ -128,8 +123,12 @@ else
endif endif
endif endif
############################################################# #############################################################
ESPTOOL ?= ../tools/esptool.py
GITHUB_TOOLCHAIN = https://github.com/jmattsson/esp-toolchains
GITHUB_SDK = https://github.com/espressif/ESP8266_NONOS_SDK
GITHUB_ESPTOOL = https://github.com/espressif/esptool
ESPTOOL ?= $(TOP_DIR)/tools/toolchains/esptool.py
CSRCS ?= $(wildcard *.c) CSRCS ?= $(wildcard *.c)
CXXSRCS ?= $(wildcard *.cpp) CXXSRCS ?= $(wildcard *.cpp)
...@@ -234,18 +233,16 @@ $(BINODIR)/%.bin: $(IMAGEODIR)/%.out ...@@ -234,18 +233,16 @@ $(BINODIR)/%.bin: $(IMAGEODIR)/%.out
all: toolchain sdk_pruned pre_build .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS) all: toolchain sdk_pruned pre_build .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS)
.PHONY: sdk_extracted .PHONY: sdk_extracted
.PHONY: sdk_patched
.PHONY: sdk_pruned .PHONY: sdk_pruned
.PHONY: toolchain .PHONY: toolchain
sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER) sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER)
sdk_patched: sdk_extracted $(TOP_DIR)/sdk/.patched-$(SDK_VER)
sdk_pruned: $(SDK_DIR_DEPENDS) $(TOP_DIR)/sdk/.pruned-$(SDK_VER) sdk_pruned: $(SDK_DIR_DEPENDS) $(TOP_DIR)/sdk/.pruned-$(SDK_VER)
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
toolchain: toolchain:
else else
toolchain: $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc toolchain: $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc $(TOP_DIR)/tools/toolchains/esptool.py
$(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc: $(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc: $(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz
mkdir -p $(TOP_DIR)/tools/toolchains/ mkdir -p $(TOP_DIR)/tools/toolchains/
...@@ -256,22 +253,34 @@ $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa- ...@@ -256,22 +253,34 @@ $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-
$(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz: $(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz:
mkdir -p $(TOP_DIR)/cache mkdir -p $(TOP_DIR)/cache
$(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@)
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused https://github.com/jmattsson/esp-toolchains/releases/download/$(PLATFORM)-$(TOOLCHAIN_VERSION)/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz -O $@ || { rm -f "$@"; exit 1; } $(WGET) $(GITHUB_TOOLCHAIN)/releases/download/$(PLATFORM)-$(TOOLCHAIN_VERSION)/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz -O $@ \
|| { rm -f "$@"; exit 1; }
endif endif
$(TOP_DIR)/tools/toolchains/esptool.py: $(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz
mkdir -p $(TOP_DIR)/tools/toolchains/
tar -C $(TOP_DIR)/tools/toolchains/ -xzf $< --strip-components=1 esptool-$(ESPTOOL_VER)/esptool.py
chmod +x $@
touch $@
$(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz:
mkdir -p $(TOP_DIR)/cache/esptool/
$(WGET) $(GITHUB_ESPTOOL)/archive/v$(ESPTOOL_VER).tar.gz -O $@ || { rm -f "$@"; exit 1; }
$(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER): $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip $(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER): $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip
mkdir -p "$(dir $@)" mkdir -p "$(dir $@)"
$(summary) UNZIP $(patsubst $(TOP_DIR)/%,%,$<) $(summary) UNZIP $(patsubst $(TOP_DIR)/%,%,$<)
(cd "$(dir $@)" && rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-$(SDK_BASE_VER) && unzip $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip ESP8266_NONOS_SDK-$(SDK_BASE_VER)/lib/* ESP8266_NONOS_SDK-$(SDK_BASE_VER)/ld/eagle.rom.addr.v6.ld ESP8266_NONOS_SDK-$(SDK_BASE_VER)/include/* ESP8266_NONOS_SDK-$(SDK_BASE_VER)/bin/esp_init_data_default_v05.bin) (cd "$(dir $@)" && \
rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-$(SDK_BASE_VER) && \
unzip $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip \
'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/lib/*' \
'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/ld/*.v6.ld' \
'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/include/*' \
'ESP8266_NONOS_SDK-$(SDK_BASE_VER)/bin/esp_init_data_default_v05.bin' \
)
mv $(dir $@)/ESP8266_NONOS_SDK-$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER) mv $(dir $@)/ESP8266_NONOS_SDK-$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER)
touch $@ touch $@
$(TOP_DIR)/sdk/.patched-$(SDK_VER): $(TOP_DIR)/cache/$(SDK_PATCH_VER).patch
mv $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_VER)
$(summary) APPLY $(patsubst $(TOP_DIR)/%,%,$<)
git apply --verbose -p1 --exclude='*VERSION' --exclude='*bin/at*' --directory=$(SDK_REL_DIR) $<
touch $@
$(TOP_DIR)/sdk/.pruned-$(SDK_VER): $(TOP_DIR)/sdk/.pruned-$(SDK_VER):
rm -f $(SDK_DIR)/lib/liblwip.a $(SDK_DIR)/lib/libssl.a $(SDK_DIR)/lib/libmbedtls.a rm -f $(SDK_DIR)/lib/liblwip.a $(SDK_DIR)/lib/libssl.a $(SDK_DIR)/lib/libmbedtls.a
$(summary) PRUNE libmain.a libc.a $(summary) PRUNE libmain.a libc.a
...@@ -282,15 +291,9 @@ $(TOP_DIR)/sdk/.pruned-$(SDK_VER): ...@@ -282,15 +291,9 @@ $(TOP_DIR)/sdk/.pruned-$(SDK_VER):
$(TOP_DIR)/cache/v$(SDK_FILE_VER).zip: $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip:
mkdir -p "$(dir $@)" mkdir -p "$(dir $@)"
$(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@)
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused https://github.com/espressif/ESP8266_NONOS_SDK/archive/v$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; } $(WGET) $(GITHUB_SDK)/archive/v$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; }
(echo "$(SDK_FILE_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; } (echo "$(SDK_FILE_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; }
$(TOP_DIR)/cache/$(SDK_PATCH_VER).patch:
mkdir -p "$(dir $@)"
$(summary) WGET $(SDK_PATCH_VER).patch
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused "https://github.com/espressif/ESP8266_NONOS_SDK/compare/v$(SDK_BASE_VER)...$(SDK_PATCH_VER).patch" -O $@ || { rm -f "$@"; exit 1; }
(echo "$(SDK_PATCH_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; }
clean: clean:
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;) $(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;)
$(RM) -r $(ODIR)/$(TARGET)/$(FLAVOR) $(RM) -r $(ODIR)/$(TARGET)/$(FLAVOR)
......
...@@ -97,7 +97,6 @@ LINKFLAGS_eagle.app.v6 = \ ...@@ -97,7 +97,6 @@ LINKFLAGS_eagle.app.v6 = \
-T$(LD_FILE) \ -T$(LD_FILE) \
-Wl,@../ld/defsym.rom \ -Wl,@../ld/defsym.rom \
-Wl,--no-check-sections \ -Wl,--no-check-sections \
-Wl,--wrap=_xtos_set_exception_handler \
-Wl,-static \ -Wl,-static \
$(addprefix -u , $(SELECTED_MODULE_SYMS)) \ $(addprefix -u , $(SELECTED_MODULE_SYMS)) \
-Wl,--start-group \ -Wl,--start-group \
...@@ -116,6 +115,8 @@ LINKFLAGS_eagle.app.v6 = \ ...@@ -116,6 +115,8 @@ LINKFLAGS_eagle.app.v6 = \
$(DEP_LIBS_eagle.app.v6) \ $(DEP_LIBS_eagle.app.v6) \
-Wl,--end-group \ -Wl,--end-group \
-lm -lm
# -Wl,--cref
# -Wl,--wrap=_xtos_set_exception_handler
DEPENDS_eagle.app.v6 = \ DEPENDS_eagle.app.v6 = \
$(LD_FILE) \ $(LD_FILE) \
......
...@@ -659,11 +659,22 @@ static void ATTR_GDBFN gdb_semihost_putchar1(char c) { ...@@ -659,11 +659,22 @@ static void ATTR_GDBFN gdb_semihost_putchar1(char c) {
} }
#if !GDBSTUB_FREERTOS #if !GDBSTUB_FREERTOS
//The OS-less SDK uses the Xtensa HAL to handle exceptions. We can use those functions to catch any /* The non-OS SDK uses the Xtensa HAL to handle exceptions, and the SDK now establishes exception
//fatal exceptions and invoke the debugger when this happens. * handlers for EXCCAUSE errors: ILLEGAL, INSTR_ERROR, LOAD_STORE_ERROR, PRIVILEGED, UNALIGNED,
* LOAD_PROHIBITED and STORE_PROHIBITED. These handlers are established in SDK/app_main.c.
* LOAD_STORE_ERROR is handled by SDK/user_exceptions.o:load_non_32_wide_handler() which is a
* fork of our version. The remaining are handled by a static function at
* SDK:app+main.c:offset 0x0348.
*
* Our SDK 2 load_non_32_wide_handler chained into the gdb stub handler if the error was anything
* other than a L8UI, L16SI or L16UI at a flash mapped address. However in this current
* implementation, we have left the Espressif handler in place and handle the other errors with
* the debugger. This means that the debugger will not capture other load store errors. I
* might revise this.
*/
static void ATTR_GDBINIT install_exceptions() { static void ATTR_GDBINIT install_exceptions() {
int i; int i;
int exno[]={EXCCAUSE_ILLEGAL, EXCCAUSE_SYSCALL, EXCCAUSE_INSTR_ERROR, EXCCAUSE_LOAD_STORE_ERROR, const int exno[]={EXCCAUSE_ILLEGAL, EXCCAUSE_SYSCALL, EXCCAUSE_INSTR_ERROR, /* EXCCAUSE_LOAD_STORE_ERROR, */
EXCCAUSE_DIVIDE_BY_ZERO, EXCCAUSE_UNALIGNED, EXCCAUSE_INSTR_DATA_ERROR, EXCCAUSE_LOAD_STORE_DATA_ERROR, EXCCAUSE_DIVIDE_BY_ZERO, EXCCAUSE_UNALIGNED, EXCCAUSE_INSTR_DATA_ERROR, EXCCAUSE_LOAD_STORE_DATA_ERROR,
EXCCAUSE_INSTR_ADDR_ERROR, EXCCAUSE_LOAD_STORE_ADDR_ERROR, EXCCAUSE_INSTR_PROHIBITED, EXCCAUSE_INSTR_ADDR_ERROR, EXCCAUSE_LOAD_STORE_ADDR_ERROR, EXCCAUSE_INSTR_PROHIBITED,
EXCCAUSE_LOAD_PROHIBITED, EXCCAUSE_STORE_PROHIBITED}; EXCCAUSE_LOAD_PROHIBITED, EXCCAUSE_STORE_PROHIBITED};
......
...@@ -51,40 +51,39 @@ typedef size_t mem_size_t; ...@@ -51,40 +51,39 @@ typedef size_t mem_size_t;
* allow these defines to be overridden. * allow these defines to be overridden.
*/ */
#ifndef MEMLEAK_DEBUG #ifndef MEMLEAK_DEBUG
#ifndef mem_free #ifndef mem_free
#define mem_free vPortFree #define mem_free(s) vPortFree(s, "", __LINE__)
#endif #endif
#ifndef mem_malloc #ifndef mem_malloc
#define mem_malloc pvPortMalloc #define mem_malloc(s) pvPortMalloc(s, "", __LINE__,false)
#endif #endif
#ifndef mem_calloc #ifndef mem_calloc
#define mem_calloc pvPortCalloc #define mem_calloc(l, s) pvPortCalloc(l, s, "", __LINE__)
#endif #endif
#ifndef mem_realloc #ifndef mem_realloc
#define mem_realloc pvPortRealloc #define mem_realloc(p, s) pvPortRealloc(p, s, "", __LINE__)
#endif #endif
#ifndef mem_zalloc #ifndef mem_zalloc
#define mem_zalloc pvPortZalloc #define mem_zalloc(s) pvPortZalloc(s, "", __LINE__)
#endif #endif
#else #else
#ifndef mem_free #ifndef mem_free
#define mem_free(s) \ #define mem_free(s) vPortFree(s, mem_debug_file, __LINE__)
do{\
const char *file = mem_debug_file;\
vPortFree(s, file, __LINE__);\
}while(0)
#endif #endif
#ifndef mem_malloc #ifndef mem_malloc
#define mem_malloc(s) ({const char *file = mem_debug_file; pvPortMalloc(s, file, __LINE__);}) #define mem_malloc(s) pvPortMalloc(s, mem_debug_file, __LINE__,false)
#endif #endif
#ifndef mem_calloc #ifndef mem_calloc
#define mem_calloc(l, s) ({const char *file = mem_debug_file; pvPortCalloc(l, s, file, __LINE__);}) #define mem_calloc(l, s) pvPortCalloc(l, s, mem_debug_file, __LINE__)
#endif #endif
#ifndef mem_realloc #ifndef mem_realloc
#define mem_realloc(p, s) ({const char *file = mem_debug_file; pvPortRealloc(p, s, file, __LINE__);}) #define mem_realloc(p, s) pvPortRealloc(p, s, mem_debug_file, __LINE__)
#endif #endif
#ifndef mem_zalloc #ifndef mem_zalloc
#define mem_zalloc(s) ({const char *file = mem_debug_file; pvPortZalloc(s, file, __LINE__);}) #define mem_zalloc(s) pvPortZalloc(s, mem_debug_file, __LINE__)
#endif #endif
#endif #endif
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
// this out and enabling the explicitly size, e.g. FLASH_4M. Valid sizes are // this out and enabling the explicitly size, e.g. FLASH_4M. Valid sizes are
// FLASH_512K, FLASH_1M, FLASH_2M, FLASH_4M, FLASH_8M, FLASH_16M. // FLASH_512K, FLASH_1M, FLASH_2M, FLASH_4M, FLASH_8M, FLASH_16M.
#define FLASH_AUTOSIZE //#define FLASH_AUTOSIZE
//#define FLASH_4M #define FLASH_4M
// The firmware now selects a baudrate of 115,200 by default, but the driver // The firmware now selects a baudrate of 115,200 by default, but the driver
...@@ -41,11 +41,8 @@ ...@@ -41,11 +41,8 @@
// The Lua Flash Store (LFS) allows you to store Lua code in Flash memory and // The Lua Flash Store (LFS) allows you to store Lua code in Flash memory and
// the Lua VMS will execute this code directly from flash without needing any // the Lua VMS will execute this code directly from flash without needing any
// RAM overhead. If you want to enable LFS then set the following define to // RAM overhead. Note that you should now configure LFS directly in the
// the size of the store that you need. This can be any multiple of 4kB up to // System Partition Table and not at build time.
// a maximum 256Kb.
//#define LUA_FLASH_STORE 0x10000
// By default Lua executes the file init.lua at start up. The following // By default Lua executes the file init.lua at start up. The following
...@@ -71,10 +68,10 @@ ...@@ -71,10 +68,10 @@
// general, limiting the size of the FS only to what your application needs // general, limiting the size of the FS only to what your application needs
// gives the fastest start-up and imaging times. // gives the fastest start-up and imaging times.
// Note that you should now configure SPIFFS size and position directly in the
// System Partition Table and not at build time.
#define BUILD_SPIFFS #define BUILD_SPIFFS
//#define SPIFFS_FIXED_LOCATION 0x100000
//#define SPIFFS_MAX_FILESYSTEM_SIZE 0x20000
//#define SPIFFS_SIZE_1M_BOUNDARY
#define SPIFFS_CACHE 1 // Enable if you use you SPIFFS in R/W mode #define SPIFFS_CACHE 1 // Enable if you use you SPIFFS in R/W mode
#define SPIFFS_MAX_OPEN_FILES 4 // maximum number of open files for SPIFFS #define SPIFFS_MAX_OPEN_FILES 4 // maximum number of open files for SPIFFS
#define FS_OBJ_NAME_LEN 31 // maximum length of a filename #define FS_OBJ_NAME_LEN 31 // maximum length of a filename
...@@ -206,6 +203,19 @@ ...@@ -206,6 +203,19 @@
// change this if you have tracked the implications through the Firmware sources // change this if you have tracked the implications through the Firmware sources
// and understand the these. // and understand the these.
#define NODEMCU_EAGLEROM_PARTITION 1
#define NODEMCU_IROM0TEXT_PARTITION 2
#define NODEMCU_LFS0_PARTITION 3
#define NODEMCU_LFS1_PARTITION 4
#define NODEMCU_TLSCERT_PARTITION 5
#define NODEMCU_SPIFFS0_PARTITION 6
#define NODEMCU_SPIFFS1_PARTITION 7
#define LUA_FLASH_STORE 0x0
#define SPIFFS_FIXED_LOCATION 0x0
#define SPIFFS_MAX_FILESYSTEM_SIZE (~0x0)
//#define SPIFFS_SIZE_1M_BOUNDARY
#define LUA_TASK_PRIO USER_TASK_PRIO_0 #define LUA_TASK_PRIO USER_TASK_PRIO_0
#define LUA_PROCESS_LINE_SIG 2 #define LUA_PROCESS_LINE_SIG 2
#define LUA_OPTIMIZE_DEBUG 2 #define LUA_OPTIMIZE_DEBUG 2
......
...@@ -11,7 +11,7 @@ double floor(double x) ...@@ -11,7 +11,7 @@ double floor(double x)
#define MINEXP -2047 /* (MIN_EXP * 16) - 1 */ #define MINEXP -2047 /* (MIN_EXP * 16) - 1 */
#define HUGE MAXFLOAT #define HUGE MAXFLOAT
double a1[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = static const double a1[] =
{ {
1.0, 1.0,
0.95760328069857365, 0.95760328069857365,
...@@ -31,7 +31,7 @@ double a1[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = ...@@ -31,7 +31,7 @@ double a1[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR =
0.52213689121370692, 0.52213689121370692,
0.50000000000000000 0.50000000000000000
}; };
double a2[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = static const double a2[] =
{ {
0.24114209503420288E-17, 0.24114209503420288E-17,
0.92291566937243079E-18, 0.92291566937243079E-18,
...@@ -42,18 +42,19 @@ double a2[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = ...@@ -42,18 +42,19 @@ double a2[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR =
0.29306999570789681E-17, 0.29306999570789681E-17,
0.11260851040933474E-17 0.11260851040933474E-17
}; };
double p1 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.833333333333332114e-1; static const double
double p2 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.125000000005037992e-1; p1 = 0.833333333333332114e-1,
double p3 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.223214212859242590e-2; p2 = 0.125000000005037992e-1,
double p4 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.434457756721631196e-3; p3 = 0.223214212859242590e-2,
double q1 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.693147180559945296e0; p4 = 0.434457756721631196e-3,
double q2 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.240226506959095371e0; q1 = 0.693147180559945296e0,
double q3 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.555041086640855953e-1; q2 = 0.240226506959095371e0,
double q4 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.961812905951724170e-2; q3 = 0.555041086640855953e-1,
double q5 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.133335413135857847e-2; q4 = 0.961812905951724170e-2,
double q6 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.154002904409897646e-3; q5 = 0.133335413135857847e-2,
double q7 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.149288526805956082e-4; q6 = 0.154002904409897646e-3,
double k ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.442695040888963407; q7 = 0.149288526805956082e-4,
k = 0.442695040888963407;
double pow(double x, double y) double pow(double x, double y)
{ {
......
...@@ -28,12 +28,12 @@ static int db_getregistry (lua_State *L) { ...@@ -28,12 +28,12 @@ static int db_getregistry (lua_State *L) {
} }
static int db_getstrings (lua_State *L) { static int db_getstrings (lua_State *L) {
size_t i,n; size_t i,n=0;
stringtable *tb; stringtable *tb;
GCObject *o; GCObject *o;
#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) #ifndef LUA_CROSS_COMPILER
const char *opt = lua_tolstring (L, 1, &n); const char *opt = lua_tolstring (L, 1, &n);
if (n==3 && memcmp(opt, "ROM", 4) == 0) { if (n==3 && c_memcmp(opt, "ROM", 4) == 0) {
if (G(L)->ROstrt.hash == NULL) if (G(L)->ROstrt.hash == NULL)
return 0; return 0;
tb = &G(L)->ROstrt; tb = &G(L)->ROstrt;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#ifdef LUA_FLASH_STORE
#include "lobject.h" #include "lobject.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lstate.h" #include "lstate.h"
...@@ -31,6 +30,7 @@ ...@@ -31,6 +30,7 @@
*/ */
static char *flashAddr; static char *flashAddr;
static uint32_t flashSize;
static uint32_t flashAddrPhys; static uint32_t flashAddrPhys;
static uint32_t flashSector; static uint32_t flashSector;
static uint32_t curOffset; static uint32_t curOffset;
...@@ -38,9 +38,8 @@ static uint32_t curOffset; ...@@ -38,9 +38,8 @@ static uint32_t curOffset;
#define ALIGN(s) (((s)+sizeof(size_t)-1) & ((size_t) (- (signed) sizeof(size_t)))) #define ALIGN(s) (((s)+sizeof(size_t)-1) & ((size_t) (- (signed) sizeof(size_t))))
#define ALIGN_BITS(s) (((uint32_t)s) & (sizeof(size_t)-1)) #define ALIGN_BITS(s) (((uint32_t)s) & (sizeof(size_t)-1))
#define ALL_SET (~0) #define ALL_SET (~0)
#define FLASH_SIZE LUA_FLASH_STORE
#define FLASH_PAGE_SIZE INTERNAL_FLASH_SECTOR_SIZE #define FLASH_PAGE_SIZE INTERNAL_FLASH_SECTOR_SIZE
#define FLASH_PAGES (FLASH_SIZE/FLASH_PAGE_SIZE) #define FLASH_PAGES (flashSize/FLASH_PAGE_SIZE)
#define READ_BLOCKSIZE 1024 #define READ_BLOCKSIZE 1024
#define WRITE_BLOCKSIZE 2048 #define WRITE_BLOCKSIZE 2048
#define DICTIONARY_WINDOW 16384 #define DICTIONARY_WINDOW 16384
...@@ -49,8 +48,6 @@ static uint32_t curOffset; ...@@ -49,8 +48,6 @@ static uint32_t curOffset;
#define WRITE_BLOCKS ((DICTIONARY_WINDOW/WRITE_BLOCKSIZE)+1) #define WRITE_BLOCKS ((DICTIONARY_WINDOW/WRITE_BLOCKSIZE)+1)
#define WRITE_BLOCK_WORDS (WRITE_BLOCKSIZE/WORDSIZE) #define WRITE_BLOCK_WORDS (WRITE_BLOCKSIZE/WORDSIZE)
char flash_region_base[FLASH_SIZE] ICACHE_FLASH_RESERVED_ATTR;
struct INPUT { struct INPUT {
int fd; int fd;
int len; int len;
...@@ -152,11 +149,16 @@ static void flashErase(uint32_t start, uint32_t end){ ...@@ -152,11 +149,16 @@ static void flashErase(uint32_t start, uint32_t end){
* Hook in lstate.c:f_luaopen() to set up ROstrt and ROpvmain if needed * Hook in lstate.c:f_luaopen() to set up ROstrt and ROpvmain if needed
*/ */
LUAI_FUNC void luaN_init (lua_State *L) { LUAI_FUNC void luaN_init (lua_State *L) {
curOffset = 0;
flashAddr = flash_region_base; flashSize = platform_flash_get_partition (NODEMCU_LFS0_PARTITION, &flashAddrPhys);
flashAddrPhys = platform_flash_mapped2phys((uint32_t)flashAddr); if (flashSize == 0) {
return; // Nothing to do if the size is zero
}
G(L)->LFSsize = flashSize;
flashAddr = cast(char *, platform_flash_phys2mapped(flashAddrPhys));
flashSector = platform_flash_get_sector_of_address(flashAddrPhys); flashSector = platform_flash_get_sector_of_address(flashAddrPhys);
FlashHeader *fh = cast(FlashHeader *, flashAddr); FlashHeader *fh = cast(FlashHeader *, flashAddr);
curOffset = 0;
/* /*
* For the LFS to be valid, its signature has to be correct for this build * For the LFS to be valid, its signature has to be correct for this build
...@@ -201,6 +203,13 @@ LUALIB_API int luaN_reload_reboot (lua_State *L) { ...@@ -201,6 +203,13 @@ LUALIB_API int luaN_reload_reboot (lua_State *L) {
// luaL_dbgbreak(); // luaL_dbgbreak();
const char *fn = lua_tostring(L, 1), *msg = ""; const char *fn = lua_tostring(L, 1), *msg = "";
int status; int status;
if (G(L)->LFSsize == 0) {
lua_pushstring(L, "No LFS partition allocated");
return 1;
}
/* /*
* Do a protected call of loadLFS. * Do a protected call of loadLFS.
* *
...@@ -264,13 +273,18 @@ LUAI_FUNC int luaN_index (lua_State *L) { ...@@ -264,13 +273,18 @@ LUAI_FUNC int luaN_index (lua_State *L) {
int i; int i;
int n = lua_gettop(L); int n = lua_gettop(L);
/* Return nil + the LFS base address if the LFS isn't loaded */ /* Return nil + the LFS base address if the LFS size > 0 and it isn't loaded */
if(!(G(L)->ROpvmain)) { if (!(G(L)->ROpvmain)) {
lua_settop(L, 0); lua_settop(L, 0);
lua_pushnil(L); lua_pushnil(L);
lua_pushinteger(L, (lua_Integer) flashAddr); if (G(L)->LFSsize) {
lua_pushinteger(L, flashAddrPhys); lua_pushinteger(L, (lua_Integer) flashAddr);
return 3; lua_pushinteger(L, flashAddrPhys);
lua_pushinteger(L, G(L)->LFSsize);
return 4;
} else {
return 1;
}
} }
/* Push the LClosure of the LFS index function */ /* Push the LClosure of the LFS index function */
...@@ -409,10 +423,10 @@ int procFirstPass (void) { ...@@ -409,10 +423,10 @@ int procFirstPass (void) {
flash_error("Incorrect LFS build type"); flash_error("Incorrect LFS build type");
if ((fh->flash_sig & ~FLASH_SIG_ABSOLUTE) != FLASH_SIG) if ((fh->flash_sig & ~FLASH_SIG_ABSOLUTE) != FLASH_SIG)
flash_error("incorrect LFS header signature"); flash_error("incorrect LFS header signature");
if (fh->flash_size > FLASH_SIZE) if (fh->flash_size > flashSize)
flash_error("LFS Image too big for configured LFS region"); flash_error("LFS Image too big for configured LFS region");
if ((fh->flash_size & 0x3) || if ((fh->flash_size & 0x3) ||
fh->flash_size > FLASH_SIZE || fh->flash_size > flashSize ||
out->flagsLen != 1 + (out->flashLen/WORDSIZE - 1) / BITS_PER_WORD) out->flagsLen != 1 + (out->flashLen/WORDSIZE - 1) / BITS_PER_WORD)
flash_error("LFS length mismatch"); flash_error("LFS length mismatch");
out->flags = luaM_newvector(out->L, out->flagsLen, uint); out->flags = luaM_newvector(out->L, out->flagsLen, uint);
...@@ -557,4 +571,3 @@ static int loadLFSgc (lua_State *L) { ...@@ -557,4 +571,3 @@ static int loadLFSgc (lua_State *L) {
} }
return 0; return 0;
} }
#endif
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
#if defined(LUA_FLASH_STORE) && !defined(lflash_h) #ifndef lflash_h
#define lflash_h #define lflash_h
#include "lobject.h" #include "lobject.h"
......
...@@ -28,10 +28,6 @@ ...@@ -28,10 +28,6 @@
#define GCSWEEPCOST 10 #define GCSWEEPCOST 10
#define GCFINALIZECOST 100 #define GCFINALIZECOST 100
#if READONLYMASK != (1<<READONLYBIT) || (defined(LUA_FLASH_STORE) && LFSMASK != (1<<LFSBIT))
#error "lgc.h and object.h out of sync on READONLYMASK / LFSMASK"
#endif
#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) #define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
#define makewhite(g,x) \ #define makewhite(g,x) \
......
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
#define isfixedstack(x) testbit((x)->marked, FIXEDSTACKBIT) #define isfixedstack(x) testbit((x)->marked, FIXEDSTACKBIT)
#define fixedstack(x) l_setbit((x)->marked, FIXEDSTACKBIT) #define fixedstack(x) l_setbit((x)->marked, FIXEDSTACKBIT)
#define unfixedstack(x) resetbit((x)->marked, FIXEDSTACKBIT) #define unfixedstack(x) resetbit((x)->marked, FIXEDSTACKBIT)
#ifdef LUA_FLASH_STORE #ifndef LUA_CROSS_COMPILER
#define isLFSobject(x) testbit(getmarked(x), LFSBIT) #define isLFSobject(x) testbit(getmarked(x), LFSBIT)
#define stringfix(s) if (!test2bits(getmarked(&(s)->tsv), FIXEDBIT, LFSBIT)) {l_setbit((s)->tsv.marked, FIXEDBIT);} #define stringfix(s) if (!test2bits(getmarked(&(s)->tsv), FIXEDBIT, LFSBIT)) {l_setbit((s)->tsv.marked, FIXEDBIT);}
#else #else
......
...@@ -24,9 +24,7 @@ ...@@ -24,9 +24,7 @@
#define NUM_TAGS (LAST_TAG+1) #define NUM_TAGS (LAST_TAG+1)
#define READONLYMASK (1<<7) /* denormalised bitmask for READONLYBIT and */ #define READONLYMASK (1<<7) /* denormalised bitmask for READONLYBIT and */
#ifdef LUA_FLASH_STORE
#define LFSMASK (1<<6) /* LFSBIT to avoid include proliferation */ #define LFSMASK (1<<6) /* LFSBIT to avoid include proliferation */
#endif
/* /*
** Extra tags for non-values ** Extra tags for non-values
*/ */
......
...@@ -73,7 +73,7 @@ static void f_luaopen (lua_State *L, void *ud) { ...@@ -73,7 +73,7 @@ static void f_luaopen (lua_State *L, void *ud) {
sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) #ifndef LUA_CROSS_COMPILER
luaN_init(L); /* optionally map RO string table */ luaN_init(L); /* optionally map RO string table */
#endif #endif
luaT_init(L); luaT_init(L);
...@@ -196,11 +196,12 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { ...@@ -196,11 +196,12 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
#else #else
g->memlimit = 0; g->memlimit = 0;
#endif #endif
#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) #ifndef LUA_CROSS_COMPILER
g->ROstrt.size = 0; g->ROstrt.size = 0;
g->ROstrt.nuse = 0; g->ROstrt.nuse = 0;
g->ROstrt.hash = NULL; g->ROstrt.hash = NULL;
g->ROpvmain = NULL; g->ROpvmain = NULL;
g->LFSsize = 0;
#endif #endif
for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL; for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
......
...@@ -94,9 +94,10 @@ typedef struct global_State { ...@@ -94,9 +94,10 @@ typedef struct global_State {
UpVal uvhead; /* head of double-linked list of all open upvalues */ UpVal uvhead; /* head of double-linked list of all open upvalues */
struct Table *mt[NUM_TAGS]; /* metatables for basic types */ struct Table *mt[NUM_TAGS]; /* metatables for basic types */
TString *tmname[TM_N]; /* array with tag-method names */ TString *tmname[TM_N]; /* array with tag-method names */
#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) #ifndef LUA_CROSS_COMPILER
stringtable ROstrt; /* Flash-based hash table for RO strings */ stringtable ROstrt; /* Flash-based hash table for RO strings */
Proto *ROpvmain; /* Flash-based Proto main */ Proto *ROpvmain; /* Flash-based Proto main */
int LFSsize; /* Size of Lua Flash Store */
#endif #endif
} global_State; } global_State;
......
...@@ -112,7 +112,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { ...@@ -112,7 +112,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
return ts; return ts;
} }
} }
#if defined(LUA_FLASH_STORE) && !defined(LUA_CROSS_COMPILER) #ifndef LUA_CROSS_COMPILER
/* /*
* The RAM strt is searched first since RAM access is faster tham Flash access. * The RAM strt is searched first since RAM access is faster tham Flash access.
* If a miss, then search the RO string table. * If a miss, then search the RO string table.
......
...@@ -22,9 +22,7 @@ ...@@ -22,9 +22,7 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
#include "legc.h" #include "legc.h"
#ifdef LUA_FLASH_STORE
#include "lflash.h" #include "lflash.h"
#endif
#include "os_type.h" #include "os_type.h"
lua_State *globalL = NULL; lua_State *globalL = NULL;
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
#define LUA_CORE #define LUA_CORE
#include "lobject.h" #include "lobject.h"
#include "lstring.h" #include "lstring.h"
#undef LUA_FLASH_STORE
#define LUA_FLASH_STORE
#include "lflash.h" #include "lflash.h"
#include "uzlib.h" #include "uzlib.h"
......
...@@ -17,9 +17,7 @@ ...@@ -17,9 +17,7 @@
#include "platform.h" #include "platform.h"
#include "lrodefs.h" #include "lrodefs.h"
#ifdef LUA_FLASH_STORE
#include "lflash.h" #include "lflash.h"
#endif
#include "c_types.h" #include "c_types.h"
#include "c_string.h" #include "c_string.h"
#include "driver/uart.h" #include "driver/uart.h"
...@@ -162,10 +160,6 @@ static int node_flashid( lua_State* L ) ...@@ -162,10 +160,6 @@ static int node_flashid( lua_State* L )
// Lua: flashsize() // Lua: flashsize()
static int node_flashsize( lua_State* L ) static int node_flashsize( lua_State* L )
{ {
if (lua_type(L, 1) == LUA_TNUMBER)
{
flash_rom_set_size_byte(luaL_checkinteger(L, 1));
}
uint32_t sz = flash_rom_get_size_byte(); uint32_t sz = flash_rom_get_size_byte();
lua_pushinteger( L, sz ); lua_pushinteger( L, sz );
return 1; return 1;
...@@ -603,10 +597,8 @@ static const LUA_REG_TYPE node_map[] = ...@@ -603,10 +597,8 @@ static const LUA_REG_TYPE node_map[] =
{ LSTRKEY( "heap" ), LFUNCVAL( node_heap ) }, { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) },
{ LSTRKEY( "info" ), LFUNCVAL( node_info ) }, { LSTRKEY( "info" ), LFUNCVAL( node_info ) },
{ LSTRKEY( "task" ), LROVAL( node_task_map ) }, { LSTRKEY( "task" ), LROVAL( node_task_map ) },
#ifdef LUA_FLASH_STORE
{ LSTRKEY( "flashreload" ), LFUNCVAL( luaN_reload_reboot ) }, { LSTRKEY( "flashreload" ), LFUNCVAL( luaN_reload_reboot ) },
{ LSTRKEY( "flashindex" ), LFUNCVAL( luaN_index ) }, { LSTRKEY( "flashindex" ), LFUNCVAL( luaN_index ) },
#endif
{ LSTRKEY( "restart" ), LFUNCVAL( node_restart ) }, { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) },
{ LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) }, { LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) },
{ LSTRKEY( "dsleepMax" ), LFUNCVAL( dsleepMax ) }, { LSTRKEY( "dsleepMax" ), LFUNCVAL( dsleepMax ) },
......
...@@ -46,10 +46,10 @@ void __attribute__((noreturn)) TEXT_SECTION_ATTR rtc_time_enter_deep_sleep_final ...@@ -46,10 +46,10 @@ void __attribute__((noreturn)) TEXT_SECTION_ATTR rtc_time_enter_deep_sleep_final
void rtctime_early_startup (void) void rtctime_early_startup (void)
{ {
Cache_Read_Enable (0, 0, 1); // Cache_Read_Enable (0, 0, 1);
rtc_time_register_bootup (); rtc_time_register_bootup ();
rtc_time_switch_clocks (); rtc_time_switch_clocks ();
Cache_Read_Disable (); // Cache_Read_Disable ();
} }
void rtctime_late_startup (void) void rtctime_late_startup (void)
......
...@@ -39,16 +39,19 @@ uint32_t flash_detect_size_byte(void) ...@@ -39,16 +39,19 @@ uint32_t flash_detect_size_byte(void)
#undef FLASH_BUFFER_SIZE_DETECT #undef FLASH_BUFFER_SIZE_DETECT
} }
SPIFlashInfo flash_rom_getinfo(void) static SPIFlashInfo spi_flash_info = {0};
SPIFlashInfo *flash_rom_getinfo(void)
{ {
volatile SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR; if (spi_flash_info.entry_point == 0) {
spi_flash_read(0, (uint32 *)(& spi_flash_info), sizeof(spi_flash_info)); spi_flash_read(0, (uint32 *)(& spi_flash_info), sizeof(spi_flash_info));
return spi_flash_info; }
return &spi_flash_info;
} }
uint8_t flash_rom_get_size_type(void) uint8_t flash_rom_get_size_type(void)
{ {
return flash_rom_getinfo().size; return flash_rom_getinfo()->size;
} }
uint32_t flash_rom_get_size_byte(void) uint32_t flash_rom_get_size_byte(void)
...@@ -56,7 +59,7 @@ uint32_t flash_rom_get_size_byte(void) ...@@ -56,7 +59,7 @@ uint32_t flash_rom_get_size_byte(void)
static uint32_t flash_size = 0; static uint32_t flash_size = 0;
if (flash_size == 0) if (flash_size == 0)
{ {
switch (flash_rom_getinfo().size) switch (flash_rom_getinfo()->size)
{ {
case SIZE_2MBIT: case SIZE_2MBIT:
// 2Mbit, 256kByte // 2Mbit, 256kByte
...@@ -107,99 +110,15 @@ uint32_t flash_rom_get_size_byte(void) ...@@ -107,99 +110,15 @@ uint32_t flash_rom_get_size_byte(void)
return flash_size; return flash_size;
} }
bool flash_rom_set_size_type(uint8_t size)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
NODE_DBG("\nBEGIN SET FLASH HEADER\n");
uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR;
if (SPI_FLASH_RESULT_OK == spi_flash_read(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
{
NODE_DBG("\nflash_rom_set_size_type(%u), was %u\n", size, ((SPIFlashInfo *)data)->size );
((SPIFlashInfo *)data)->size = size;
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE))
{
NODE_DBG("\nSECTOR 0 ERASE SUCCESS\n");
}
if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
{
NODE_DBG("\nWRITE SUCCESS, %u\n", size);
}
}
NODE_DBG("\nEND SET FLASH HEADER\n");
return true;
}
bool flash_rom_set_size_byte(uint32_t size)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
bool result = true;
uint32_t flash_size = 0;
switch (size)
{
case 256 * 1024:
// 2Mbit, 256kByte
flash_size = SIZE_2MBIT;
flash_rom_set_size_type(flash_size);
break;
case 512 * 1024:
// 4Mbit, 512kByte
flash_size = SIZE_4MBIT;
flash_rom_set_size_type(flash_size);
break;
case 1 * 1024 * 1024:
// 8Mbit, 1MByte
flash_size = SIZE_8MBIT;
flash_rom_set_size_type(flash_size);
break;
case 2 * 1024 * 1024:
// 16Mbit, 2MByte
flash_size = SIZE_16MBIT;
flash_rom_set_size_type(flash_size);
break;
case 4 * 1024 * 1024:
// 32Mbit, 4MByte
flash_size = SIZE_32MBIT;
flash_rom_set_size_type(flash_size);
break;
case 8 * 1024 * 1024:
// 64Mbit, 8MByte
flash_size = SIZE_64MBIT;
flash_rom_set_size_type(flash_size);
break;
case 16 * 1024 * 1024:
// 128Mbit, 16MByte
flash_size = SIZE_128MBIT;
flash_rom_set_size_type(flash_size);
break;
default:
// Unknown flash size.
result = false;
break;
}
return result;
}
uint16_t flash_rom_get_sec_num(void) uint16_t flash_rom_get_sec_num(void)
{ {
//static uint16_t sec_num = 0;
// return flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE);
// c_printf("\nflash_rom_get_size_byte()=%d\n", ( flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE) ));
// if( sec_num == 0 )
//{
// sec_num = 4 * 1024 * 1024 / (SPI_FLASH_SEC_SIZE);
//}
//return sec_num;
return ( flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE) ); return ( flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE) );
} }
uint8_t flash_rom_get_mode(void) uint8_t flash_rom_get_mode(void)
{ {
SPIFlashInfo spi_flash_info = flash_rom_getinfo(); uint8_t mode = flash_rom_getinfo()->mode;
switch (spi_flash_info.mode) switch (mode)
{ {
// Reserved for future use // Reserved for future use
case MODE_QIO: case MODE_QIO:
...@@ -211,14 +130,14 @@ uint8_t flash_rom_get_mode(void) ...@@ -211,14 +130,14 @@ uint8_t flash_rom_get_mode(void)
case MODE_DOUT: case MODE_DOUT:
break; break;
} }
return spi_flash_info.mode; return mode;
} }
uint32_t flash_rom_get_speed(void) uint32_t flash_rom_get_speed(void)
{ {
uint32_t speed = 0; uint32_t speed = 0;
SPIFlashInfo spi_flash_info = flash_rom_getinfo(); uint8_t spi_speed = flash_rom_getinfo()->speed;
switch (spi_flash_info.speed) switch (spi_speed)
{ {
case SPEED_40MHZ: case SPEED_40MHZ:
// 40MHz // 40MHz
...@@ -240,47 +159,6 @@ uint32_t flash_rom_get_speed(void) ...@@ -240,47 +159,6 @@ uint32_t flash_rom_get_speed(void)
return speed; return speed;
} }
bool flash_rom_set_speed(uint32_t speed)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
NODE_DBG("\nBEGIN SET FLASH HEADER\n");
uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR;
uint8_t speed_type = SPEED_40MHZ;
if (speed < 26700000)
{
speed_type = SPEED_20MHZ;
}
else if (speed < 40000000)
{
speed_type = SPEED_26MHZ;
}
else if (speed < 80000000)
{
speed_type = SPEED_40MHZ;
}
else if (speed >= 80000000)
{
speed_type = SPEED_80MHZ;
}
if (SPI_FLASH_RESULT_OK == spi_flash_read(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
{
((SPIFlashInfo *)(&data[0]))->speed = speed_type;
NODE_DBG("\nflash_rom_set_speed(%u), was %u\n", speed_type, ((SPIFlashInfo *)(&data[0]))->speed );
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE))
{
NODE_DBG("\nERASE SUCCESS\n");
}
if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
{
NODE_DBG("\nWRITE SUCCESS, %u\n", speed_type);
}
}
NODE_DBG("\nEND SET FLASH HEADER\n");
return true;
}
uint8_t byte_of_aligned_array(const uint8_t *aligned_array, uint32_t index) uint8_t byte_of_aligned_array(const uint8_t *aligned_array, uint32_t index)
{ {
if ( (((uint32_t)aligned_array) % 4) != 0 ) if ( (((uint32_t)aligned_array) % 4) != 0 )
...@@ -303,31 +181,5 @@ uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index) ...@@ -303,31 +181,5 @@ uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index)
volatile uint32_t v = ((uint32_t *)aligned_array)[ index / 2 ]; volatile uint32_t v = ((uint32_t *)aligned_array)[ index / 2 ];
uint16_t *p = (uint16_t *) (&v); uint16_t *p = (uint16_t *) (&v);
return (index % 2 == 0) ? p[ 0 ] : p[ 1 ]; return (index % 2 == 0) ? p[ 0 ] : p[ 1 ];
// return p[ (index % 2) ]; // -- why error???
// (byte_of_aligned_array((uint8_t *)aligned_array, index * 2 + 1) << 8) | byte_of_aligned_array((uint8_t *)aligned_array, index * 2);
} }
// uint8_t flash_rom_get_checksum(void)
// {
// // SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR = flash_rom_getinfo();
// // uint32_t address = sizeof(spi_flash_info) + spi_flash_info.segment_size;
// // uint32_t address_aligned_4bytes = (address + 3) & 0xFFFFFFFC;
// // uint8_t buffer[64] = {0};
// // spi_flash_read(address, (uint32 *) buffer, 64);
// // uint8_t i = 0;
// // c_printf("\nBEGIN DUMP\n");
// // for (i = 0; i < 64; i++)
// // {
// // c_printf("%02x," , buffer[i]);
// // }
// // i = (address + 0x10) & 0x10 - 1;
// // c_printf("\nSIZE:%d CHECK SUM:%02x\n", spi_flash_info.segment_size, buffer[i]);
// // c_printf("\nEND DUMP\n");
// // return buffer[0];
// return 0;
// }
// uint8_t flash_rom_calc_checksum(void)
// {
// return 0;
// }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment