Skip to content

Support for nonos-sdk 3.0.x and legacy OTA #283

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

Closed
wants to merge 4 commits into from
Closed
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
162 changes: 103 additions & 59 deletions builder/frameworks/esp8266-nonos-sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
https://github.com/espressif/ESP8266_NONOS_SDK
"""

from os.path import isdir, join
from os.path import isdir, join, isfile

from SCons.Script import Builder, DefaultEnvironment

Expand Down Expand Up @@ -61,7 +61,8 @@
CXXFLAGS=[
"-fno-rtti",
"-fno-exceptions",
"-std=c++11"
"-std=c++11",
"-Wno-literal-suffix"
],

LINKFLAGS=[
Expand All @@ -83,16 +84,8 @@

CPPPATH=[
join(FRAMEWORK_DIR, "include"),
join(FRAMEWORK_DIR, "extra_include"),
join(FRAMEWORK_DIR, "driver_lib", "include"),
join(FRAMEWORK_DIR, "include", "espressif"),
join(FRAMEWORK_DIR, "include", "lwip"),
join(FRAMEWORK_DIR, "include", "lwip", "ipv4"),
join(FRAMEWORK_DIR, "include", "lwip", "ipv6"),
join(FRAMEWORK_DIR, "include", "nopoll"),
join(FRAMEWORK_DIR, "include", "ssl"),
join(FRAMEWORK_DIR, "include", "json"),
join(FRAMEWORK_DIR, "include", "openssl")
join(FRAMEWORK_DIR, "third_party", "include")
],

LIBPATH=[
Expand All @@ -102,71 +95,122 @@

LIBS=[
"airkiss", "at", "c", "crypto", "driver", "espnow", "gcc", "json",
"lwip", "main", "mbedtls", "mesh", "net80211", "phy", "pp", "pwm",
"lwip", "main", "mbedtls", "net80211", "phy", "pp", "pwm",
"smartconfig", "ssl", "upgrade", "wpa", "wpa2", "wps"
],

BUILDERS=dict(
ElfToBin=Builder(
action=env.VerboseAction(" ".join([
'"%s"' % join(platform.get_package_dir("tool-esptool"), "esptool"),
"-eo", "$SOURCE",
"-bo", "${TARGET}",
"-bm", "$BOARD_FLASH_MODE",
"-bf", "${__get_board_f_flash(__env__)}",
"-bz", "${__get_flash_size(__env__)}",
"-bs", ".text",
"-bs", ".data",
"-bs", ".rodata",
"-bc", "-ec",
"-eo", "$SOURCE",
"-es", ".irom0.text", "${TARGET}.irom0text.bin",
"-ec", "-v"
]), "Building $TARGET"),
suffix=".bin"
)
)
]
)


###################################################################################
# common code between esp8266-nonos-sdk and esp8266-rtos-sdk for OTA support

# choose LDSCRIPT_PATH based on OTA
if not env.BoardConfig().get("build.ldscript", ""):
env.Replace(
if "ota" in BUILD_TARGETS: # flash map size >= 5 only!!!
LDSCRIPT_PATH=join(FRAMEWORK_DIR, "ld", "eagle.app.v6.new.2048.ld")
else:
LDSCRIPT_PATH=join(FRAMEWORK_DIR, "ld", "eagle.app.v6.ld")
)

board_flash_size = int(env.BoardConfig().get("upload.maximum_size", 0))
if board_flash_size > 8388608:
init_data_flash_address = 0xffc000 # for 16 MB
elif board_flash_size > 4194304:
init_data_flash_address = 0x7fc000 # for 8 MB
elif board_flash_size > 2097152:
init_data_flash_address = 0x3fc000 # for 4 MB
elif board_flash_size > 1048576:
init_data_flash_address = 0x1fc000 # for 2 MB
elif board_flash_size > 524288:
init_data_flash_address = 0xfc000 # for 1 MB
else:
init_data_flash_address = 0x7c000 # for 512 kB
env.Replace(LDSCRIPT_PATH=LDSCRIPT_PATH)


# evaluate SPI_FLASH_SIZE_MAP flag for NONOS_SDK 3.x and set CCFLAG
board_flash_size = int(env.BoardConfig().get("upload.maximum_size", 524288))
flash_size_maps = [0.5, 0.25, 1.0, 0.0, 0.0, 2.0, 4.0, 0.0, 8.0, 16.0] # ignore maps 3 and 4.prefer 5 and 6
flash_sizes_str = ['512KB','256KB','1MB','2MB','4MB','2MB-c1','4MB-c1','4MB-c2','8MB','16MB']
try:
flash_size_map = flash_size_maps.index(board_flash_size/1048576)
flash_size_str = flash_sizes_str[flash_size_map]
except:
flash_size_map = 6
flash_size_str = '4MB-c1'
# for OTA, only size maps 5, 6, 8 and 9 are supported to avoid linking twice for user1 and user2

env.Append(CCFLAGS=["-DSPI_FLASH_SIZE_MAP="+str(flash_size_map)]) # NONOS-SDK 3.x user_main.c need it
env.Append(FLASH_SIZE_STR=flash_size_str) # required for custom uploader


# create binaries list to upload

if "ota" in BUILD_TARGETS: # if OTA, flash user1 but generate user1 and user2
boot_bin = join(FRAMEWORK_DIR, "bin", "boot_v1.7.bin")
user_bin = join("$BUILD_DIR", "${PROGNAME}.bin.user1.bin") # firmware.bin.user1.bin # user1.4096.new.6.bin
user_addr = 0x1000
else: # non ota
boot_bin = join("$BUILD_DIR", "${PROGNAME}.bin") # firmware.bin # eagle.flash.bin
user_bin = join("$BUILD_DIR", "${PROGNAME}.bin.irom0text.bin") # firmware.bin.irom0text.bin # eagle.irom0text.bin
if (env['PIOFRAMEWORK'][0] == "esp8266-rtos-sdk"):
user_addr = 0x20000
else:
user_addr = 0x10000

# check the init_data_default file to use
esp_init_data_default_file = "esp_init_data_default_v08.bin" # new in NONOS 3.04
if not isfile(join(FRAMEWORK_DIR, "bin", esp_init_data_default_file)):
esp_init_data_default_file = "esp_init_data_default.bin"

data_bin = join(FRAMEWORK_DIR, "bin", esp_init_data_default_file)
blank_bin = join(FRAMEWORK_DIR, "bin", "blank.bin")
rf_cal_addr = board_flash_size-0x5000 # 3fb000 for 4M board blank_bin
phy_data_addr = board_flash_size-0x4000 # 3fc000 for 4M board data_bin
sys_param_addr = board_flash_size-0x2000 # 3fe000 for 4M board blank_bin

env.Append(
FLASH_EXTRA_IMAGES=[
("0x10000", join("$BUILD_DIR", "${PROGNAME}.bin.irom0text.bin")),
(hex(init_data_flash_address),
join(FRAMEWORK_DIR, "bin", "esp_init_data_default.bin")),
(hex(init_data_flash_address + 0x2000),
join(FRAMEWORK_DIR, "bin", "blank.bin"))
(hex(0), boot_bin),
(hex(user_addr), user_bin),
(hex(phy_data_addr), data_bin),
(hex(sys_param_addr), blank_bin),
(hex(rf_cal_addr), blank_bin),
("--flash_mode", "$BOARD_FLASH_MODE"),
("--flash_freq", "$${__get_board_f_flash(__env__)}m"),
("--flash_size", "$FLASH_SIZE_STR") # required by NONOS 3.0.4
]
)

# register genbin.py BUILDER which allows to create OTA files
if "ota" in BUILD_TARGETS: # if OTA, flash user1 but generate user1 and user2
env.Append(
BUILDERS=dict(
ElfToBin=Builder(
action=env.VerboseAction(" ".join([
'"%s"' % env.subst("$PYTHONEXE"), join(platform.get_package_dir("tool-genbin"), "genbin.py"),
"12", # create firmware.bin.user1.bin and firmware.bin.user2.bin
"$BOARD_FLASH_MODE", "${__get_board_f_flash(__env__)}m", "$FLASH_SIZE_STR",
"$SOURCE", "${TARGET}.user1.bin", "${TARGET}.user2.bin"
# could have used espressif naming: user1.4096.new.6.bin or user1.16384.new.9.bin
]), "Building $TARGET"),
suffix=".bin"
)
)
)
else:
env.Append(
BUILDERS=dict(
ElfToBin=Builder(
action=env.VerboseAction(" ".join([
'"%s"' % env.subst("$PYTHONEXE"), join(platform.get_package_dir("tool-genbin"), "genbin.py"),
"0", # create firmware.bin and firmware.bin.irom0text.bin
"$BOARD_FLASH_MODE", "${__get_board_f_flash(__env__)}m", "$FLASH_SIZE_STR",
"$SOURCE", "${TARGET}", "${TARGET}.irom0text.bin"
]), "Building $TARGET"),
suffix=".bin"
)
)
)

###################################################################################


#
# Target: Build Driver Library
#

libs = []

libs.append(env.BuildLibrary(
join(FRAMEWORK_DIR, "lib", "driver"),
join(FRAMEWORK_DIR, "driver_lib")
))
if False:
libs.append(env.BuildLibrary(
join(FRAMEWORK_DIR, "lib", "driver"),
join(FRAMEWORK_DIR, "driver_lib")
))

env.Prepend(LIBS=libs)
147 changes: 99 additions & 48 deletions builder/frameworks/esp8266-rtos-sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
https://github.com/espressif/ESP8266_RTOS_SDK
"""

from os.path import isdir, join
from os.path import isdir, join, isfile

from SCons.Script import Builder, DefaultEnvironment

Expand Down Expand Up @@ -61,7 +61,8 @@
CXXFLAGS=[
"-fno-rtti",
"-fno-exceptions",
"-std=c++11"
"-std=c++11",
"-Wno-literal-suffix"
],

LINKFLAGS=[
Expand Down Expand Up @@ -103,62 +104,112 @@

LIBS=[
"cirom", "crypto", "driver", "espconn", "espnow", "freertos", "gcc",
"json", "hal", "lwip", "main", "mesh", "mirom", "net80211", "nopoll",
"json", "hal", "lwip", "main", "mbedtls", "mesh", "mirom", "net80211", "nopoll",
"phy", "pp", "pwm", "smartconfig", "spiffs", "ssl", "wpa", "wps"
],

BUILDERS=dict(
ElfToBin=Builder(
action=env.VerboseAction(" ".join([
'"%s"' % join(platform.get_package_dir("tool-esptool"), "esptool"),
"-eo", "$SOURCE",
"-bo", "${TARGET}",
"-bm", "$BOARD_FLASH_MODE",
"-bf", "${__get_board_f_flash(__env__)}",
"-bz", "${__get_flash_size(__env__)}",
"-bs", ".text",
"-bs", ".data",
"-bs", ".rodata",
"-bc", "-ec",
"-eo", "$SOURCE",
"-es", ".irom0.text", "${TARGET}.irom0text.bin",
"-ec", "-v"
]), "Building $TARGET"),
suffix=".bin"
)
)
]
)

if not env.BoardConfig().get("build.ldscript", ""):
env.Replace(
LDSCRIPT_PATH=join(FRAMEWORK_DIR, "ld", "eagle.app.v6.ld"),
)

# Extra flash images
board_flash_size = int(env.BoardConfig().get("upload.maximum_size", 0))
if board_flash_size > 8388608:
init_data_flash_address = 0xffc000 # for 16 MB
elif board_flash_size > 4194304:
init_data_flash_address = 0x7fc000 # for 8 MB
elif board_flash_size > 2097152:
init_data_flash_address = 0x3fc000 # for 4 MB
elif board_flash_size > 1048576:
init_data_flash_address = 0x1fc000 # for 2 MB
elif board_flash_size > 524288:
init_data_flash_address = 0xfc000 # for 1 MB
else:
init_data_flash_address = 0x7c000 # for 512 kB
###################################################################################
# common code between esp8266-nonos-sdk and esp8266-rtos-sdk for OTA support

# choose LDSCRIPT_PATH based on OTA
if not env.BoardConfig().get("build.ldscript", ""):
if "ota" in BUILD_TARGETS: # flash map size >= 5 only!!!
LDSCRIPT_PATH=join(FRAMEWORK_DIR, "ld", "eagle.app.v6.new.2048.ld")
else:
LDSCRIPT_PATH=join(FRAMEWORK_DIR, "ld", "eagle.app.v6.ld")
env.Replace(LDSCRIPT_PATH=LDSCRIPT_PATH)


# evaluate SPI_FLASH_SIZE_MAP flag for NONOS_SDK 3.x and set CCFLAG
board_flash_size = int(env.BoardConfig().get("upload.maximum_size", 524288))
flash_size_maps = [0.5, 0.25, 1.0, 0.0, 0.0, 2.0, 4.0, 0.0, 8.0, 16.0] # ignore maps 3 and 4.prefer 5 and 6
flash_sizes_str = ['512KB','256KB','1MB','2MB','4MB','2MB-c1','4MB-c1','4MB-c2','8MB','16MB']
try:
flash_size_map = flash_size_maps.index(board_flash_size/1048576)
flash_size_str = flash_sizes_str[flash_size_map]
except:
flash_size_map = 6
flash_size_str = '4MB-c1'
# for OTA, only size maps 5, 6, 8 and 9 are supported to avoid linking twice for user1 and user2

env.Append(CCFLAGS=["-DSPI_FLASH_SIZE_MAP="+str(flash_size_map)]) # NONOS-SDK 3.x user_main.c need it
env.Append(FLASH_SIZE_STR=flash_size_str) # required for custom uploader


# create binaries list to upload

if "ota" in BUILD_TARGETS: # if OTA, flash user1 but generate user1 and user2
boot_bin = join(FRAMEWORK_DIR, "bin", "boot_v1.7.bin")
user_bin = join("$BUILD_DIR", "${PROGNAME}.bin.user1.bin") # firmware.bin.user1.bin # user1.4096.new.6.bin
user_addr = 0x1000
else: # non ota
boot_bin = join("$BUILD_DIR", "${PROGNAME}.bin") # firmware.bin # eagle.flash.bin
user_bin = join("$BUILD_DIR", "${PROGNAME}.bin.irom0text.bin") # firmware.bin.irom0text.bin # eagle.irom0text.bin
if (env['PIOFRAMEWORK'][0] == "esp8266-rtos-sdk"):
user_addr = 0x20000
else:
user_addr = 0x10000

# check the init_data_default file to use
esp_init_data_default_file = "esp_init_data_default_v08.bin" # new in NONOS 3.04
if not isfile(join(FRAMEWORK_DIR, "bin", esp_init_data_default_file)):
esp_init_data_default_file = "esp_init_data_default.bin"

data_bin = join(FRAMEWORK_DIR, "bin", esp_init_data_default_file)
blank_bin = join(FRAMEWORK_DIR, "bin", "blank.bin")
rf_cal_addr = board_flash_size-0x5000 # 3fb000 for 4M board blank_bin
phy_data_addr = board_flash_size-0x4000 # 3fc000 for 4M board data_bin
sys_param_addr = board_flash_size-0x2000 # 3fe000 for 4M board blank_bin

env.Append(
FLASH_EXTRA_IMAGES=[
("0x20000", join("$BUILD_DIR", "${PROGNAME}.bin.irom0text.bin")),
(hex(init_data_flash_address),
join(FRAMEWORK_DIR, "bin", "esp_init_data_default.bin")),
(hex(init_data_flash_address + 0x2000),
join(FRAMEWORK_DIR, "bin", "blank.bin"))
(hex(0), boot_bin),
(hex(user_addr), user_bin),
(hex(phy_data_addr), data_bin),
(hex(sys_param_addr), blank_bin),
(hex(rf_cal_addr), blank_bin),
("--flash_mode", "$BOARD_FLASH_MODE"),
("--flash_freq", "$${__get_board_f_flash(__env__)}m"),
("--flash_size", "$FLASH_SIZE_STR") # required by NONOS 3.0.4
]
)

# register genbin.py BUILDER which allows to create OTA files
if "ota" in BUILD_TARGETS: # if OTA, flash user1 but generate user1 and user2
env.Append(
BUILDERS=dict(
ElfToBin=Builder(
action=env.VerboseAction(" ".join([
'"%s"' % env.subst("$PYTHONEXE"), join(platform.get_package_dir("tool-genbin"), "genbin.py"),
"12", # create firmware.bin.user1.bin and firmware.bin.user2.bin
"$BOARD_FLASH_MODE", "${__get_board_f_flash(__env__)}m", "$FLASH_SIZE_STR",
"$SOURCE", "${TARGET}.user1.bin", "${TARGET}.user2.bin"
# could have used espressif naming: user1.4096.new.6.bin or user1.16384.new.9.bin
]), "Building $TARGET"),
suffix=".bin"
)
)
)
else:
env.Append(
BUILDERS=dict(
ElfToBin=Builder(
action=env.VerboseAction(" ".join([
'"%s"' % env.subst("$PYTHONEXE"), join(platform.get_package_dir("tool-genbin"), "genbin.py"),
"0", # create firmware.bin and firmware.bin.irom0text.bin
"$BOARD_FLASH_MODE", "${__get_board_f_flash(__env__)}m", "$FLASH_SIZE_STR",
"$SOURCE", "${TARGET}", "${TARGET}.irom0text.bin"
]), "Building $TARGET"),
suffix=".bin"
)
)
)

###################################################################################


#
# Target: Build Driver Library
#
Expand Down
Loading