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:
31
components/grub_boot_switch/usb_descriptors.h
Normal file
31
components/grub_boot_switch/usb_descriptors.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace grub_boot_switch {
|
||||
|
||||
// Built at runtime from configuration values so VID/PID/strings can be tuned
|
||||
// from YAML. Lifetime: descriptors live forever once built (single device).
|
||||
struct UsbDescriptorBundle {
|
||||
// tusb_desc_device_t struct (18 bytes), kept opaque here to avoid leaking
|
||||
// tusb headers into the rest of the component.
|
||||
uint8_t device[18];
|
||||
|
||||
// Configuration descriptor: 9 (config) + 9 (interface) + 2*7 (endpoints) = 32 bytes.
|
||||
uint8_t config[32];
|
||||
|
||||
// String descriptors: index 0 = lang (English), 1 = manufacturer,
|
||||
// 2 = product, 3 = serial. ASCII C-strings, null terminated.
|
||||
const char *strings[4];
|
||||
char serial_buf[24]; // backing store for the auto-generated serial.
|
||||
};
|
||||
|
||||
// Populate the bundle from runtime values. The serial_buf is filled with the
|
||||
// chip's MAC address ("E072A1D54520") if `serial_override` is null/empty.
|
||||
void usb_descriptors_build(UsbDescriptorBundle *bundle, uint16_t vid, uint16_t pid,
|
||||
const char *manufacturer, const char *product,
|
||||
const char *serial_override);
|
||||
|
||||
} // namespace grub_boot_switch
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user