diff --git a/bootloader/Makefile b/bootloader/Makefile index 64a0ebc..1928d01 100644 --- a/bootloader/Makefile +++ b/bootloader/Makefile @@ -1,34 +1,17 @@ # This is a wrapper around the rboot makefile, which gives us the parameters -# we need to use rboot with esp-open-rtos +# we need to use rboot with esp-open-rtos. +# +# Use 'make bootloader' to build a custom bootloader. +# +# 'make flash' for any esp-open-rtos program will use the compiled +# bootloader if it exists, or a prebuilt bootloader if no custom +# bootloader was compiled. # # The wrapper means we don't require esptool2 in the build process, so we can just use # esptool.py (still need xxd, grep, sed to generate the header - see below.) +BOOTLOADER_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST)))) -BUILD_DIR ?= build -FIRMWARE_DIR ?= firmware - -# RBOOT configuration parameters. -# RBOOT_BIG_FLASH is required for esp-open-rtos. -export RBOOT_BIG_FLASH = 1 - -export RBOOT_BUILD_BASE=$(abspath $(BUILD_DIR)) - -# Default ESPTOOL params, all the same as when using normal esp-open-rtos makefiles -ESPTOOL ?= esptool.py -ESPPORT ?= /dev/ttyUSB0 -ESPBAUD ?= 115200 - -FLASH_SIZE ?= 16 -FLASH_MODE ?= qio -FLASH_SPEED ?= 40 - -ESPTOOL_ARGS=-fs $(FLASH_SIZE)m -fm $(FLASH_MODE) -ff $(FLASH_SPEED)m - -ifeq ("$(V)","1") -Q := -else -Q := @ -endif +include ../parameters.mk all: $(FIRMWARE_DIR)/rboot.bin @@ -52,14 +35,19 @@ $(BUILD_DIR)/rboot-hex2a.h: $(BUILD_DIR)/rboot-stage2a.elf $(BUILD_DIR) $(Q) echo "const uint32 _text_addr = 0x$$(xtensa-lx106-elf-objdump -h -j .text $< | grep ".text" | grep -o '401.....' | head -n1);" >> $@.in $(Q) mv $@.in $@ + +RBOOT_BUILD_BASE="$(abspath $(BUILD_DIR))" +RBOOT_FW_BASE="$(abspath $(FIRMWARE_DIR))" +MAKE_VARS=RBOOT_EXTRA_INCDIR=$(BOOTLOADER_DIR) RBOOT_BUILD_BASE=$(RBOOT_BUILD_BASE) RBOOT_FW_BASE=$(RBOOT_FW_BASE) + $(BUILD_DIR)/rboot-stage2a.elf: $(BUILD_DIR) - $(Q) $(MAKE) -C rboot $(RBOOT_BUILD_BASE)/rboot-stage2a.elf + $(Q) $(MAKE) -C rboot $(RBOOT_BUILD_BASE)/rboot-stage2a.elf $(MAKE_VARS) $(BUILD_DIR)/rboot.elf: $(BUILD_DIR)/rboot-hex2a.h - $(Q) $(MAKE) -C rboot $(RBOOT_BUILD_BASE)/rboot.elf + $(Q) $(MAKE) -C rboot $(RBOOT_BUILD_BASE)/rboot.elf $(MAKE_VARS) $(BUILD_DIR) $(FIRMWARE_DIR): - $(Q) mkdir -p "$@" + mkdir -p $@ flash: $(FIRMWARE_DIR)/rboot.bin $(Q) $(ESPTOOL) -p $(ESPPORT) -b $(ESPBAUD) write_flash $(ESPTOOL_ARGS) 0x0 $< @@ -68,4 +56,4 @@ clean: $(Q) rm -rf $(BUILD_DIR) $(Q) rm -rf $(FIRMWARE_DIR) -.PHONY: all clean flash erase_config +.PHONY: all diff --git a/bootloader/README.md b/bootloader/README.md index 6527dba..710205b 100644 --- a/bootloader/README.md +++ b/bootloader/README.md @@ -1,11 +1,12 @@ OTA Bootloader (rboot) source module and support files. -Can be used to build an esp-open-rtos compatible rboot bootloader, for use when OTA=1. - -It is also possible to use the upstream rboot verbatim, but *ensure that the `RBOOT_BIG_FLASH` option is enabled or images in slots other than 0 won't work correctly. - rboot is an open source bootloader by Richard Burton: https://github.com/raburton/rboot -See the contents of the 'rboot' directory for more information. +Can be used to build an esp-open-rtos compatible rboot bootloader. Run 'make bootloader' in this directory to compile a new bootloader. +Compiling a new bootloader is optional, there's a prebuilt one in the "firmware_prebuilt" directory that will be used if no new bootloader was compiled. + +It is also possible to use rboot from upstream verbatim, but *ensure that the `RBOOT_BIG_FLASH` option is enabled or images in slots other than 0 won't work correctly. + +See the contents of the 'rboot' directory for more information on rboot. diff --git a/bootloader/firmware_prebuilt/blank_config.bin b/bootloader/firmware_prebuilt/blank_config.bin new file mode 100644 index 0000000..e9784eb Binary files /dev/null and b/bootloader/firmware_prebuilt/blank_config.bin differ diff --git a/bootloader/firmware_prebuilt/rboot.bin b/bootloader/firmware_prebuilt/rboot.bin new file mode 100644 index 0000000..6cc646c Binary files /dev/null and b/bootloader/firmware_prebuilt/rboot.bin differ diff --git a/bootloader/rboot b/bootloader/rboot index 4cf6132..30afbaa 160000 --- a/bootloader/rboot +++ b/bootloader/rboot @@ -1 +1 @@ -Subproject commit 4cf6132f6ee624318c04b2a8d9e37da64b7c283c +Subproject commit 30afbaa777e00abf9d7d469fb3345f118c4975c1 diff --git a/bootloader/rboot.h b/bootloader/rboot.h new file mode 100644 index 0000000..9260a64 --- /dev/null +++ b/bootloader/rboot.h @@ -0,0 +1,23 @@ +/* rboot header overrides + + This "wrapper" header contains default values for building rboot + on/for esp-open-rtos. It gets included both when building the + bootloader and when building extras/rboot-ota support. It includes + the default bootloader/rboot/rboot.h header via the gcc + include_next mechanism. +*/ +#ifndef __RBOOT_H__ + +// Big flash support is required for esp-open-rtos (we use 8Mbit +// "slots" only.) +#define BOOT_BIG_FLASH + +// enable 2 way communication between +// rBoot and the user app via the esp rtc data area +#define BOOT_RTC_ENABLED + +// Call 'main' rboot.h to pick up defaults for other parameters +#include_next "rboot.h" + +#endif + diff --git a/common.mk b/common.mk index 73a998d..172fbe2 100644 --- a/common.mk +++ b/common.mk @@ -20,149 +20,7 @@ # assume the 'root' directory (ie top of the tree) is the directory common.mk is in ROOT := $(dir $(lastword $(MAKEFILE_LIST))) -# include optional local overrides at the root level, then in program directory -# -# Create either of these files for local system overrides if possible, -# instead of editing this makefile directly. --include $(ROOT)local.mk --include local.mk - -# Flash size in megabits -# Valid values are same as for esptool.py - 2,4,8,16,32 -FLASH_SIZE ?= 16 - -# Flash mode, valid values are same as for esptool.py - qio,qout,dio.dout -FLASH_MODE ?= qio - -# Flash speed in MHz, valid values are same as for esptool.py - 80, 40, 26, 20 -FLASH_SPEED ?= 40 - -# Output directories to store intermediate compiled files -# relative to the program directory -BUILD_DIR ?= $(PROGRAM_DIR)build/ -FIRMWARE_DIR ?= $(PROGRAM_DIR)firmware/ - -# esptool.py from https://github.com/themadinventor/esptool -ESPTOOL ?= esptool.py -# serial port settings for esptool.py -ESPPORT ?= /dev/ttyUSB0 -ESPBAUD ?= 115200 - -# set this to 0 if you don't need floating point support in printf/scanf -# this will save approx 14.5KB flash space and 448 bytes of statically allocated -# data RAM -# -# NB: Setting the value to 0 requires a recent esptool.py (Feb 2016 / commit ebf02c9) -PRINTF_SCANF_FLOAT_SUPPORT ?= 1 - -# Set OTA to 1 to build an image that supports rBoot OTA bootloader -# -# Requires 16mbit or higher flash sizes, with 8mbit -# images for each OTA "slot" -OTA ?= 0 - -ifeq ($(OTA),1) -# Tell C preprocessor that we're building for OTA -CPPFLAGS = -DOTA -endif - -FLAVOR ?= release # or debug - -# Compiler names, etc. assume gdb -CROSS ?= xtensa-lx106-elf- - -# Path to the filteroutput.py tool -FILTEROUTPUT ?= $(ROOT)/utils/filteroutput.py - -AR = $(CROSS)ar -CC = $(CROSS)gcc -CPP = $(CROSS)cpp -LD = $(CROSS)gcc -NM = $(CROSS)nm -C++ = $(CROSS)g++ -SIZE = $(CROSS)size -OBJCOPY = $(CROSS)objcopy -OBJDUMP = $(CROSS)objdump - -# Source components to compile and link. Each of these are subdirectories -# of the root, with a 'component.mk' file. -COMPONENTS ?= $(EXTRA_COMPONENTS) FreeRTOS lwip core - -# binary esp-iot-rtos SDK libraries to link. These are pre-processed prior to linking. -SDK_LIBS ?= main net80211 phy pp wpa - -# open source libraries linked in -LIBS ?= hal gcc c - -# set to 0 if you want to use the toolchain libc instead of esp-open-rtos newlib -OWN_LIBC ?= 1 - -# Note: you will need a recent esp -ENTRY_SYMBOL ?= call_user_start - -# Set this to zero if you don't want individual function & data sections -# (some code may be slightly slower, linking will be slighty slower, -# but compiled code size will come down a small amount.) -SPLIT_SECTIONS ?= 1 - -# Set this to 1 to have all compiler warnings treated as errors (and stop the -# build). This is recommended whenever you are working on code which will be -# submitted back to the main project, as all submitted code will be expected to -# compile without warnings to be accepted. -WARNINGS_AS_ERRORS ?= 0 - -# Common flags for both C & C++_ -C_CXX_FLAGS ?= -Wall -Wl,-EL -nostdlib $(EXTRA_C_CXX_FLAGS) -# Flags for C only -CFLAGS ?= $(C_CXX_FLAGS) -std=gnu99 $(EXTRA_CFLAGS) -# Flags for C++ only -CXXFLAGS ?= $(C_CXX_FLAGS) -fno-exceptions -fno-rtti $(EXTRA_CXXFLAGS) - -# these aren't technically preprocesor args, but used by all 3 of C, C++, assembler -CPPFLAGS += -mlongcalls -mtext-section-literals - -LDFLAGS = -nostdlib -Wl,--no-check-sections -L$(BUILD_DIR)sdklib -L$(ROOT)lib -u $(ENTRY_SYMBOL) -Wl,-static -Wl,-Map=$(BUILD_DIR)$(PROGRAM).map $(EXTRA_LDFLAGS) - -ifeq ($(WARNINGS_AS_ERRORS),1) - C_CXX_FLAGS += -Werror -endif - -ifeq ($(SPLIT_SECTIONS),1) - C_CXX_FLAGS += -ffunction-sections -fdata-sections - LDFLAGS += -Wl,-gc-sections -endif - -ifeq ($(FLAVOR),debug) - C_CXX_FLAGS += -g -O0 - LDFLAGS += -g -O0 -else ifeq ($(FLAVOR),sdklike) - # These are flags intended to produce object code as similar as possible to - # the output of the compiler used to build the SDK libs (for comparison of - # disassemblies when coding replacement routines). It is not normally - # intended to be used otherwise. - CFLAGS += -O2 -Os -fno-inline -fno-ipa-cp -fno-toplevel-reorder - LDFLAGS += -O2 -else - C_CXX_FLAGS += -g -O2 - LDFLAGS += -g -O2 -endif - -GITSHORTREV=\"$(shell cd $(ROOT); git rev-parse --short -q HEAD 2> /dev/null)\" -ifeq ($(GITSHORTREV),\"\") - GITSHORTREV="\"(nogit)\"" # (same length as a short git hash) -endif -CPPFLAGS += -DGITSHORTREV=$(GITSHORTREV) - -ifeq ($(OTA),0) -LINKER_SCRIPTS = $(ROOT)ld/nonota.ld -else -LINKER_SCRIPTS = $(ROOT)ld/ota.ld -endif -LINKER_SCRIPTS += $(ROOT)ld/common.ld $(ROOT)ld/rom.ld - -#### -#### no user configurable options below here -#### +include $(ROOT)parameters.mk ifndef PROGRAM $(error "Set the PROGRAM environment variable in your Makefile before including common.mk") @@ -184,20 +42,7 @@ LIB_ARGS = $(addprefix -l,$(LIBS)) PROGRAM_OUT = $(BUILD_DIR)$(PROGRAM).out LDFLAGS += $(addprefix -T,$(LINKER_SCRIPTS)) -# firmware tool arguments -ESPTOOL_ARGS=-fs $(FLASH_SIZE)m -fm $(FLASH_MODE) -ff $(FLASH_SPEED)m - -ifeq ($(OTA),0) -# for non-OTA, we create two different files for uploading into the flash -# these are the names and options to generate them -FW_ADDR_1 = 0x00000 -FW_ADDR_2 = 0x20000 -FW_FILE_1 = $(addprefix $(FIRMWARE_DIR),$(FW_ADDR_1).bin) -FW_FILE_2 = $(addprefix $(FIRMWARE_DIR),$(FW_ADDR_2).bin) -else -# for OTA, it's a single monolithic image -FW_FILE = $(addprefix $(FIRMWARE_DIR),$(PROGRAM)-ota.bin) -endif +FW_FILE = $(addprefix $(FIRMWARE_DIR),$(PROGRAM).bin) # Common include directories, shared across all "components" # components will add their include directories to this argument @@ -223,7 +68,7 @@ Q := @ vecho := @echo endif -.PHONY: all clean debug_print flash flash_bootloader erase_flash +.PHONY: all clean flash erase_flash all: $(PROGRAM_OUT) $(FW_FILE_1) $(FW_FILE_2) $(FW_FILE) @@ -364,17 +209,8 @@ $(FW_FILE): $(PROGRAM_OUT) $(FIRMWARE_DIR) $(vecho) "FW $@" $(Q) $(ESPTOOL) elf2image --version=2 $(ESPTOOL_ARGS) $< -o $(FW_FILE) -ifeq ($(OTA),0) -flash: $(FW_FILE_1) $(FW_FILE_2) - $(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) write_flash $(ESPTOOL_ARGS) $(FW_ADDR_2) $(FW_FILE_2) $(FW_ADDR_1) $(FW_FILE_1) -else flash: $(FW_FILE) - $(vecho) "Flashing OTA image slot 0 (bootloader not updated)" - $(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) write_flash $(ESPTOOL_ARGS) 0x2000 $(FW_FILE) -endif - -flash_bootloader: - $(MAKE) -C $(ROOT)/bootloader flash + $(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) write_flash $(ESPTOOL_ARGS) 0x0 $(RBOOT_BIN) 0x1000 $(RBOOT_CONF) 0x2000 $(FW_FILE) erase_flash: $(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) erase_flash diff --git a/core/spiflash-cache-enable.S b/core/spiflash-cache-enable.S index 2363a98..3e06f4a 100644 --- a/core/spiflash-cache-enable.S +++ b/core/spiflash-cache-enable.S @@ -12,8 +12,6 @@ * Copyright (C) 2015 Superhouse Automation Pty Ltd * BSD Licensed as described in the file LICENSE */ -#ifdef OTA - #define RBOOT_CONFIG_BASE (0x40200000 + 0x1000) #define RBOOT_ROMS_OFFS 0x8 /* offset of rboot_config_t.roms array in config */ @@ -74,5 +72,3 @@ Cache_Read_Enable: movi a0, cache_return_save /* restore a0 return address */ l32i a0, a0, 0 ret.n - -#endif diff --git a/examples/ota_basic/Makefile b/examples/ota_basic/Makefile index aafb05a..3f2ea5a 100644 --- a/examples/ota_basic/Makefile +++ b/examples/ota_basic/Makefile @@ -1,5 +1,4 @@ PROGRAM=ota_basic -OTA=1 EXTRA_COMPONENTS=extras/rboot-ota extras/mbedtls include ../../common.mk diff --git a/examples/ota_basic/ota_basic.c b/examples/ota_basic/ota_basic.c index 68e6c71..9ab3f20 100644 --- a/examples/ota_basic/ota_basic.c +++ b/examples/ota_basic/ota_basic.c @@ -16,7 +16,6 @@ #include "mbedtls/sha256.h" #include "ota-tftp.h" -#include "rboot.h" #include "rboot-api.h" #define TFTP_IMAGE_SERVER "192.168.1.23" diff --git a/extras/rboot-ota/component.mk b/extras/rboot-ota/component.mk index 690b7bc..62cf14f 100644 --- a/extras/rboot-ota/component.mk +++ b/extras/rboot-ota/component.mk @@ -1,8 +1,9 @@ # Component makefile for extras/rboot-ota -INC_DIRS += $(rboot-ota_ROOT) +# global include directories need to find rboot.h for integration, even +# when just including rboot-api.h :( +INC_DIRS += $(rboot-ota_ROOT) $(ROOT)bootloader $(ROOT)bootloader/rboot -# args for passing into compile rule generation rboot-ota_SRC_DIR = $(rboot-ota_ROOT) $(eval $(call component_compile_rules,rboot-ota)) diff --git a/extras/rboot-ota/ota-tftp.c b/extras/rboot-ota/ota-tftp.c index 1dee8cd..b6472a3 100644 --- a/extras/rboot-ota/ota-tftp.c +++ b/extras/rboot-ota/ota-tftp.c @@ -22,7 +22,6 @@ #include #include "ota-tftp.h" -#include "rboot.h" #include "rboot-api.h" #define TFTP_FIRMWARE_FILE "firmware.bin" diff --git a/extras/rboot-ota/rboot-api.c b/extras/rboot-ota/rboot-api.c index b3faac2..b9a5e57 100644 --- a/extras/rboot-ota/rboot-api.c +++ b/extras/rboot-ota/rboot-api.c @@ -8,7 +8,7 @@ // esp-open-rtos additions Copyright 2016 Angus Gratton ////////////////////////////////////////////////// -#include +#include #include //#include //#include diff --git a/extras/rboot-ota/rboot-api.h b/extras/rboot-ota/rboot-api.h index a74eeb2..29c11bd 100644 --- a/extras/rboot-ota/rboot-api.h +++ b/extras/rboot-ota/rboot-api.h @@ -12,6 +12,7 @@ * @{ */ +#include #include #ifdef __cplusplus diff --git a/extras/rboot-ota/rboot-integration.h b/extras/rboot-ota/rboot-integration.h index 064217b..005e9ea 100644 --- a/extras/rboot-ota/rboot-integration.h +++ b/extras/rboot-ota/rboot-integration.h @@ -9,6 +9,10 @@ #include #include +/*************************************************** + * Platform configuration definitions * + ***************************************************/ + #define uint8 uint8_t #define uint16 uint16_t #define uint32 uint32_t diff --git a/extras/rboot-ota/rboot.h b/extras/rboot-ota/rboot.h deleted file mode 100644 index 750c4d7..0000000 --- a/extras/rboot-ota/rboot.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef __RBOOT_H__ -#define __RBOOT_H__ - -////////////////////////////////////////////////// -// rBoot open source boot loader for ESP8266. -// Copyright 2015 Richard A Burton -// richardaburton@gmail.com -// See license.txt for license terms. -////////////////////////////////////////////////// - -#ifdef __cplusplus -extern "C" { -#endif - -#define RBOOT_INTEGRATION - -// uncomment to use only c code -// if you aren't using gcc you may need to do this -//#define BOOT_NO_ASM - -// Note: enabling RBOOT_CONFIG_CHECKSUM here means the config sector -// is always written by esp-open-rtos with a checksum. -// -// This means it will work whether the bootloader has config -// checksumming enabled or not. - -#define BOOT_CONFIG_CHKSUM - -// uncomment to enable big flash support (>1MB) -#define BOOT_BIG_FLASH - -// uncomment to enable 2 way communication between -// rBoot and the user app via the esp rtc data area -#define BOOT_RTC_ENABLED - -// uncomment to enable GPIO booting -//#define BOOT_GPIO_ENABLED - -// uncomment to include .irom0.text section in the checksum -// roms must be built with esptool2 using -iromchksum option -//#define BOOT_IROM_CHKSUM - -// uncomment to add a boot delay, allows you time to connect -// a terminal before rBoot starts to run and output messages -// value is in microseconds -//#define BOOT_DELAY_MICROS 2000000 - -// increase if required -#define MAX_ROMS 4 - -#define CHKSUM_INIT 0xef - -#define SECTOR_SIZE 0x1000 -#define BOOT_CONFIG_SECTOR 1 - -#define BOOT_CONFIG_MAGIC 0xe1 -#define BOOT_CONFIG_VERSION 0x01 - -#define MODE_STANDARD 0x00 -#define MODE_GPIO_ROM 0x01 -#define MODE_TEMP_ROM 0x02 - -#define RBOOT_RTC_MAGIC 0x2334ae68 -#define RBOOT_RTC_READ 1 -#define RBOOT_RTC_WRITE 0 -#define RBOOT_RTC_ADDR 64 - -#ifdef RBOOT_INTEGRATION -#include -#endif - -/** @brief Structure containing rBoot configuration - * @note ROM addresses must be multiples of 0x1000 (flash sector aligned). - * Without BOOT_BIG_FLASH only the first 8Mbit (1MB) of the chip will - * be memory mapped so ROM slots containing .irom0.text sections must - * remain below 0x100000. Slots beyond this will only be accessible via - * spi read calls, so use these for stored resources, not code. With - * BOOT_BIG_FLASH the flash will be mapped in chunks of 8MBit (1MB), so - * ROMs can be anywhere, but must not straddle two 8MBit (1MB) blocks. - * @ingroup rboot -*/ -typedef struct { - uint8 magic; ///< Our magic, identifies rBoot configuration - should be BOOT_CONFIG_MAGIC - uint8 version; ///< Version of configuration structure - should be BOOT_CONFIG_VERSION - uint8 mode; ///< Boot loader mode (MODE_STANDARD | MODE_GPIO_ROM) - uint8 current_rom; ///< Currently selected ROM (will be used for next standard boot) - uint8 gpio_rom; ///< ROM to use for GPIO boot (hardware switch) with mode set to MODE_GPIO_ROM - uint8 count; ///< Quantity of ROMs available to boot - uint8 unused[2]; ///< Padding (not used) - uint32 roms[MAX_ROMS]; ///< Flash addresses of each ROM -#ifdef BOOT_CONFIG_CHKSUM - uint8 chksum; ///< Checksum of this configuration structure (if BOOT_CONFIG_CHKSUM defined) -#endif -} rboot_config; - -#ifdef BOOT_RTC_ENABLED -/** @brief Structure containing rBoot status/control data - * @note This structure is used to, optionally, communicate between rBoot and - * the user app. It is stored in the ESP RTC data area. - * @ingroup rboot -*/ -typedef struct { - uint32 magic; ///< Magic, identifies rBoot RTC data - should be RBOOT_RTC_MAGIC - uint8 next_mode; ///< The next boot mode, defaults to MODE_STANDARD - can be set to MODE_TEMP_ROM - uint8 last_mode; ///< The last (this) boot mode - can be MODE_STANDARD, MODE_GPIO_ROM or MODE_TEMP_ROM - uint8 last_rom; ///< The last (this) boot rom number - uint8 temp_rom; ///< The next boot rom number when next_mode set to MODE_TEMP_ROM - uint8 chksum; ///< Checksum of this structure this will be updated for you passed to the API -} rboot_rtc_data; -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ld/nonota.ld b/ld/nonota.ld deleted file mode 100644 index 97054e6..0000000 --- a/ld/nonota.ld +++ /dev/null @@ -1,15 +0,0 @@ -/* Memory layout for esp-open-rtos when not using OTA - (ie ROM bootloader only, no second stage rboot) - */ -MEMORY -{ - dport0_0_seg : org = 0x3FF00000, len = 0x10 - dram0_0_seg : org = 0x3FFE8000, len = 0x14000 - iram1_0_seg : org = 0x40100000, len = 0x08000 -/* irom0 section, mapped from SPI flash - - Origin is offset by 0x20000 to leave space for bootloader RAM sections. - - - Length is max 8Mbit of mappable flash, minus start offset -*/ - irom0_0_seg : org = 0x40220000, len = (1M - 0x20000) -} diff --git a/ld/ota.ld b/ld/ota.ld deleted file mode 100644 index da32ce1..0000000 --- a/ld/ota.ld +++ /dev/null @@ -1,15 +0,0 @@ -/* Memory layout for esp-open-rtos when using OTA second stage bootloader */ - -MEMORY -{ - dport0_0_seg : org = 0x3FF00000, len = 0x10 - dram0_0_seg : org = 0x3FFE8000, len = 0x14000 - iram1_0_seg : org = 0x40100000, len = 0x08000 -/* irom0 section, mapped from SPI flash - - Origin is offset by 0x2010 to create spacer for second stage bootloader image, - header. - - - Length is max 8Mbit of mappable flash, minus start offset -*/ - irom0_0_seg : org = 0x40202010, len = (1M - 0x2010) -} diff --git a/ld/common.ld b/ld/program.ld similarity index 93% rename from ld/common.ld rename to ld/program.ld index 444c8e7..88fa0f4 100644 --- a/ld/common.ld +++ b/ld/program.ld @@ -1,7 +1,17 @@ -/* - * Common (OTA and non-OTA) parts for the esp-open-rtos Linker Script - * - */ +/* Memory layout for esp-open-rtos when using OTA second stage bootloader */ +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x08000 +/* irom0 section, mapped from SPI flash + - Origin is offset by 0x2010 to create spacer for second stage bootloader image, + header. + + - Length is max 8Mbit of mappable flash, minus start offset +*/ + irom0_0_seg : org = 0x40202010, len = (1M - 0x2010) +} /* FreeRTOS memory management functions diff --git a/parameters.mk b/parameters.mk new file mode 100644 index 0000000..e750e83 --- /dev/null +++ b/parameters.mk @@ -0,0 +1,141 @@ +# Parameters for the esp-open-rtos make process +# +# You can edit this file to change parameters, but a better option is +# to create a local.mk file and add overrides there. The local.mk file +# can be in the root directory, or the program directory alongside the +# Makefile, or both. +# +-include $(ROOT)local.mk +-include local.mk + +# Flash size in megabits +# Valid values are same as for esptool.py - 2,4,8,16,32 +FLASH_SIZE ?= 16 + +# Flash mode, valid values are same as for esptool.py - qio,qout,dio.dout +FLASH_MODE ?= qio + +# Flash speed in MHz, valid values are same as for esptool.py - 80, 40, 26, 20 +FLASH_SPEED ?= 40 + +# Output directories to store intermediate compiled files +# relative to the program directory +BUILD_DIR ?= $(PROGRAM_DIR)build/ +FIRMWARE_DIR ?= $(PROGRAM_DIR)firmware/ + +# esptool.py from https://github.com/themadinventor/esptool +ESPTOOL ?= esptool.py +# serial port settings for esptool.py +ESPPORT ?= /dev/ttyUSB0 +ESPBAUD ?= 115200 + +# firmware tool arguments +ESPTOOL_ARGS=-fs $(FLASH_SIZE)m -fm $(FLASH_MODE) -ff $(FLASH_SPEED)m + + +# set this to 0 if you don't need floating point support in printf/scanf +# this will save approx 14.5KB flash space and 448 bytes of statically allocated +# data RAM +# +# NB: Setting the value to 0 requires a recent esptool.py (Feb 2016 / commit ebf02c9) +PRINTF_SCANF_FLOAT_SUPPORT ?= 1 + +FLAVOR ?= release # or debug + +# Compiler names, etc. assume gdb +CROSS ?= xtensa-lx106-elf- + +# Path to the filteroutput.py tool +FILTEROUTPUT ?= $(ROOT)/utils/filteroutput.py + +AR = $(CROSS)ar +CC = $(CROSS)gcc +CPP = $(CROSS)cpp +LD = $(CROSS)gcc +NM = $(CROSS)nm +C++ = $(CROSS)g++ +SIZE = $(CROSS)size +OBJCOPY = $(CROSS)objcopy +OBJDUMP = $(CROSS)objdump + +# Source components to compile and link. Each of these are subdirectories +# of the root, with a 'component.mk' file. +COMPONENTS ?= $(EXTRA_COMPONENTS) FreeRTOS lwip core + +# binary esp-iot-rtos SDK libraries to link. These are pre-processed prior to linking. +SDK_LIBS ?= main net80211 phy pp wpa + +# open source libraries linked in +LIBS ?= hal gcc c + +# set to 0 if you want to use the toolchain libc instead of esp-open-rtos newlib +OWN_LIBC ?= 1 + +# Note: you will need a recent esp +ENTRY_SYMBOL ?= call_user_start + +# Set this to zero if you don't want individual function & data sections +# (some code may be slightly slower, linking will be slighty slower, +# but compiled code size will come down a small amount.) +SPLIT_SECTIONS ?= 1 + +# Set this to 1 to have all compiler warnings treated as errors (and stop the +# build). This is recommended whenever you are working on code which will be +# submitted back to the main project, as all submitted code will be expected to +# compile without warnings to be accepted. +WARNINGS_AS_ERRORS ?= 0 + +# Common flags for both C & C++_ +C_CXX_FLAGS ?= -Wall -Wl,-EL -nostdlib $(EXTRA_C_CXX_FLAGS) +# Flags for C only +CFLAGS ?= $(C_CXX_FLAGS) -std=gnu99 $(EXTRA_CFLAGS) +# Flags for C++ only +CXXFLAGS ?= $(C_CXX_FLAGS) -fno-exceptions -fno-rtti $(EXTRA_CXXFLAGS) + +# these aren't all technically preprocesor args, but used by all 3 of C, C++, assembler +CPPFLAGS += -mlongcalls -mtext-section-literals + +LDFLAGS = -nostdlib -Wl,--no-check-sections -L$(BUILD_DIR)sdklib -L$(ROOT)lib -u $(ENTRY_SYMBOL) -Wl,-static -Wl,-Map=$(BUILD_DIR)$(PROGRAM).map $(EXTRA_LDFLAGS) + +ifeq ($(WARNINGS_AS_ERRORS),1) + C_CXX_FLAGS += -Werror +endif + +ifeq ($(SPLIT_SECTIONS),1) + C_CXX_FLAGS += -ffunction-sections -fdata-sections + LDFLAGS += -Wl,-gc-sections +endif + +ifeq ($(FLAVOR),debug) + C_CXX_FLAGS += -g -O0 + LDFLAGS += -g -O0 +else ifeq ($(FLAVOR),sdklike) + # These are flags intended to produce object code as similar as possible to + # the output of the compiler used to build the SDK libs (for comparison of + # disassemblies when coding replacement routines). It is not normally + # intended to be used otherwise. + CFLAGS += -O2 -Os -fno-inline -fno-ipa-cp -fno-toplevel-reorder + LDFLAGS += -O2 +else + C_CXX_FLAGS += -g -O2 + LDFLAGS += -g -O2 +endif + +GITSHORTREV=\"$(shell cd $(ROOT); git rev-parse --short -q HEAD 2> /dev/null)\" +ifeq ($(GITSHORTREV),\"\") + GITSHORTREV="\"(nogit)\"" # (same length as a short git hash) +endif +CPPFLAGS += -DGITSHORTREV=$(GITSHORTREV) + +LINKER_SCRIPTS += $(ROOT)ld/program.ld $(ROOT)ld/rom.ld + +# rboot firmware binary paths for flashing +RBOOT_BIN = $(ROOT)bootloader/firmware/rboot.bin +RBOOT_PREBUILT_BIN = $(ROOT)bootloader/firmware_prebuilt/rboot.bin +RBOOT_CONF = $(ROOT)bootloader/firmware_prebuilt/blank_config.bin + +# if a custom bootloader hasn't been compiled, use the +# prebuilt binary from the source tree +ifeq (,$(wildcard $(RBOOT_BIN))) +RBOOT_BIN=$(RBOOT_PREBUILT_BIN) +endif