]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
board: stm32mp1: move set_dfu_alt_info in st common directory
authorPatrick Delaunay <patrick.delaunay@st.com>
Wed, 18 Mar 2020 08:22:45 +0000 (09:22 +0100)
committerPatrick Delaunay <patrick.delaunay@st.com>
Thu, 14 May 2020 07:02:12 +0000 (09:02 +0200)
Move the stm32mp1 common code set_dfu_alt_info() in common directory,
this patch reduce the maintenance effort on this generic part (not board
dependent).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
board/dhelectronics/dh_stm32mp1/Makefile
board/dhelectronics/dh_stm32mp1/board.c
board/st/common/Makefile
board/st/common/stm32mp_dfu.c [new file with mode: 0644]
board/st/stm32mp1/stm32mp1.c

index c77a1e3a84f42501d96221ceb9a67a3e7c3f2b7d..e8f218da085ea62b394dded094974f044a1704d6 100644 (file)
@@ -8,4 +8,6 @@ obj-y += ../../st/stm32mp1/spl.o
 endif
 
 obj-y += ../../st/stm32mp1/board.o board.o
+
 obj-$(CONFIG_SYS_MTDPARTS_RUNTIME) += ../../st/common/stm32mp_mtdparts.o
+obj-$(CONFIG_SET_DFU_ALT_INFO) += ../../st/common/stm32mp_dfu.o
index 5f3fe452ce29438cd8ce36f0414045c04d6a1fd2..873fa86e53c623f127aedd770bdab28fc7267c85 100644 (file)
@@ -662,56 +662,6 @@ int ft_board_setup(void *blob, bd_t *bd)
 }
 #endif
 
-#ifdef CONFIG_SET_DFU_ALT_INFO
-#define DFU_ALT_BUF_LEN SZ_1K
-
-static void board_get_alt_info(const char *dev, char *buff)
-{
-       char var_name[32] = "dfu_alt_info_";
-       int ret;
-
-       ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
-
-       /* name of env variable to read = dfu_alt_info_<dev> */
-       strcat(var_name, dev);
-       ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
-       if (ret) {
-               if (buff[0] != '\0')
-                       strcat(buff, "&");
-               strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
-       }
-}
-
-void set_dfu_alt_info(char *interface, char *devstr)
-{
-       struct udevice *dev;
-
-       ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
-
-       if (env_get("dfu_alt_info"))
-               return;
-
-       memset(buf, 0, sizeof(buf));
-
-       /* probe all MTD devices */
-       mtd_probe_devices();
-
-       board_get_alt_info("ram", buf);
-
-       if (!uclass_get_device(UCLASS_MMC, 0, &dev))
-               board_get_alt_info("mmc0", buf);
-
-       if (!uclass_get_device(UCLASS_MMC, 1, &dev))
-               board_get_alt_info("mmc1", buf);
-
-       if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
-               board_get_alt_info("nor0", buf);
-
-       env_set("dfu_alt_info", buf);
-       puts("DFU alt info setting: done\n");
-}
-#endif
-
 static void board_copro_image_process(ulong fw_image, size_t fw_size)
 {
        int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
index 4bb8b498675d55f51433e950ceffc8bf2a0e2f9e..aa030bacd81dbfdc1ec5a0bbc23218f1ca671e0b 100644 (file)
@@ -7,4 +7,5 @@ obj-$(CONFIG_CMD_STBOARD) += cmd_stboard.o
 
 ifeq ($(CONFIG_ARCH_STM32MP),y)
 obj-$(CONFIG_SYS_MTDPARTS_RUNTIME) += stm32mp_mtdparts.o
+obj-$(CONFIG_SET_DFU_ALT_INFO) += stm32mp_dfu.o
 endif
diff --git a/board/st/common/stm32mp_dfu.c b/board/st/common/stm32mp_dfu.c
new file mode 100644 (file)
index 0000000..99ea21c
--- /dev/null
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+/*
+ * Copyright (C) 2020, STMicroelectronics - All Rights Reserved
+ */
+
+#include <common.h>
+#include <dfu.h>
+#include <env.h>
+#include <memalign.h>
+#include <misc.h>
+#include <mtd.h>
+#include <mtd_node.h>
+
+#define DFU_ALT_BUF_LEN SZ_1K
+
+static void board_get_alt_info(const char *dev, char *buff)
+{
+       char var_name[32] = "dfu_alt_info_";
+       int ret;
+
+       ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
+
+       /* name of env variable to read = dfu_alt_info_<dev> */
+       strcat(var_name, dev);
+       ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
+       if (ret) {
+               if (buff[0] != '\0')
+                       strcat(buff, "&");
+               strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
+       }
+}
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+       struct udevice *dev;
+       struct mtd_info *mtd;
+
+       ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+       if (env_get("dfu_alt_info"))
+               return;
+
+       memset(buf, 0, sizeof(buf));
+
+       /* probe all MTD devices */
+       mtd_probe_devices();
+
+       board_get_alt_info("ram", buf);
+
+       if (!uclass_get_device(UCLASS_MMC, 0, &dev))
+               board_get_alt_info("mmc0", buf);
+
+       if (!uclass_get_device(UCLASS_MMC, 1, &dev))
+               board_get_alt_info("mmc1", buf);
+
+       if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
+               board_get_alt_info("nor0", buf);
+
+       mtd = get_mtd_device_nm("nand0");
+       if (!IS_ERR_OR_NULL(mtd))
+               board_get_alt_info("nand0", buf);
+
+       mtd = get_mtd_device_nm("spi-nand0");
+       if (!IS_ERR_OR_NULL(mtd))
+               board_get_alt_info("spi-nand0", buf);
+
+#ifdef CONFIG_DFU_VIRT
+       strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
+
+       if (IS_ENABLED(CONFIG_PMIC_STPMIC1))
+               strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
+#endif
+
+       env_set("dfu_alt_info", buf);
+       puts("DFU alt info setting: done\n");
+}
+
+#if CONFIG_IS_ENABLED(DFU_VIRT)
+#include <dfu.h>
+#include <power/stpmic1.h>
+
+static int dfu_otp_read(u64 offset, u8 *buffer, long *size)
+{
+       struct udevice *dev;
+       int ret;
+
+       ret = uclass_get_device_by_driver(UCLASS_MISC,
+                                         DM_GET_DRIVER(stm32mp_bsec),
+                                         &dev);
+       if (ret)
+               return ret;
+
+       ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size);
+       if (ret >= 0) {
+               *size = ret;
+               ret = 0;
+       }
+
+       return 0;
+}
+
+static int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
+{
+       int ret;
+#ifdef CONFIG_PMIC_STPMIC1
+       struct udevice *dev;
+
+       ret = uclass_get_device_by_driver(UCLASS_MISC,
+                                         DM_GET_DRIVER(stpmic1_nvm),
+                                         &dev);
+       if (ret)
+               return ret;
+
+       ret = misc_read(dev, 0xF8 + offset, buffer, *size);
+       if (ret >= 0) {
+               *size = ret;
+               ret = 0;
+       }
+       if (ret == -EACCES) {
+               *size = 0;
+               ret = 0;
+       }
+#else
+       pr_err("PMIC update not supported");
+       ret = -EOPNOTSUPP;
+#endif
+
+       return ret;
+}
+
+int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
+                        void *buf, long *len)
+{
+       switch (dfu->data.virt.dev_num) {
+       case 0x0:
+               return dfu_otp_read(offset, buf, len);
+       case 0x1:
+               return dfu_pmic_read(offset, buf, len);
+       }
+       *len = 0;
+       return 0;
+}
+
+int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
+{
+       *size = SZ_1K;
+
+       return 0;
+}
+
+#endif
index 641cfb14681dc8dd3e77179325e2fa20058f64a9..3ccb12d817db08c324ffb4f3716f8bc2be27471f 100644 (file)
@@ -7,7 +7,6 @@
 #include <bootm.h>
 #include <clk.h>
 #include <config.h>
-#include <dfu.h>
 #include <dm.h>
 #include <env.h>
 #include <env_internal.h>
@@ -18,9 +17,7 @@
 #include <init.h>
 #include <led.h>
 #include <malloc.h>
-#include <memalign.h>
 #include <misc.h>
-#include <mtd.h>
 #include <mtd_node.h>
 #include <netdev.h>
 #include <phy.h>
@@ -843,148 +840,6 @@ int ft_board_setup(void *blob, bd_t *bd)
 }
 #endif
 
-#ifdef CONFIG_SET_DFU_ALT_INFO
-#define DFU_ALT_BUF_LEN SZ_1K
-
-static void board_get_alt_info(const char *dev, char *buff)
-{
-       char var_name[32] = "dfu_alt_info_";
-       int ret;
-
-       ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
-
-       /* name of env variable to read = dfu_alt_info_<dev> */
-       strcat(var_name, dev);
-       ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
-       if (ret) {
-               if (buff[0] != '\0')
-                       strcat(buff, "&");
-               strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
-       }
-}
-
-void set_dfu_alt_info(char *interface, char *devstr)
-{
-       struct udevice *dev;
-       struct mtd_info *mtd;
-
-       ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
-
-       if (env_get("dfu_alt_info"))
-               return;
-
-       memset(buf, 0, sizeof(buf));
-
-       /* probe all MTD devices */
-       mtd_probe_devices();
-
-       board_get_alt_info("ram", buf);
-
-       if (!uclass_get_device(UCLASS_MMC, 0, &dev))
-               board_get_alt_info("mmc0", buf);
-
-       if (!uclass_get_device(UCLASS_MMC, 1, &dev))
-               board_get_alt_info("mmc1", buf);
-
-       if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
-               board_get_alt_info("nor0", buf);
-
-       mtd = get_mtd_device_nm("nand0");
-       if (!IS_ERR_OR_NULL(mtd))
-               board_get_alt_info("nand0", buf);
-
-       mtd = get_mtd_device_nm("spi-nand0");
-       if (!IS_ERR_OR_NULL(mtd))
-               board_get_alt_info("spi-nand0", buf);
-
-#ifdef CONFIG_DFU_VIRT
-       strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
-
-       if (IS_ENABLED(CONFIG_PMIC_STPMIC1))
-               strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
-#endif
-
-       env_set("dfu_alt_info", buf);
-       puts("DFU alt info setting: done\n");
-}
-
-#if CONFIG_IS_ENABLED(DFU_VIRT)
-#include <dfu.h>
-#include <power/stpmic1.h>
-
-static int dfu_otp_read(u64 offset, u8 *buffer, long *size)
-{
-       struct udevice *dev;
-       int ret;
-
-       ret = uclass_get_device_by_driver(UCLASS_MISC,
-                                         DM_GET_DRIVER(stm32mp_bsec),
-                                         &dev);
-       if (ret)
-               return ret;
-
-       ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size);
-       if (ret >= 0) {
-               *size = ret;
-               ret = 0;
-       }
-
-       return 0;
-}
-
-static int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
-{
-       int ret;
-#ifdef CONFIG_PMIC_STPMIC1
-       struct udevice *dev;
-
-       ret = uclass_get_device_by_driver(UCLASS_MISC,
-                                         DM_GET_DRIVER(stpmic1_nvm),
-                                         &dev);
-       if (ret)
-               return ret;
-
-       ret = misc_read(dev, 0xF8 + offset, buffer, *size);
-       if (ret >= 0) {
-               *size = ret;
-               ret = 0;
-       }
-       if (ret == -EACCES) {
-               *size = 0;
-               ret = 0;
-       }
-#else
-       pr_err("PMIC update not supported");
-       ret = -EOPNOTSUPP;
-#endif
-
-       return ret;
-}
-
-int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
-                        void *buf, long *len)
-{
-       switch (dfu->data.virt.dev_num) {
-       case 0x0:
-               return dfu_otp_read(offset, buf, len);
-       case 0x1:
-               return dfu_pmic_read(offset, buf, len);
-       }
-       *len = 0;
-       return 0;
-}
-
-int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
-{
-       *size = SZ_1K;
-
-       return 0;
-}
-
-#endif
-
-#endif
-
 static void board_copro_image_process(ulong fw_image, size_t fw_size)
 {
        int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */