Open Source & Linux Lab

It's better when it's simple

User Tools

Site Tools


etc:users:jcmvbkbc:linux-xtensa:esp32s3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
etc:users:jcmvbkbc:linux-xtensa:esp32s3 [2023/05/24 16:41] jcmvbkbcetc:users:jcmvbkbc:linux-xtensa:esp32s3 [2024/03/15 21:07] (current) jcmvbkbc
Line 5: Line 5:
   * https://github.com/jcmvbkbc/config-esp32s3   * https://github.com/jcmvbkbc/config-esp32s3
   * https://github.com/jcmvbkbc/esp-idf/tree/linux-5.0.1   * https://github.com/jcmvbkbc/esp-idf/tree/linux-5.0.1
-  * https://github.com/jcmvbkbc/linux-xtensa/tree/xtensa-6.4-esp32 +  * https://github.com/jcmvbkbc/linux-xtensa/tree/xtensa-6.7-esp32 
-  * https://github.com/jcmvbkbc/binutils-gdb-xtensa/tree/xtensa-2.40-fdpic +  * https://github.com/jcmvbkbc/binutils-gdb-xtensa/tree/xtensa-2.41-fdpic 
-  * https://github.com/jcmvbkbc/gcc-xtensa/tree/xtensa-14-fdpic +  * https://github.com/jcmvbkbc/gcc-xtensa/tree/xtensa-14-4992-fdpic 
-  * https://github.com/jcmvbkbc/uclibc-ng-xtensa/tree/xtensa-fdpic +  * https://github.com/jcmvbkbc/uclibc-ng-xtensa/tree/xtensa-1.0.44-fdpic 
-  * https://github.com/jcmvbkbc/buildroot/tree/xtensa-2023.02-fdpic+  * https://github.com/jcmvbkbc/buildroot/tree/xtensa-2023.11-fdpic
   * https://github.com/jcmvbkbc/crosstool-NG/tree/xtensa-fdpic   * https://github.com/jcmvbkbc/crosstool-NG/tree/xtensa-fdpic
  
-Example kernel and rootfs images built from the above sources as well as a toolchain archivehttp://jcmvbkbc.spb.ru/~dumb/tmp/202305161729/+Scripts with all steps below: https://github.com/jcmvbkbc/esp32-linux-build 
 + 
 +===== Details ===== 
 + 
 +  * [[.:esp32s3:flash]] 
 +  * [[.:esp32s3:gpio]] 
 +  * [[.:esp32s3:linux-ipc]] 
 +  * [[.:esp32s3:mmu]] 
 +  * [[.:esp32s3:wifi]] 
 + 
 +===== Things that work ===== 
 + 
 +  * WiFi. Use the script that builds firmware based on esp-hosted. It runs on core 0, linux runs on core 1, special linux IPC is used for communication. WiFi transport that uses linux IPC is added both to the firmware and to the linux kernel wifi driver. Not all wifi security options may be working, e.g. open and wpa2-psk are working and 802.11w is not. 
 +  * Writing to FLASH and using ESP FLASH partition table. Driver based on linux IPC sends FLASH-related requests to the firmware. Default configuration has an etc partition that is flashed with /etc file system and mounted at boot time. The file system is writable and it can be used to store things like wpa_supplicant.conf, /etc/passwd, /etc/shadow, ... 
 +  * USB serial. It is visible as the /dev/ttyACM1 (in kernels based on v6.5) or the /dev/ttyGS3 (in kernels based on v6.6-rc and newer) device inside the linux environment. (The change of name was requested by the linux TTY subsystem maintainer, the change of number is to keep UART ports numbering coherent with esp32s3 TRM). 
 +  * GPIO, including interrupts. Software I2C over GPIO and software SPI over GPIO. 
 +  * hardware SPI. Tested clock speed up to 20MHz with SD card. 
 +  * clock frequency detection. CPU, XTAL and APB clocks may be preset by the bootloader, the kernel will understand and use preset frequencies without additional configuration. 
 +  * ssh server and ssh client. There's an issue using scp from openssh version 9 because that version switched from the original scp protocol to sftp. The option -O makes it use the now legacy scp. 
 +  * mounting NFS shares. 
 +  * running executable code from outside the rootfs, e.g. from /etc or from NFS mounts. A special hack in the kernel code does address remapping, so that when an executable memory mapping is created, the mapping address points to the PSRAM alias in the IRAM address range. This does not work for ESP32 as it doesn't have executable mappings of PSRAM. 
 +  * passing command line from bootloader to the kernel. Bootloader reads the file /etc/cmdline if it exists and passes its contents to the kernel as the command line. The bootloader does JFFS2 file system parsing for that. E.g. the following line can be used to move console to the USB serial<code>earlycon=esp32s3acm,mmio32,0x60038000 console=ttyGS3 debug rw root=mtd:rootfs no_hash_pointers</code> 
 +  * strace (a one-line fix is needed for the mainline strace to correctly handle the initial exec). 
 +  * perf stat (heavy patching is needed to build it for nommu). -D1 is needed to properly enable events (perf relies on ability to run code after the fork but before the exec in the child process to manage events on systems with mmu, -D1 looks like a good workaround for nommu case). 
 +  * c++ exceptions, c cleanup routines, forced stack unwinding, unwinding over signal frames. 
 +  * TLS and NPTL. Some corner cases still need attention though. 
 + 
 +===== Things that don't work ===== 
 + 
 +  * about 290 failing tests in the gcc testsuite, most related to TLS and linuxthreads limitations. About 300 failing tests in the g++ testsuite. 
 +  * mmap with MAP_FIXED flag. By design of the nommu linux, but it seems to me that it doesn't have to be like that. It's usually not a big deal, but that's the reason there's no module information in the /proc/*/maps other than for the ld.so and the executable. 
 +  * tcpdump and libpcap in general. It tries to mmap the packet socket and it's missing a few things (mm/nommu.c doesn't know what capabilities to assign to S_IFSOCK files, the socket file needs to have get_unmapped_area callback defined), but most importantly the packet_mmap code heavily relies on the presence of mmu. Although it seems that it could be worked around. 
 +  * bluetooth. It requires heavy userspace support that includes dbus which wants fork. Looks like it can be worked around, but the amount of bloat is discouraging. 
 +  * perf record. It requires mmapping perf events and the kernel code somewhat relies on the presence of mmu. I've tried to add a workaround, but something is still missing. 
 + 
 +===== Building/flashing/running ===== 
 + 
 +<code> 
 +$ git clone https://github.com/jcmvbkbc/esp32-linux-build 
 +$ cd esp32-linux-build 
 +$ ./rebuild-esp32s3-linux-wifi.sh 
 +</code> 
 + 
 +It will run the following steps to build the toolchain, the kernel, the root and etc filesystem images and the firmware and it will flash it.
  
 ==== Build toolchain dynconfig library and export XTENSA_GNU_CONFIG for use by the toolchain ==== ==== Build toolchain dynconfig library and export XTENSA_GNU_CONFIG for use by the toolchain ====
Line 18: Line 61:
 <code> <code>
 $ git clone https://github.com/jcmvbkbc/xtensa-dynconfig -b original $ git clone https://github.com/jcmvbkbc/xtensa-dynconfig -b original
-$ git clone https://github.com/jcmvbkbc/config-esp32s3 -o esp32s3+$ git clone https://github.com/jcmvbkbc/config-esp32s3 esp32s3
 $ make -C xtensa-dynconfig ORIG=1 CONF_DIR=`pwd` esp32s3.so $ make -C xtensa-dynconfig ORIG=1 CONF_DIR=`pwd` esp32s3.so
 $ export XTENSA_GNU_CONFIG=`pwd`/xtensa-dynconfig/esp32s3.so # make sure this environment variable is set for all commands involving building or using the toolchain $ export XTENSA_GNU_CONFIG=`pwd`/xtensa-dynconfig/esp32s3.so # make sure this environment variable is set for all commands involving building or using the toolchain
Line 24: Line 67:
  
 ==== Build the toolchain ==== ==== Build the toolchain ====
- 
-=== Using crosstool-NG === 
  
 <code> <code>
Line 58: Line 99:
 [ERROR]  >> [ERROR]  >>
 ... ...
-</code> 
- 
-=== Or manually === 
- 
-<code> 
-$ git clone https://github.com/jcmvbkbc/binutils-gdb-xtensa -b xtensa-2.40-fdpic 
-$ git clone https://github.com/jcmvbkbc/gcc-xtensa -b xtensa-14-fdpic 
-$ git clone https://github.com/jcmvbkbc/linux-xtensa -b xtensa-6.4-esp32 
-$ git clone https://github.com/jcmvbkbc/uclibc-ng-xtensa -b xtensa-fdpic 
-$ mkdir build-xtensa-fdpic-toolchain-esp32s3 ; mkdir build-xtensa-fdpic-nothread-esp32s3 
-$ ( cd build-xtensa-fdpic-toolchain-esp32s3 ; rm -rf * ; FLAGS_FOR_TARGET='-mtext-section-literals -mfdpic -O2 -g -mforce-l32' nice ../build-xtensa-fdpic-toolchain.sh ) 
-$ ( cd build-xtensa-fdpic-nothread-esp32s3 ; rm -rf * ; CROSS_COMPILE=`pwd`/../build-xtensa-fdpic-toolchain-esp32s3/root/bin/xtensa-linux-uclibcfdpic- TARGET_CFLAGS='-mauto-litpools -mforce-l32 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' ../build.sh ) 
-$ ln -s `pwd`/build-xtensa-fdpic-nothread-esp32s3/sysroot build-xtensa-fdpic-toolchain-esp32s3/root/xtensa-linux-uclibcfdpic/ 
-</code> 
- 
-build-xtensa-fdpic-toolchain.sh: 
- 
-<code> 
-#! /bin/bash -ex 
- 
-src_base=$(dirname $(readlink -f "$0")) 
-binutils_src="$src_base/binutils-gdb" 
-gcc_src="$src_base/gcc" 
- 
-target=${TARGET:-xtensa-linux-uclibcfdpic} 
-base=`pwd` 
- 
-_FLAGS_FOR_TARGET=${FLAGS_FOR_TARGET:--mtext-section-literals -mfdpic -O2 -g} 
- 
-mkdir binutils && ( 
-        cd binutils 
-        "$binutils_src/configure" --prefix="$base/root" \ 
-                --target=$target \ 
-                --disable-shared --disable-werror --disable-gdb --disable-gdbstub \ 
-                CFLAGS='-O0 -g' 
- 
-        make -j8 
-        make -j8 install 
-) 
- 
-mkdir gcc && ( 
-        cd gcc 
-        "$gcc_src/configure" --prefix="$base/root" \ 
-                --target=$target \ 
-                --with-sysroot="$base/root/$target/sysroot" \ 
-                --enable-languages=c \ 
-                --disable-shared \ 
-                --enable-__cxa_atexit \ 
-                --enable-tls --disable-threads \ 
-                --without-headers --with-newlib \ 
-                CFLAGS_FOR_TARGET="$_FLAGS_FOR_TARGET" \ 
-                CXXFLAGS_FOR_TARGET="$_FLAGS_FOR_TARGET" \ 
-                CFLAGS='-O0 -g' \ 
-                CXXFLAGS='-O0 -g' 
- 
-        make -j8 all-gcc 
-        make -j8 all-target-libgcc 
-        make -j8 install-gcc 
-        make -j8 install-target-libgcc 
-) 
-</code> 
- 
-build.sh: 
- 
-<code> 
-#! /bin/bash -ex 
- 
-if [ $1 = "-r" ]; then 
-        reconfigure=1 
-fi 
-base=$(dirname $(readlink -f "$0")) 
-export CROSS_COMPILE=${CROSS_COMPILE:-xtensa-dc233c-elf-} 
-export TARGET_CFLAGS="${TARGET_CFLAGS:--mlongcalls -mauto-litpools -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64}" 
- 
-if [ ! -d build-linux ]; then 
-        cur=`pwd` 
-        mkdir -p build-linux 
-        cd build-linux 
-        make -C $base/linux ARCH=xtensa O=`pwd` defconfig 
-        make -C $base/linux ARCH=xtensa O=`pwd` INSTALL_HDR_PATH="$cur" -j8 headers_install 
-        cd .. 
-fi 
- 
-#base=$(dirname "$0") 
-if [ -z "$reconfigure" ]; then 
-        [ -f .config ] || make -C $base/uclibc-ng ARCH=xtensa O=`pwd` KERNEL_HEADERS=`pwd`/include UCLIBC_EXTRA_CFLAGS="${TARGET_CFLAGS}" defconfig 
-else 
-        make -C $base/uclibc-ng ARCH=xtensa O=`pwd` KERNEL_HEADERS=`pwd`/include UCLIBC_EXTRA_CFLAGS="${TARGET_CFLAGS}" menuconfig 
-fi 
- 
-make -C $base/uclibc-ng ARCH=xtensa O=`pwd` KERNEL_HEADERS=`pwd`/include UCLIBC_EXTRA_CFLAGS="${TARGET_CFLAGS}" -j8 "$@" 
-make -C $base/uclibc-ng ARCH=xtensa O=`pwd` KERNEL_HEADERS=`pwd`/include UCLIBC_EXTRA_CFLAGS="${TARGET_CFLAGS}" DESTDIR=`pwd`/sysroot install 
 </code> </code>
  
Line 155: Line 104:
  
 <code> <code>
-$ git clone https://github.com/jcmvbkbc/buildroot -b xtensa-2023.02-fdpic +$ git clone https://github.com/jcmvbkbc/buildroot -b xtensa-2023.08-fdpic 
-$ nice make -C buildroot O=`pwd`/build-xtensa-2023.02-fdpic-esp32s3 esp32s3_defconfig +$ nice make -C buildroot O=`pwd`/build-buildroot-esp32s3 esp32s3_defconfig 
-nice make -buildroot O=`pwd`/build-xtensa-2023.02-fdpic-esp32s3 menuconfig # adjust external toolchain location to the one built above +buildroot/utils/config --file build-buildroot-esp32s3/.config --set-str TOOLCHAIN_EXTERNAL_PATH `pwd`/crosstool-NG/builds/xtensa-esp32s3-linux-uclibcfdpic 
-$ nice make -C buildroot O=`pwd`/build-xtensa-2023.02-fdpic-esp32s3+$ buildroot/utils/config --file build-buildroot-esp32s3/.config --set-str TOOLCHAIN_EXTERNAL_PREFIX '$(ARCH)-esp32s3-linux-uclibcfdpic' 
 +$ buildroot/utils/config --file build-buildroot-esp32s3/.config --set-str TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX '$(ARCH)-esp32s3-linux-uclibcfdpic' 
 +$ nice make -C buildroot O=`pwd`/build-buildroot-esp32s3
 </code> </code>
  
Line 169: Line 120:
 $ cd examples/get-started/linux_boot $ cd examples/get-started/linux_boot
 $ idf.py set-target esp32s3 $ idf.py set-target esp32s3
 +$ cp sdkconfig.defaults.esp32s3 sdkconfig
 $ idf.py build $ idf.py build
 $ idf.py flash $ idf.py flash
 $ popd $ popd
-$ parttool.py -p /dev/ttyUSB0 write_partition --partition-name linux  --input build-xtensa-2023.02-fdpic-esp32s3/images/xipImage +$ parttool.py write_partition --partition-name linux  --input build-buildroot-esp32s3/images/xipImage 
-$ parttool.py -p /dev/ttyUSB0 write_partition --partition-name rootfs --input build-xtensa-2023.02-fdpic-esp32s3/images/rootfs.cramfs+$ parttool.py write_partition --partition-name rootfs --input build-buildroot-esp32s3/images/rootfs.cramfs 
 +$ parttool.py write_partition --partition-name etc    --input build-buildroot-esp32s3/images/etc.jffs2
 </code> </code>
  
etc/users/jcmvbkbc/linux-xtensa/esp32s3.1684935694.txt.gz · Last modified: 2023/05/24 16:41 by jcmvbkbc