Get Started
For a long time, no one has been surprised by running Linux on ESP with 8 and 16 MB of memory and RAM. So today we will talk about running Linux on a 4MB platform. And so straight to the point.
Download these packages:
apt install autoconf automake bash bc bison build-essential cmake flex gawk git gperf help2man libncurses-dev libtool libtool-bin libusb-1.0-0 python3 python3-venv rsync texinfo unzip wget cpio
Get dynconfig
git clone https://github.com/jcmvbkbc/xtensa-dynconfig -b original
wget https://github.com/jcmvbkbc/xtensa-toolchain-build/raw/e46089b8418f27ecd895881f071aa192dd7f42b5/overlays/original/esp32.tar.gz
mkdir esp32 && tar -xf esp32.tar.gz -C esp32
sed -i 's/\(XSHAL_ABI\s\+\)XTHAL_ABI_WINDOWED/\1XTHAL_ABI_CALL0/' esp32/{binutils,gcc}/xtensa-config.h
make -C xtensa-dynconfig ORIG=1 CONF_DIR=`pwd` esp32.so
Dont forget to set exports every new shell sessions or add to your shell config file
export XTENSA_GNU_CONFIG=`pwd`/xtensa-dynconfig/esp32.so
Get Toolchain
git clone https://github.com/jcmvbkbc/crosstool-NG.git -b xtensa-fdpic
cd crosstool-NG
./bootstrap && ./configure --enable-local && make
./ct-ng xtensa-esp32-linux-uclibcfdpic
CT_PREFIX=`pwd`/builds nice ./ct-ng build
cd ..
Now you can check your toolchain set in crosstool-NG/builds/xtensa-esp32-linux-uclibcfdpic/bin/
Kernel and Rootfs
For pure ESP32 (4MB) we are using xtensa-2024.05-fdpic version
git clone https://github.com/jcmvbkbc/buildroot -b xtensa-2024.05-fdpic
Time to create buildroot
make -C buildroot O=`pwd`/build-buildroot-esp32 esp32_defconfig
buildroot/utils/config --file build-buildroot-esp32/.config --set-str TOOLCHAIN_EXTERNAL_PATH `pwd`/crosstool-NG/builds/xtensa-esp32-linux-uclibcfdpic
buildroot/utils/config --file build-buildroot-esp32/.config --set-str TOOLCHAIN_EXTERNAL_PREFIX '$(ARCH)-esp32-linux-uclibcfdpic'
buildroot/utils/config --file build-buildroot-esp32/.config --set-str TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX '$(ARCH)-esp32-linux-uclibcfdpic'
nice make -C buildroot O=`pwd`/build-buildroot-esp32
Bootloader
git clone https://github.com/jcmvbkbc/esp-idf -b linux-5.1.2
pushd esp-idf
. ./export.sh
cd examples/get-started/linux_boot
idf.py set-target esp32
cp sdkconfig.defaults.esp32 sdkconfig
idf.py build
As you can see the partitions table looks like:
Flash
idf.py flash
Final Flash
parttool.py -b 1000000 write_partition --partition-name linux --input build-buildroot-esp32/images/xipImage
parttool.py -b 1000000 write_partition --partition-name rootfs --input build-buildroot-esp32/images/rootfs.cramfs
Connect (dont forget to add user in diagout group):
apt install minicom
minicom -b 115200 -D /dev/ttyUSB0
End
Thank you for reading this rather short article. I tried to describe everything to the point.
I also wanted to give a thank you to the author who ported Linux to the xtensa platform specialy ESP.
His github: https://github.com/jcmvbkbc/↗
His scripts to automate build: https://github.com/jcmvbkbc/esp32-linux-build↗