|
| 1 | +#! /bin/bash -x |
| 2 | + |
| 3 | +# |
| 4 | +# environment variables affecting the build: |
| 5 | +# |
| 6 | +# keep_toolchain=y -- don't rebuild the toolchain, but rebuild everything else |
| 7 | +# keep_rootfs=y -- don't reconfigure or rebuild rootfs from scratch. Would still apply overlay changes |
| 8 | +# keep_buildroot=y -- don't redownload the buildroot, only git pull any updates into it |
| 9 | +# keep_bootloader=y -- don't redownload the bootloader, only rebuild it |
| 10 | +# keep_etc=y -- don't overwrite the /etc partition |
| 11 | +# |
| 12 | + |
| 13 | +SET_BAUDRATE='-b 1000000' |
| 14 | + |
| 15 | +CTNG_VER=xtensa-fdpic |
| 16 | +CTNG_CONFIG=xtensa-esp32-linux-uclibcfdpic |
| 17 | +BUILDROOT_VER=xtensa-2023.11-fdpic |
| 18 | +BUILDROOT_CONFIG=esp32_defconfig |
| 19 | +ESP_BOOTLOADER_VER=linux-5.1.2 |
| 20 | +ESP_BOOTLOADER_CONFIG=sdkconfig.defaults.esp32 |
| 21 | + |
| 22 | +if [ ! -d autoconf-2.71/root/bin ] ; then |
| 23 | + wget https://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.xz |
| 24 | + tar -xf autoconf-2.71.tar.xz |
| 25 | + pushd autoconf-2.71 |
| 26 | + ./configure --prefix=`pwd`/root |
| 27 | + make && make install |
| 28 | + popd |
| 29 | +fi |
| 30 | +export PATH=`pwd`/autoconf-2.71/root/bin:$PATH |
| 31 | + |
| 32 | +if [ -z "$keep_toolchain$keep_buildroot$keep_rootfs$keep_bootloader" ] ; then |
| 33 | + rm -rf build |
| 34 | +else |
| 35 | + [ -n "$keep_rootfs" ] || rm -rf build/build-buildroot-esp32 |
| 36 | + [ -n "$keep_buildroot" ] || rm -rf build/buildroot |
| 37 | + [ -n "$keep_bootloader" ] || rm -rf build/esp-idf |
| 38 | +fi |
| 39 | +mkdir -p build |
| 40 | +cd build |
| 41 | + |
| 42 | +# |
| 43 | +# dynconfig |
| 44 | +# |
| 45 | +if [ ! -f xtensa-dynconfig/esp32.so ] ; then |
| 46 | + git clone https://github.com/jcmvbkbc/xtensa-dynconfig -b original |
| 47 | + wget https://github.com/jcmvbkbc/xtensa-toolchain-build/raw/e46089b8418f27ecd895881f071aa192dd7f42b5/overlays/original/esp32.tar.gz |
| 48 | + mkdir esp32 |
| 49 | + tar -xf esp32.tar.gz -C esp32 |
| 50 | + sed -i 's/\(XSHAL_ABI\s\+\)XTHAL_ABI_WINDOWED/\1XTHAL_ABI_CALL0/' esp32/{binutils,gcc}/xtensa-config.h |
| 51 | + make -C xtensa-dynconfig ORIG=1 CONF_DIR=`pwd` esp32.so |
| 52 | +fi |
| 53 | +export XTENSA_GNU_CONFIG=`pwd`/xtensa-dynconfig/esp32.so |
| 54 | + |
| 55 | +# |
| 56 | +# toolchain |
| 57 | +# |
| 58 | +if [ ! -x crosstool-NG/builds/xtensa-esp32-linux-uclibcfdpic/bin/xtensa-esp32-linux-uclibcfdpic-gcc ] ; then |
| 59 | + git clone https://github.com/jcmvbkbc/crosstool-NG.git -b $CTNG_VER |
| 60 | + pushd crosstool-NG |
| 61 | + ./bootstrap && ./configure --enable-local && make |
| 62 | + ./ct-ng $CTNG_CONFIG |
| 63 | + CT_PREFIX=`pwd`/builds nice ./ct-ng build |
| 64 | + popd |
| 65 | + [ -x crosstool-NG/builds/xtensa-esp32-linux-uclibcfdpic/bin/xtensa-esp32-linux-uclibcfdpic-gcc ] || exit 1 |
| 66 | +fi |
| 67 | + |
| 68 | +# |
| 69 | +# kernel and rootfs |
| 70 | +# |
| 71 | +if [ ! -d buildroot ] ; then |
| 72 | + git clone https://github.com/jcmvbkbc/buildroot -b $BUILDROOT_VER |
| 73 | +else |
| 74 | + pushd buildroot |
| 75 | + git pull |
| 76 | + popd |
| 77 | +fi |
| 78 | +if [ ! -d build-buildroot-esp32 ] ; then |
| 79 | + nice make -C buildroot O=`pwd`/build-buildroot-esp32 $BUILDROOT_CONFIG |
| 80 | + buildroot/utils/config --file build-buildroot-esp32/.config --set-str TOOLCHAIN_EXTERNAL_PATH `pwd`/crosstool-NG/builds/xtensa-esp32-linux-uclibcfdpic |
| 81 | + buildroot/utils/config --file build-buildroot-esp32/.config --set-str TOOLCHAIN_EXTERNAL_PREFIX '$(ARCH)-esp32-linux-uclibcfdpic' |
| 82 | + buildroot/utils/config --file build-buildroot-esp32/.config --set-str TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX '$(ARCH)-esp32-linux-uclibcfdpic' |
| 83 | +fi |
| 84 | +nice make -C buildroot O=`pwd`/build-buildroot-esp32 |
| 85 | +[ -f build-buildroot-esp32/images/xipImage -a -f build-buildroot-esp32/images/rootfs.cramfs -a -f build-buildroot-esp32/images/etc.jffs2 ] || exit 1 |
| 86 | + |
| 87 | +# |
| 88 | +# bootloader |
| 89 | +# |
| 90 | +[ -d esp-idf ] || git clone https://github.com/jcmvbkbc/esp-idf -b $ESP_BOOTLOADER_VER |
| 91 | +pushd esp-idf |
| 92 | +. export.sh |
| 93 | +cd examples/get-started/linux_boot |
| 94 | +idf.py set-target esp32 |
| 95 | +cp $ESP_BOOTLOADER_CONFIG sdkconfig |
| 96 | +idf.py build |
| 97 | +read -p 'ready to flash... press enter' |
| 98 | +while ! idf.py $SET_BAUDRATE flash ; do |
| 99 | + read -p 'failure... press enter to try again' |
| 100 | +done |
| 101 | +popd |
| 102 | + |
| 103 | +# |
| 104 | +# flash |
| 105 | +# |
| 106 | +parttool.py $SET_BAUDRATE write_partition --partition-name linux --input build-buildroot-esp32/images/xipImage |
| 107 | +parttool.py $SET_BAUDRATE write_partition --partition-name rootfs --input build-buildroot-esp32/images/rootfs.cramfs |
0 commit comments