From 0033ca1c380a7e852d40e699c0213916822bac92 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Tue, 30 Jul 2019 21:07:02 -0500 Subject: [PATCH] Implement USB "flash drive" gadget --- .../rootfs_overlay/etc/init.d/S99flashdrive | 15 +++++++++++ board/businesscard/v1/genimage.cfg | 26 +++++++++++++++++++ board/businesscard/v1/post-build.sh | 3 +++ board/businesscard/v1/uboot_defconfig | 2 +- .../thirtythreeforty_businesscard_defconfig | 2 ++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 board/businesscard/rootfs_overlay/etc/init.d/S99flashdrive create mode 100755 board/businesscard/v1/post-build.sh diff --git a/board/businesscard/rootfs_overlay/etc/init.d/S99flashdrive b/board/businesscard/rootfs_overlay/etc/init.d/S99flashdrive new file mode 100755 index 0000000..c56fb4e --- /dev/null +++ b/board/businesscard/rootfs_overlay/etc/init.d/S99flashdrive @@ -0,0 +1,15 @@ +#! /bin/sh + +case "$1" in + start|"") + echo 1 > /sys/class/udc/musb-hdrc.1.auto/device/gadget/lun0/ro + echo /dev/ubiblock0_3 > /sys/class/udc/musb-hdrc.1.auto/device/gadget/lun0/file + ;; + stop) + echo '' > /sys/class/udc/musb-hdrc.1.auto/device/gadget/lun0/file + ;; + *) + echo "Usage: flashdrive {start|stop}" >&2 + exit 1 + ;; +esac diff --git a/board/businesscard/v1/genimage.cfg b/board/businesscard/v1/genimage.cfg index a7cac1f..ebd8317 100644 --- a/board/businesscard/v1/genimage.cfg +++ b/board/businesscard/v1/genimage.cfg @@ -20,6 +20,28 @@ image flash.bin { } } +image flashdrive.vfat { + vfat { + files = { + "George Hilliard resume.pdf", + "README.txt" + } + } + size = 96K +} + +image flashdrive.img { + hdimage {} + partition businesscard { + partition-type = 0xc + image = "flashdrive.vfat" + } + // Hardcode a size here to help the ubi builder, which cannot infer a size + // of this image or wait until this image is built, due to the design of + // genimage. + size = 97K +} + image root.ubi { ubi {} partition kernel { @@ -34,6 +56,10 @@ image root.ubi { image = "rootfs.squashfs" read-only = true } + partition flashdrive { + image = flashdrive.img + read-only = true + } } image boot.vfat { diff --git a/board/businesscard/v1/post-build.sh b/board/businesscard/v1/post-build.sh new file mode 100755 index 0000000..b5dc5da --- /dev/null +++ b/board/businesscard/v1/post-build.sh @@ -0,0 +1,3 @@ +#!/bin/sh +grep -q "GADGET_SERIAL" "${TARGET_DIR}/etc/inittab" \ + || echo '/dev/ttyGS0::respawn:/sbin/getty -L /dev/ttyGS0 0 vt100 # GADGET_SERIAL' >> "${TARGET_DIR}/etc/inittab" diff --git a/board/businesscard/v1/uboot_defconfig b/board/businesscard/v1/uboot_defconfig index 76551c8..78d7734 100644 --- a/board/businesscard/v1/uboot_defconfig +++ b/board/businesscard/v1/uboot_defconfig @@ -10,7 +10,7 @@ CONFIG_DRAM_ZQ=0 CONFIG_SPL_SPI_SUNXI=y # CONFIG_FIT is not set CONFIG_BOOTDELAY=0 -CONFIG_BOOTCOMMAND="setenv bootargs console=ttyS0,115200 ubi.mtd=1 ubi.block=0,root root=/dev/ubiblock0_2; sf probe 0 20000000; ubi part rootubi; ubi read ${kernel_addr_r} kernel; ubi read ${fdt_addr_r} dtb; bootz ${kernel_addr_r} - ${fdt_addr_r}" +CONFIG_BOOTCOMMAND="setenv bootargs console=ttyS0,115200 ubi.mtd=1 ubi.block=0,root ubi.block=0,flashdrive root=/dev/ubiblock0_2 g_acm_ms.removable=1; sf probe 0 20000000; ubi part rootubi; ubi read ${kernel_addr_r} kernel; ubi read ${fdt_addr_r} dtb; bootz ${kernel_addr_r} - ${fdt_addr_r}" CONFIG_LOG_MAX_LEVEL=6 CONFIG_LOG_ERROR_RETURN=y # CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR is not set diff --git a/configs/thirtythreeforty_businesscard_defconfig b/configs/thirtythreeforty_businesscard_defconfig index aea142f..ac37092 100644 --- a/configs/thirtythreeforty_businesscard_defconfig +++ b/configs/thirtythreeforty_businesscard_defconfig @@ -12,6 +12,8 @@ BR2_TARGET_GENERIC_ISSUE="Welcome to Businesscard Linux!" BR2_TARGET_GENERIC_GETTY_PORT="/dev/ttyS0" BR2_TARGET_GENERIC_GETTY_BAUDRATE_115200=y # BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set +BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_BUSINESSCARD_PATH)/board/businesscard/rootfs_overlay" +BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL_BUSINESSCARD_PATH)/board/businesscard/v1/post-build.sh" BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh" BR2_ROOTFS_POST_SCRIPT_ARGS="-c $(BR2_EXTERNAL_BUSINESSCARD_PATH)/board/businesscard/v1/genimage.cfg" BR2_LINUX_KERNEL=y