We do not do USB enumeration by default, but we should if we want to be
able to boot off an UEFI installer image inserted via USB.

This has been tested on QNAP TS-433eU with
debian-13.1.0-arm64-netinst.iso.

Signed-off-by: Ahmad Fatoum <[email protected]>
---
This is the same as v1, but I asked for this to be applied yet, because
EFI loader support was still pending. This is not the case now, so I ask
this be applied to master.
---
 Documentation/boards/rk35xx/qnap-tsx33.rst    | 53 +++++++++++++++++--
 arch/arm/boards/qnap-tsx33/Makefile           |  1 +
 arch/arm/boards/qnap-tsx33/board.c            |  6 ++-
 .../defaultenv-tsx33/init/usbdetect           |  6 +++
 arch/arm/configs/rockchip_v8_defconfig        |  5 ++
 5 files changed, 67 insertions(+), 4 deletions(-)
 create mode 100755 arch/arm/boards/qnap-tsx33/defaultenv-tsx33/init/usbdetect

diff --git a/Documentation/boards/rk35xx/qnap-tsx33.rst 
b/Documentation/boards/rk35xx/qnap-tsx33.rst
index b205e31e561b..3086bd2b5bac 100644
--- a/Documentation/boards/rk35xx/qnap-tsx33.rst
+++ b/Documentation/boards/rk35xx/qnap-tsx33.rst
@@ -24,6 +24,14 @@ With these barebox can be compiled as:
 
 If cross-compiling, ``CROSS_COMPILE`` needs to be additionally set.
 
+Alternatively, if you enable barebox to boot an OS image with
+UEFI, use:
+
+.. code-block:: sh
+
+  make ARCH=arm rockchip_v8_efiloader_defconfig
+  make ARCH=arm
+
 Flashing via USB
 ----------------
 
@@ -42,11 +50,50 @@ load barebox into RAM and flash it to the eMMC using 
``fastboot``:
 
 .. code-block:: sh
 
-  scripts/rk-usb-loader images/barebox-qnap-ts433.img # or *ts433eu.img
+  scripts/rk-usb-loader images/barebox-qnap-ts433.img # or *-eu.img
   fastboot flash bbu-emmc barebox-qnap-ts433.img
 
+Repartitioning and environment partition
+----------------------------------------
+
+If you are wiping the disk anyway to repartition it to fit the distro
+that's going to be installed, it's recommended to add a barebox environment
+partition for holding persistent bootloader configuration:
+
+.. warning:: This will delete the vendor system on the eMMC!
+
+.. code-block:: sh
+
+   fastboot erase emmc     # wipes full eMMC including barebox!
+   fastboot oem exec "createnv -f /dev/mmc0"
+   fastboot flash bbu-emmc barebox-qnap-ts433.img # or *-eu.img
+
+Known issues
+------------
+
+- eMMC can't be operated at HS200 under Linux, when it should be possible.
+- eMMC accesses times out occasionally under barebox. If an error message
+  is reported during flashing, retry the operation.
+- second USB port doesn't work in barebox
+- Having multiple images per variant could be avoided by having barebox
+  read the EEPROM early enough to determine correct device tree
+
 Booting Debian
 --------------
 
-Refer to https://wiki.debian.org/InstallingDebianOn/Qnap/TS-433
-for information on how to install Debian.
+Flash the Debian netinstall image to a USB stick and insert it into
+the (first) front USB and power on the device after having flashed
+barebox to the eMMC as per the previous section.
+
+It should then boot into a GRUB menu and from there into the
+Debian installer.
+
+When the installer asks you at the end about whether to also install
+GRUB to the removable media path, say **yes**.
+
+After installation is done, remove the USB drive and the system
+will automatically boot from the Debian system installed to the
+eMMC.
+
+Refer also to https://wiki.debian.org/InstallingDebianOn/Qnap/TS-433
+for more information on how to install Debian.
diff --git a/arch/arm/boards/qnap-tsx33/Makefile 
b/arch/arm/boards/qnap-tsx33/Makefile
index 1d052d28c9fc..ec1b7fb7486b 100644
--- a/arch/arm/boards/qnap-tsx33/Makefile
+++ b/arch/arm/boards/qnap-tsx33/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 lwl-y += lowlevel.o
 obj-y += board.o
+bbenv-y += defaultenv-tsx33
diff --git a/arch/arm/boards/qnap-tsx33/board.c 
b/arch/arm/boards/qnap-tsx33/board.c
index a4e86b0337f8..a52a048d2462 100644
--- a/arch/arm/boards/qnap-tsx33/board.c
+++ b/arch/arm/boards/qnap-tsx33/board.c
@@ -7,6 +7,7 @@
 #include <globalvar.h>
 #include <envfs.h>
 #include <deep-probe.h>
+#include <environment.h>
 #include <linux/usb/gadget-multi.h>
 
 struct ts433_match_data {
@@ -30,7 +31,8 @@ static int ts433_probe(struct device *dev)
                 * usbgadget -b -A 
"kernel(kernel)c,initramfs(initramfs)c,dtb(dtb)" -a
                 */
                globalvar_add_simple("fastboot.bbu", "1");
-               globalvar_add_simple("fastboot.partitions", 
"kernel(kernel)c,initramfs(initramfs)c,dtb(dtb)c");
+               globalvar_add_simple("fastboot.partitions",
+                    
"/dev/mmc0(emmc),kernel(kernel)c,initramfs(initramfs)c,dtb(dtb)c");
                globalvar_add_simple("usbgadget.acm", "1");
                usbgadget_autostart(true);
 
@@ -49,6 +51,8 @@ static int ts433_probe(struct device *dev)
 
        rockchip_bbu_mmc_register("emmc", BBU_HANDLER_FLAG_DEFAULT, 
"/dev/mmc0");
 
+       defaultenv_append_directory(defaultenv_tsx33);
+
        return 0;
 }
 
diff --git a/arch/arm/boards/qnap-tsx33/defaultenv-tsx33/init/usbdetect 
b/arch/arm/boards/qnap-tsx33/defaultenv-tsx33/init/usbdetect
new file mode 100755
index 000000000000..f2d30f01ac32
--- /dev/null
+++ b/arch/arm/boards/qnap-tsx33/defaultenv-tsx33/init/usbdetect
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+if [ -n "${efi.loader}" ] && [ "${bootsource}" = mmc ]; then
+       otg.mode=host
+       usb
+fi
diff --git a/arch/arm/configs/rockchip_v8_defconfig 
b/arch/arm/configs/rockchip_v8_defconfig
index f8f8ceb80516..a44b898f5584 100644
--- a/arch/arm/configs/rockchip_v8_defconfig
+++ b/arch/arm/configs/rockchip_v8_defconfig
@@ -37,6 +37,8 @@ CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_STATE=y
 CONFIG_BOOTCHOOSER=y
 CONFIG_RESET_SOURCE=y
+CONFIG_FASTBOOT_SPARSE=y
+CONFIG_FASTBOOT_CMD_OEM=y
 CONFIG_CMD_DMESG=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
@@ -48,6 +50,8 @@ CONFIG_CMD_RESET=y
 CONFIG_CMD_UIMAGE=y
 CONFIG_CMD_BOOTCHOOSER=y
 CONFIG_CMD_PARTITION=y
+CONFIG_CMD_PARTED=y
+CONFIG_CMD_CREATENV=y
 CONFIG_CMD_EXPORT=y
 CONFIG_CMD_DEFAULTENV=y
 CONFIG_CMD_LOADENV=y
@@ -77,6 +81,7 @@ CONFIG_CMD_TIMEOUT=y
 CONFIG_CMD_MM=y
 CONFIG_CMD_CLK=y
 CONFIG_CMD_DETECT=y
+CONFIG_CMD_FLASH=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_LED=y
-- 
2.47.3


Reply via email to