]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
board: phytec: Commonize board code for K3 based SoMs
authorWadim Egorov <w.egorov@phytec.de>
Wed, 24 Apr 2024 12:53:34 +0000 (14:53 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 10 May 2024 16:42:22 +0000 (10:42 -0600)
Environment handling code can be reused across all our K3 based SoMs.
Instead of adding the same code for every new SoM, move it to a common
board.c file.

Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
board/phytec/common/Makefile
board/phytec/common/k3/Makefile [new file with mode: 0644]
board/phytec/common/k3/board.c [new file with mode: 0644]
board/phytec/phycore_am62x/phycore-am62x.c

index 35c817413066d0a6ab733d5e7c376f9ffc40869c..0c738041565ed91bf90f934246a43835d65970a0 100644 (file)
@@ -5,6 +5,8 @@
 ifdef CONFIG_SPL_BUILD
 # necessary to create built-in.o
 obj- := __dummy__.o
+else
+obj-$(CONFIG_ARCH_K3) += k3/
 endif
 
 obj-y += phytec_som_detection.o
diff --git a/board/phytec/common/k3/Makefile b/board/phytec/common/k3/Makefile
new file mode 100644 (file)
index 0000000..bcca1a9
--- /dev/null
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0+
+obj-y += board.o
diff --git a/board/phytec/common/k3/board.c b/board/phytec/common/k3/board.c
new file mode 100644 (file)
index 0000000..9cb168c
--- /dev/null
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov <w.egorov@phytec.de>
+ */
+
+#include <env_internal.h>
+#include <spl.h>
+#include <asm/arch/hardware.h>
+
+#if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) || IS_ENABLED(CONFIG_ENV_IS_IN_MMC)
+int mmc_get_env_dev(void)
+{
+       u32 boot_device = get_boot_device();
+
+       switch (boot_device) {
+       case BOOT_DEVICE_MMC1:
+               return 0;
+       case BOOT_DEVICE_MMC2:
+               return 1;
+       };
+
+       return CONFIG_SYS_MMC_ENV_DEV;
+}
+#endif
+
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+       u32 boot_device = get_boot_device();
+
+       if (prio)
+               return ENVL_UNKNOWN;
+
+       switch (boot_device) {
+       case BOOT_DEVICE_MMC1:
+       case BOOT_DEVICE_MMC2:
+               if (CONFIG_IS_ENABLED(ENV_IS_IN_FAT))
+                       return ENVL_FAT;
+               if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
+                       return ENVL_MMC;
+       case BOOT_DEVICE_SPI:
+               if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
+                       return ENVL_SPI_FLASH;
+       default:
+               return ENVL_NOWHERE;
+       };
+}
+
+#if IS_ENABLED(CONFIG_BOARD_LATE_INIT)
+int board_late_init(void)
+{
+       u32 boot_device = get_boot_device();
+
+       switch (boot_device) {
+       case BOOT_DEVICE_MMC1:
+               env_set_ulong("mmcdev", 0);
+               env_set("boot", "mmc");
+               break;
+       case BOOT_DEVICE_MMC2:
+               env_set_ulong("mmcdev", 1);
+               env_set("boot", "mmc");
+               break;
+       case BOOT_DEVICE_SPI:
+               env_set("boot", "spi");
+               break;
+       case BOOT_DEVICE_ETHERNET:
+               env_set("boot", "net");
+               break;
+       };
+
+       return 0;
+}
+#endif
index 618b4c370d1e636c403cf32e6ef252661dc4e144..a082b886bda7b2268d05e7aafe9a77d648089b41 100644 (file)
@@ -5,11 +5,8 @@
  */
 
 #include <asm/io.h>
-#include <env.h>
-#include <env_internal.h>
 #include <spl.h>
 #include <fdt_support.h>
-#include <asm/arch/hardware.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -57,67 +54,3 @@ void spl_board_init(void)
               MCU_CTRL_DEVICE_CLKOUT_32K_CTRL);
 }
 #endif
-
-#if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) || IS_ENABLED(CONFIG_ENV_IS_IN_MMC)
-int mmc_get_env_dev(void)
-{
-       u32 boot_device = get_boot_device();
-
-       switch (boot_device) {
-       case BOOT_DEVICE_MMC1:
-               return 0;
-       case BOOT_DEVICE_MMC2:
-               return 1;
-       };
-
-       return CONFIG_SYS_MMC_ENV_DEV;
-}
-#endif
-
-enum env_location env_get_location(enum env_operation op, int prio)
-{
-       u32 boot_device = get_boot_device();
-
-       if (prio)
-               return ENVL_UNKNOWN;
-
-       switch (boot_device) {
-       case BOOT_DEVICE_MMC1:
-       case BOOT_DEVICE_MMC2:
-               if (CONFIG_IS_ENABLED(ENV_IS_IN_FAT))
-                       return ENVL_FAT;
-               if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
-                       return ENVL_MMC;
-       case BOOT_DEVICE_SPI:
-               if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
-                       return ENVL_SPI_FLASH;
-       default:
-               return ENVL_NOWHERE;
-       };
-}
-
-#if IS_ENABLED(CONFIG_BOARD_LATE_INIT)
-int board_late_init(void)
-{
-       u32 boot_device = get_boot_device();
-
-       switch (boot_device) {
-       case BOOT_DEVICE_MMC1:
-               env_set_ulong("mmcdev", 0);
-               env_set("boot", "mmc");
-               break;
-       case BOOT_DEVICE_MMC2:
-               env_set_ulong("mmcdev", 1);
-               env_set("boot", "mmc");
-               break;
-       case BOOT_DEVICE_SPI:
-               env_set("boot", "spi");
-               break;
-       case BOOT_DEVICE_ETHERNET:
-               env_set("boot", "net");
-               break;
-       };
-
-       return 0;
-}
-#endif