diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..943ba1d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+settings.cfg
+*.swp
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..eeb4a4c
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "esp32-linux-build"]
+ path = esp32-linux-build
+ url = https://github.com/jcmvbkbc/esp32-linux-build.git
diff --git a/Dockerfile b/Dockerfile
index a9f8e5f..04824a1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,11 +1,7 @@
-# Dockerfile port of https://gist.github.com/jcmvbkbc/316e6da728021c8ff670a24e674a35e6
-# wifi details http://wiki.osll.ru/doku.php/etc:users:jcmvbkbc:linux-xtensa:esp32s3wifi
-
-# we need python 3.10 not 3.11
FROM ubuntu:22.04
RUN apt-get update
-RUN apt-get -y install gperf bison flex texinfo help2man gawk libtool-bin git unzip ncurses-dev rsync zlib1g zlib1g-dev xz-utils cmake wget bzip2 g++ python3 python3-dev python3-pip cpio bc virtualenv libusb-1.0 && \
+RUN apt-get -y install gperf bison flex texinfo help2man gawk libtool-bin git unzip ncurses-dev rsync zlib1g zlib1g-dev xz-utils cmake wget bzip2 g++ python3 python3-dev python3-pip python3.10-venv cpio bc virtualenv libusb-1.0 && \
ln -s /usr/bin/python3 /usr/bin/python
WORKDIR /app
@@ -19,64 +15,16 @@ RUN wget https://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.xz && \
make install
ENV PATH="$PATH:/app/autoconf-2.71/root/bin"
-# dynconfig
-RUN git clone https://github.com/jcmvbkbc/xtensa-dynconfig -b original --depth=1 && \
- git clone https://github.com/jcmvbkbc/config-esp32s3 esp32s3 --depth=1 && \
- make -C xtensa-dynconfig ORIG=1 CONF_DIR=`pwd` esp32s3.so
-ENV XTENSA_GNU_CONFIG="/app/xtensa-dynconfig/esp32s3.so"
-
-# ct-ng cannot run as root, we'll just do everything else as a user
-RUN useradd -d /app/build -u 3232 esp32 && mkdir build && chown esp32:esp32 build
-USER esp32
-
-# toolchain
-RUN cd build && \
- git clone https://github.com/jcmvbkbc/crosstool-NG.git -b xtensa-fdpic --depth=1 && \
- cd crosstool-NG && \
- ./bootstrap && \
- ./configure --enable-local && \
- make && \
- ./ct-ng xtensa-esp32s3-linux-uclibcfdpic && \
- CT_PREFIX=`pwd`/builds ./ct-ng build || echo "Completed" # the complete ct-ng build fails but we still get what we wanted!
-RUN [ -e build/crosstool-NG/builds/xtensa-esp32s3-linux-uclibcfdpic/bin/xtensa-esp32s3-linux-uclibcfdpic-gcc ] || exit 1
-
-# kernel and rootfs
-RUN cd build && \
- git clone https://github.com/jcmvbkbc/buildroot -b xtensa-2023.02-fdpic --depth=1 && \
- make -C buildroot O=`pwd`/build-xtensa-2023.02-fdpic-esp32s3 esp32s3wifi_defconfig && \
- buildroot/utils/config --file build-xtensa-2023.02-fdpic-esp32s3/.config --set-str TOOLCHAIN_EXTERNAL_PATH `pwd`/crosstool-NG/builds/xtensa-esp32s3-linux-uclibcfdpic && \
- buildroot/utils/config --file build-xtensa-2023.02-fdpic-esp32s3/.config --set-str TOOLCHAIN_EXTERNAL_PREFIX '$(ARCH)-esp32s3-linux-uclibcfdpic' && \
- buildroot/utils/config --file build-xtensa-2023.02-fdpic-esp32s3/.config --set-str TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX '$(ARCH)-esp32s3-linux-uclibcfdpic' && \
- make -C buildroot O=`pwd`/build-xtensa-2023.02-fdpic-esp32s3
-RUN [ -f build/build-xtensa-2023.02-fdpic-esp32s3/images/xipImage -a -f build/build-xtensa-2023.02-fdpic-esp32s3/images/rootfs.cramfs ] || exit 1
-
-
-# bootloader
-ENV IDF_PATH="/app/build/esp-hosted/esp_hosted_ng/esp/esp_driver/esp-idf"
-RUN cd build && \
- git clone https://github.com/jcmvbkbc/esp-hosted -b shmem --depth=1 && \
- cd esp-hosted/esp_hosted_ng/esp/esp_driver && cmake . && \
- cd esp-idf && . ./export.sh && \
- cd ../network_adapter && idf.py set-target esp32s3 && \
- cp sdkconfig.defaults.esp32s3 sdkconfig && idf.py build
+RUN rm -rf autoconf-2.71*
+#COPY esp32-linux-build/* /app/
+RUN chmod a+rwx /app
-# move files over
-RUN cd build && mkdir release && \
- cp esp-hosted/esp_hosted_ng/esp/esp_driver/network_adapter/build/bootloader/bootloader.bin release && \
- cp esp-hosted/esp_hosted_ng/esp/esp_driver/network_adapter/build/partition_table/partition-table.bin release && \
- cp esp-hosted/esp_hosted_ng/esp/esp_driver/network_adapter/build/network_adapter.bin release && \
- cp build-xtensa-2023.02-fdpic-esp32s3/images/xipImage release && \
- cp build-xtensa-2023.02-fdpic-esp32s3/images/rootfs.cramfs release
-
-# keep docker running so we can debug/rebuild :)
-USER root
-ENTRYPOINT ["tail", "-f", "/dev/null"]
+ARG DOCKER_USER=default_user
+ARG DOCKER_USERID=default_userid
+# ct-ng cannot run as root, we'll just do everything else as a user
+RUN useradd -d /app/build -u $DOCKER_USERID $DOCKER_USER && mkdir build && chown $DOCKER_USER:$DOCKER_USER build
+RUN usermod -a -G dialout $DOCKER_USER
+USER $DOCKER_USER
-# grab the files with `docker cp CONTAINER_NAME:/app/build/release/\* .`
-# now you can burn the files from the 'release' folder with:
-# python esptool.py --chip esp32s3 -p /dev/ttyUSB0 -b 921600 --before=default_reset --after=hard_reset write_flash 0x0 bootloader.bin 0x10000 network_adapter.bin 0x8000 partition-table.bin
-# next we can burn in the kernel and filesys with parttool, which is part of esp-idf
-# parttool.py write_partition --partition-name linux --input xipImage
-# parttool.py write_partition --partition-name rootfs --input rootfs.cramfs
diff --git a/README.md b/README.md
index 6c26a79..500aefb 100644
--- a/README.md
+++ b/README.md
@@ -1,57 +1,99 @@
# ESP32 S3 Linux - Docker builder
-Dockerfile ported by Adafruit from the work of [@jcmvbkbc](https://gist.github.com/jcmvbkbc/316e6da728021c8ff670a24e674a35e6)
+The initial version was a Dockerfile ported by Adafruit from the work of [@jcmvbkbc](https://gist.github.com/jcmvbkbc/316e6da728021c8ff670a24e674a35e6). The current version uses the last version of the build scripts like a git submodule and it has some improvements on the DockerFile to support USB flashing.
+
+
+
+
+ Don't forget to star ⭐ this repository
+ |
+
+
## Build
Please follow the next steps:
-1. Build the docker image:
+1. Download or clone this repo
```bash
-docker build -t esp32-s3_linux .
+git clone --recursive https://github.com/hpsaturn/esp32s3-linux.git && cd esp32s3-linux
```
-This step takes around ~35 minutes and needs ~20Gb:
+2. Then build the docker image:
-
+```bash
+docker build --build-arg DOCKER_USER=$USER --build-arg DOCKER_USERID=$UID -t esp32linuxbase .
+```
-2. Run a container in a terminal
+3. Copy settings sample and configure it:
```bash
-docker run --name esp32s3build -it esp32-s3_linux
+cp settings.cfg.default settings.cfg
```
-3. In a second termintal, copy the binaries
+Possible settings:
```bash
-docker cp esp32s3build:/app/build/release/ bin_files
-```
+keep_toolchain=
+keep_rootfs=
+keep_buildroot=
+keep_bootloader=
+keep_etc=
+```
-4. Stop the container
+put `y` to enable some one like this:
```bash
-docker stop esp32s3build
+# keep_toolchain=y -- don't rebuild the toolchain, but rebuild everything else
+# keep_rootfs=y -- don't reconfigure or rebuild rootfs from scratch. Would still apply overlay changes
+# keep_buildroot=y -- don't redownload the buildroot, only git pull any updates into it
+# keep_bootloader=y -- don't redownload the bootloader, only rebuild it
+# keep_etc=y -- don't overwrite the /etc partition
+```
+
+4. Run the build script of your preference, for example:
+
+```bash
+docker run --rm -it --name esp32s3linux --user="$(id -u):$(id -g)" -v ./esp32-linux-build:/app --env-file settings.cfg --device-cgroup-rule='c 166:* rmw' --device=/dev/ttyACM0 esp32linuxbase ./rebuild-esp32s3-linux-wifi.sh
```
-5. Upload
+Keep in mind that you should change the **--device** to your USB device where is connected the ESP32S3. For a different script please check the directory `esp32-linux-build`. This step takes around ~35 minutes and needs ~20Gb.
+
+After that you should have this message:
+
+
-You must have two tools installed in your system, [ESPTool](https://docs.espressif.com/projects/esptool/en/latest/esp32/installation.html) and [Espressif IDF](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/#installation). After that please upload the binaries using:
+## Flashing
+
+1. Open a different terminal and enter to the running container:
```bash
-python esptool.py --chip esp32s3 -p YOUR-PORT-HERE -b 921600 --before=default_reset --after=hard_reset write_flash 0x0 bootloader.bin 0x10000 network_adapter.bin 0x8000 partition-table.bin
+docker exec -it -u root esp32s3linux bash
```
+and change the docker USB device permissions:
+
```bash
-parttool.py write_partition --partition-name linux --input xipImage
+chmod 666 /dev/ttyACM0
```
+2. Return to the main terminal and perform the flashing. And that's it!
+
+
+
+---
+
+# Updates
+
+After the first build and flashing, you can keep the sources and working directories changing the `settings.cfg` file and repeating the steps from the step 4. Also don't forget update before, the git submodules like this:
+
```bash
-parttool.py write_partition --partition-name rootfs --input rootfs.cramfs
+git submodule update --init --recursive
```
-Alternative following this [Adafruit guide](https://learn.adafruit.com/docker-esp32-s3-linux/docker-esp32-s3-linux-image).
+For clean the working directories, please enter to `esp32-linux-build` and remove the build directory.
# Linux boot
@@ -62,11 +104,64 @@ For run in a TTGO T7 S3 (LilyGO board), you should have a FTDI connection to the
+# WiFi settings
+
+Only add your credentials on `/etc/wpa_supplicant.conf` using `vi` editor or from the command line, like this:
+
+```bash
+cat > /etc/wpa_supplicant.conf < /etc/cmdline
+```
+
+### Provisional GPIO handling:
+
+```bash
+devmem 0x60004020 32 2 # (output enable for gpio1)
+devmem 0x60004004 32 2 # (drive gpio1 high)
+```
+
+For other GPIO be careful the syntax and the addressing, for instance for the LilyGO TTGO T7S3 board and its LED, the GPIO is the IO17, then you should be pass the number in hexadecimal, like this:
+
+```bash
+devmem 0x60004020 32 0x20000 # (ouput enable for GPIO 17)
+devmem 0x60004004 32 0x20000 # (set GPIO 17 high)
+```
+
+Also you can enable the LED on the startup in a simple `inet.d` service:
+
+
+
+More info in the [technical document](https://www.espressif.com/sites/default/files/documentation/esp32-s3_technical_reference_manual_en.pdf) of the ESP32S3.
+
+# Development and Contributions
+
+Maybe the best way to development is not using this guide, because is more easy modify the files and make code contributions from your local machine. For this reason you should have running the [official script](https://github.com/jcmvbkbc/esp32-linux-build) in your machine.
+
+Also with this script you could have faster updates because it supports some skip parameters like this:
+
+```bash
+keep_toolchain=y keep_rootfs=y keep_buildroot=y keep_bootloader=y keep_etc=y ./rebuild-esp32s3-linux.sh
+```
+
# TODO
-- [ ] Freezing repositories to specific commit
-- [ ] Migrate to the last script version with build parameters
-- [ ] Add provisioning stuff
+- [x] Migrate to the last script version with build parameters
+- [x] Freezing repositories to specific commit
+- [x] Add provisioning stuff (etc partition)
# Credits
diff --git a/esp32-linux-build b/esp32-linux-build
new file mode 160000
index 0000000..ae45f24
--- /dev/null
+++ b/esp32-linux-build
@@ -0,0 +1 @@
+Subproject commit ae45f2478472e569c64defcdfcaf0d7f37a3e700
diff --git a/screenshots/docker_build_before_flash.jpg b/screenshots/docker_build_before_flash.jpg
new file mode 100644
index 0000000..e058214
Binary files /dev/null and b/screenshots/docker_build_before_flash.jpg differ
diff --git a/screenshots/docker_flashing.jpg b/screenshots/docker_flashing.jpg
new file mode 100644
index 0000000..e66fa3e
Binary files /dev/null and b/screenshots/docker_flashing.jpg differ
diff --git a/screenshots/gpio_via_devmem.jpg b/screenshots/gpio_via_devmem.jpg
new file mode 100644
index 0000000..d2dde60
Binary files /dev/null and b/screenshots/gpio_via_devmem.jpg differ
diff --git a/settings.cfg.default b/settings.cfg.default
new file mode 100644
index 0000000..e430fb3
--- /dev/null
+++ b/settings.cfg.default
@@ -0,0 +1,5 @@
+keep_toolchain=
+keep_rootfs=
+keep_buildroot=
+keep_bootloader=
+keep_etc=