Switch Retronix R-Car V4H Sparrow Hawk to distro boot command to obtain
generic distro boot capability. The boot scripts now search each of the
SD, NVMe, USB boot devices for either a fitImage with embedded script,
regular boot script, or extlinux.conf, and boot the first one found.
This allows for standardized boot of the device, similar to other such
devices.

There are slight customizations to the distro boot commands, specifically
the PCIe controller is started before USB controller, because the USB
controller is attached to the PCIe controller. Furthermore, USB ethernet
boot is not enabled.

Signed-off-by: Marek Vasut <[email protected]>
---
Cc: Nobuhiro Iwamatsu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
 configs/r8a779g3_sparrowhawk_defconfig |  2 +-
 include/configs/sparrowhawk.h          | 70 +++++++++++++++++++++++++-
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/configs/r8a779g3_sparrowhawk_defconfig 
b/configs/r8a779g3_sparrowhawk_defconfig
index e39d14df806..a36ed3ffa3a 100644
--- a/configs/r8a779g3_sparrowhawk_defconfig
+++ b/configs/r8a779g3_sparrowhawk_defconfig
@@ -19,7 +19,7 @@ CONFIG_SYS_BARGSIZE=2048
 CONFIG_SYS_CBSIZE=2048
 CONFIG_BAUDRATE=921600
 CONFIG_BINMAN=y
-CONFIG_BOOTCOMMAND="tftp ${loadaddr} fitImage && bootm ${loadaddr}"
+CONFIG_DISTRO_DEFAULTS=y
 CONFIG_DEFAULT_FDT_FILE="r8a779g3-sparrow-hawk.dtb"
 CONFIG_CMD_REMOTEPROC=y
 CONFIG_GPIO_HOG=y
diff --git a/include/configs/sparrowhawk.h b/include/configs/sparrowhawk.h
index e6e18bc97b0..a4309953433 100644
--- a/include/configs/sparrowhawk.h
+++ b/include/configs/sparrowhawk.h
@@ -11,6 +11,35 @@
 
 #include "rcar-gen4-common.h"
 
+#define BOOT_TARGET_DEVICES(func)      \
+       func(MMC, mmc, 0)               \
+       func(NVME, nvme, 0)             \
+       func(USB, usb, 0)               \
+       func(DHCP, dhcp, na)
+
+#include <config_distro_bootcmd.h>
+
+/*
+ * Support for USB-ethernet and PCIe-ethernet is disabled, do not
+ * initialize either and directly boot via native ethernet only.
+ */
+#undef BOOTENV_RUN_NET_USB_START
+#define BOOTENV_RUN_NET_USB_START
+#undef BOOTENV_SHARED_USB
+#define BOOTENV_SHARED_USB                                             \
+       "usb_boot="                                                     \
+               "run boot_pci_enum ; usb start ; "                      \
+               BOOTENV_SHARED_BLKDEV_BODY(usb)
+#undef BOOTENV_DEV_DHCP
+#define BOOTENV_DEV_DHCP(devtypeu, devtypel, instance)                 \
+       "bootcmd_dhcp="                                                 \
+               "devtype=" #devtypel "; "                               \
+               "if dhcp ${scriptaddr} ${boot_script_dhcp}; then "      \
+                       "source ${scriptaddr}; "                        \
+               "fi;"                                                   \
+               BOOTENV_EFI_RUN_DHCP                                    \
+               "\0"
+
 /* Environment setting */
 #undef CFG_EXTRA_ENV_SETTINGS
 #define CFG_EXTRA_ENV_SETTINGS                                         \
@@ -62,6 +91,45 @@
        "update_loader_from_usb="                                       \
                "pci enum && usb start && "                             \
                "env set renesas_update_loader_iface usb && "           \
-               "run update_loader_from_blk01\0"
+               "run update_loader_from_blk01\0"                        \
+       \
+       BOOTENV                                                         \
+       "scriptaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0"            \
+       "scan_dev_for_scripts="                                         \
+               "if test -e ${devtype} ${devnum}:${distro_bootpart} "   \
+                               "${prefix}fitImage; then "              \
+                       "echo Found fitImage ${prefix}fitImage ; "      \
+                       "if test ${devtype} = \"mmc\" ; then "          \
+                               "env set bootargs \"${bootargs} "       \
+                                       "root=/dev/mmcblk0p1\" ; "      \
+                       "elif test ${devtype} = \"nvme\" ; then "       \
+                               "env set bootargs \"${bootargs} "       \
+                                       "root=/dev/nvme0n1p1\" ; "      \
+                       "elif test ${devtype} = \"usb\" ; then "        \
+                               "env set bootargs \"${bootargs} "       \
+                                       "root=/dev/sda1\" ; "           \
+                       "else "                                         \
+                               "part uuid ${devtype} "                 \
+                                       "${devnum}:${distro_bootpart} " \
+                                       "uuid ; "                       \
+                               "env set bootargs \"${bootargs} "       \
+                                       "root=PARTUUID=${uuid}\" ; "    \
+                       "fi ; "                                         \
+                       "env set bootargs \"${bootargs} rw rootwait\" ; " \
+                       "load ${devtype} ${devnum}:${distro_bootpart} " \
+                               "${scriptaddr} ${prefix}fitImage && "   \
+                       "source ${scriptaddr}:script ; "                \
+                       "echo fitImage script FAILED: continuing...; "  \
+               "fi; "                                                  \
+               "for script in ${boot_scripts}; do "                    \
+                       "if test -e ${devtype} "                        \
+                                       "${devnum}:${distro_bootpart} " \
+                                       "${prefix}${script}; then "     \
+                               "echo Found U-Boot script "             \
+                                       "${prefix}${script}; "          \
+                               "run boot_a_script; "                   \
+                               "echo SCRIPT FAILED: continuing...; "   \
+                       "fi; "                                          \
+               "done\0"
 
 #endif /* __SPARROWHAWK_H */
-- 
2.53.0

Reply via email to