Initial port of stecman/hw-boot-selection to ESP32-S3
ESPHome external_component that presents a synthetic 64 KB FAT12 disk over the ESP32-S3's native USB-OTG, containing a one-byte switch_position file and a switch_position_grub.cfg snippet. The disk's volume serial is fixed at 0x55AA6922 to stay drop-in compatible with the upstream /etc/grub.d hook. Components: - fat12 / msc_disk: portable FAT12 sector synthesiser ported from reference/src/fat.c and the boot-sector / FAT / dir-entry generation in reference/src/usb.c. - usb_descriptors / tusb_glue: TinyUSB MSC class with our own callbacks delegating to MscDisk::read_lba (linker --allow-multiple-definition picks ours over esp_tinyusb's storage-backed defaults). - grub_boot_switch: top-level Component, NVS persistence on target changes, exposes targets table to sub-platforms. - select: HA-facing select platform reading parent's targets map. Validated end-to-end on an ESP32-S3-DevKitC-1: USB enumerates as 26ba:8003, /dev/sdb mounts FAT12, mtype reads back the live target, and POST /select/boot_target/set?option=Windows updates both files on the next host read.
This commit is contained in:
52
test/Makefile
Normal file
52
test/Makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
CXX ?= g++
|
||||
CXXFLAGS ?= -std=c++17 -O0 -g -Wall -Wextra -Wno-unused-parameter
|
||||
INCLUDES = -I../components/grub_boot_switch
|
||||
|
||||
SRCS = test_disk.cpp \
|
||||
../components/grub_boot_switch/fat12.cpp \
|
||||
../components/grub_boot_switch/msc_disk.cpp
|
||||
|
||||
BIN = test_disk
|
||||
IMG = disk.img
|
||||
|
||||
.PHONY: all build run verify clean
|
||||
|
||||
all: verify
|
||||
|
||||
build: $(BIN)
|
||||
|
||||
$(BIN): $(SRCS)
|
||||
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ $(SRCS)
|
||||
|
||||
# Generate a disk image (target=0 by default; pass T=N to override)
|
||||
$(IMG): $(BIN)
|
||||
./$(BIN) $(IMG) $(or $(T),0)
|
||||
|
||||
# Run the verifier suite. Requires mtools and `file`.
|
||||
verify: $(IMG)
|
||||
@echo "=== file(1) on disk image ==="
|
||||
@file $(IMG)
|
||||
@echo
|
||||
@echo "=== mdir listing ==="
|
||||
@MTOOLS_SKIP_CHECK=1 mdir -i $(IMG) ::
|
||||
@echo
|
||||
@echo "=== switch_position contents ==="
|
||||
@MTOOLS_SKIP_CHECK=1 mtype -i $(IMG) ::switch_position
|
||||
@echo
|
||||
@echo "=== switch_position_grub.cfg contents ==="
|
||||
@MTOOLS_SKIP_CHECK=1 mtype -i $(IMG) ::switch_position_grub.cfg
|
||||
@echo
|
||||
@echo "=== volume serial ==="
|
||||
@MTOOLS_SKIP_CHECK=1 minfo -i $(IMG) :: | grep -i serial
|
||||
|
||||
# Cycle through several target values to prove the file content tracks state
|
||||
sweep: $(BIN)
|
||||
@for t in 0 1 2 3 9 ; do \
|
||||
./$(BIN) sweep_$$t.img $$t >/dev/null ; \
|
||||
echo "target=$$t:" ; \
|
||||
MTOOLS_SKIP_CHECK=1 mtype -i sweep_$$t.img ::switch_position_grub.cfg ; \
|
||||
done ; \
|
||||
rm -f sweep_*.img
|
||||
|
||||
clean:
|
||||
rm -f $(BIN) $(IMG) sweep_*.img
|
||||
Reference in New Issue
Block a user