mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
073b2209da
We had four versions of pre-built bootloaders for the esp8266 with different settings of logging and color logging. These bootloaders were manually built from the SDK and shipped with RIOT-OS source code. However there are more settings that affect the bootloader build that are relevant to the app or final board that uses this bootloader. In particular, flash size and flash speed is important for the bootloader to be able to load an app from a large partition table at the fastest speed supported by the board layout and flash chip. Another example is the UART baudrate of the logging output from the bootloader. The boot ROM will normally start at a baud rate of 74880 (depending on the crystal installed), so it might make sense to keep the UART output at the same speed so we can debug boot modes and bootloader with the same terminal. This patch builds the bootloader.bin file from the ESP8266 SDK source code. The code is built as a module (esp8266_bootloader) which at the moment doesn't generate any object code for the application and only produces a bootloader.bin file set to the BOOTLOADER_BIN make variable for the esptool.inc.mk to flash. The code needs to be compiled and linked with custom rules defined in the module's Makefile since the bootloader.bin is its own separate application. The `BOOTLOADER_BIN` variable is changed from a path relative to the `$(RIOTCPU)/$(CPU)/bin/` directory to be full path. This makes it easier for applications or board to provide their own bootloader binary if needed. As a result of building the bootloader from source we fixed the issue of having a large partition table. Fixes #16402.
100 lines
2.9 KiB
Bash
Executable File
100 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Script to update the bootloader.inc.mk file.
|
|
#
|
|
# bootloader.inc.mk contains the list of source files and config options that
|
|
# the vendor SDK uses while building the bootloader. This is generated and
|
|
# included in the RIOT-OS source repository since it requires to have both a
|
|
# native toolchain and esp8266 toolchain configured and it was in general tricky
|
|
# to get to work from RIOT-OS build system.
|
|
|
|
SCRIPTDIR=$(dirname "$(realpath "$0")")
|
|
|
|
set -eu
|
|
|
|
main() {
|
|
if ! which xtensa-esp8266-elf-gcc >/dev/null; then
|
|
echo "Assuming xtensa-esp8266-elf-gcc from /opt/esp/xtensa-esp8266-elf/bin"
|
|
export PATH="/opt/esp/xtensa-esp8266-elf/bin:${PATH}"
|
|
fi
|
|
|
|
local bldr_dir="${SCRIPTDIR}/bldr_build"
|
|
rm -rf "${bldr_dir}"
|
|
mkdir -p "${bldr_dir}"
|
|
cd "${bldr_dir}"
|
|
|
|
local sdk_path
|
|
sdk_path=$(realpath "${SCRIPTDIR}/../../../build/pkg/esp8266_sdk")
|
|
if [[ ! -e "${sdk_path}/Kconfig" ]]; then
|
|
echo "Download the ESP8266 RTOS SDK to ${sdk_path} by building RIOT first"
|
|
exit 1
|
|
fi
|
|
|
|
# Builds the bootloader.bin with the default config into the bldr_build
|
|
PROJECT_NAME=bootloader PROJECT_PATH="${bldr_dir}" \
|
|
make \
|
|
-f "${sdk_path}/make/project.mk" IDF_PATH="${sdk_path}" \
|
|
CONFIG_TOOLPREFIX=xtensa-esp8266-elf- \
|
|
defconfig bootloader -j
|
|
|
|
# List of all the sources and headers used by the build except the generated
|
|
# sdkconfig.h.
|
|
local bootloader_srcs
|
|
bootloader_srcs=(
|
|
$(find . -name '*.d' -print0 | xargs -0 cat | tr ' ' '\n' |
|
|
grep -E '^/[^ ]+\.[ch]$' -o | xargs -I {} realpath {} |
|
|
grep -v -F /sdkconfig.h | sort | uniq))
|
|
|
|
(
|
|
echo "# Generated by ./update_mk.sh, don't modify directly."
|
|
echo
|
|
# List of source files (.c)
|
|
echo "ESP_SDK_BOOTLOADER_SRCS = \\"
|
|
local src
|
|
for src in "${bootloader_srcs[@]}"; do
|
|
if [[ "${src%.c}" != "${src}" ]]; then
|
|
echo " ${src#${sdk_path}/} \\"
|
|
fi
|
|
done
|
|
echo " #"
|
|
) >"${SCRIPTDIR}/bootloader.inc.mk"
|
|
|
|
# List of the relevant CONFIG_ settings used by those files.
|
|
local configs
|
|
configs=(
|
|
$(grep -h -o -E '\bCONFIG_[A-Z0-9_]+\b' "${bootloader_srcs[@]}" |
|
|
sort | uniq))
|
|
|
|
(
|
|
echo "/*"
|
|
echo " * Generated by ./update_mk.sh, don't modify directly."
|
|
echo " * Default CONFIG_ parameters from the SDK package."
|
|
echo " */"
|
|
echo
|
|
echo "#ifndef SDKCONFIG_DEFAULT_H"
|
|
echo "#define SDKCONFIG_DEFAULT_H"
|
|
echo
|
|
echo "#ifdef __cplusplus"
|
|
echo "extern \"C\" {"
|
|
echo "#endif"
|
|
echo
|
|
# Only list those configs not in the bootloader sdkconfig.h included in
|
|
# RIOT-OS.
|
|
local conf
|
|
for conf in "${configs[@]}"; do
|
|
grep -F "#define ${conf} " "${SCRIPTDIR}/sdkconfig.h" >/dev/null ||
|
|
grep -F "#define ${conf} " "${bldr_dir}/build/include/sdkconfig.h" || true
|
|
done
|
|
echo
|
|
echo "#ifdef __cplusplus"
|
|
echo "}"
|
|
echo "#endif"
|
|
echo
|
|
echo "#endif /* SDKCONFIG_DEFAULT_H */"
|
|
) >"${SCRIPTDIR}/sdkconfig_default.h"
|
|
|
|
echo "Done."
|
|
}
|
|
|
|
main "$@"
|