dfu: rename dfu_tftp_write() to dfu_write_by_name()
authorAKASHI Takahiro <takahiro.akashi@linaro.org>
Thu, 29 Oct 2020 04:47:41 +0000 (13:47 +0900)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Fri, 30 Oct 2020 13:20:27 +0000 (14:20 +0100)
This function is essentially independent from tftp, and will also be
utilised in implementing UEFI capsule update in a later commit.
So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_WRITE_ALT, was
introduced so that the file will be compiled with different options,
particularly one added in a later commit.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
common/update.c
drivers/dfu/Kconfig
drivers/dfu/Makefile
drivers/dfu/dfu_alt.c [new file with mode: 0644]
drivers/dfu/dfu_tftp.c [deleted file]
include/dfu.h

index 36b6b75..3994677 100644 (file)
@@ -324,8 +324,9 @@ got_update_file:
                        }
                } else if (fit_image_check_type(fit, noffset,
                                                IH_TYPE_FIRMWARE)) {
-                       ret = dfu_tftp_write(fit_image_name, update_addr,
-                                            update_size, interface, devstring);
+                       ret = dfu_write_by_name(fit_image_name, update_addr,
+                                               update_size, interface,
+                                               devstring);
                        if (ret)
                                return ret;
                }
index 0eec00b..10196f3 100644 (file)
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
        depends on NET
 
 if DFU
+config DFU_WRITE_ALT
+       bool
+       default n
+
 config DFU_TFTP
        bool "DFU via TFTP"
+       select DFU_WRITE_ALT
        select DFU_OVER_TFTP
        help
          This option allows performing update of DFU-managed medium with data
index 0d7925c..dfbf64d 100644 (file)
@@ -9,5 +9,5 @@ obj-$(CONFIG_$(SPL_)DFU_MTD) += dfu_mtd.o
 obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
 obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
 obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
-obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o
+obj-$(CONFIG_$(SPL_)DFU_WRITE_ALT) += dfu_alt.o
 obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o
diff --git a/drivers/dfu/dfu_alt.c b/drivers/dfu/dfu_alt.c
new file mode 100644 (file)
index 0000000..8870967
--- /dev/null
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2015
+ * Lukasz Majewski <l.majewski@majess.pl>
+ */
+
+#include <common.h>
+#include <log.h>
+#include <malloc.h>
+#include <errno.h>
+#include <dfu.h>
+
+/**
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:    Name of DFU entity to write
+ * @addr:               Address of data buffer to write
+ * @len:                Number of bytes
+ * @interface:          Destination DFU medium (e.g. "mmc")
+ * @devstring:          Instance number of destination DFU medium (e.g. "1")
+ *
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
+ *
+ * Return:              0 - on success, error code - otherwise
+ */
+int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+                     unsigned int len, char *interface, char *devstring)
+{
+       char *s, *sb;
+       int alt_setting_num, ret;
+       struct dfu_entity *dfu;
+
+       debug("%s: name: %s addr: 0x%x len: %d device: %s:%s\n", __func__,
+             dfu_entity_name, addr, len, interface, devstring);
+
+       ret = dfu_init_env_entities(interface, devstring);
+       if (ret)
+               goto done;
+
+       /*
+        * We need to copy name pointed by *dfu_entity_name since this text
+        * is the integral part of the FDT image.
+        * Any implicit modification (i.e. done by strsep()) will corrupt
+        * the FDT image and prevent other images to be stored.
+        */
+       s = strdup(dfu_entity_name);
+       sb = s;
+       if (!s) {
+               ret = -ENOMEM;
+               goto done;
+       }
+
+       strsep(&s, "@");
+       debug("%s: image name: %s strlen: %zd\n", __func__, sb, strlen(sb));
+
+       alt_setting_num = dfu_get_alt(sb);
+       free(sb);
+       if (alt_setting_num < 0) {
+               pr_err("Alt setting [%d] to write not found!",
+                      alt_setting_num);
+               ret = -ENODEV;
+               goto done;
+       }
+
+       dfu = dfu_get_entity(alt_setting_num);
+       if (!dfu) {
+               pr_err("DFU entity for alt: %d not found!", alt_setting_num);
+               ret = -ENODEV;
+               goto done;
+       }
+
+       ret = dfu_write_from_mem_addr(dfu, (void *)(uintptr_t)addr, len);
+
+done:
+       dfu_free_entities();
+
+       return ret;
+}
diff --git a/drivers/dfu/dfu_tftp.c b/drivers/dfu/dfu_tftp.c
deleted file mode 100644 (file)
index ffae4bb..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * (C) Copyright 2015
- * Lukasz Majewski <l.majewski@majess.pl>
- */
-
-#include <common.h>
-#include <log.h>
-#include <malloc.h>
-#include <errno.h>
-#include <dfu.h>
-
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-                  char *interface, char *devstring)
-{
-       char *s, *sb;
-       int alt_setting_num, ret;
-       struct dfu_entity *dfu;
-
-       debug("%s: name: %s addr: 0x%x len: %d device: %s:%s\n", __func__,
-             dfu_entity_name, addr, len, interface, devstring);
-
-       ret = dfu_init_env_entities(interface, devstring);
-       if (ret)
-               goto done;
-
-       /*
-        * We need to copy name pointed by *dfu_entity_name since this text
-        * is the integral part of the FDT image.
-        * Any implicit modification (i.e. done by strsep()) will corrupt
-        * the FDT image and prevent other images to be stored.
-        */
-       s = strdup(dfu_entity_name);
-       sb = s;
-       if (!s) {
-               ret = -ENOMEM;
-               goto done;
-       }
-
-       strsep(&s, "@");
-       debug("%s: image name: %s strlen: %zd\n", __func__, sb, strlen(sb));
-
-       alt_setting_num = dfu_get_alt(sb);
-       free(sb);
-       if (alt_setting_num < 0) {
-               pr_err("Alt setting [%d] to write not found!",
-                     alt_setting_num);
-               ret = -ENODEV;
-               goto done;
-       }
-
-       dfu = dfu_get_entity(alt_setting_num);
-       if (!dfu) {
-               pr_err("DFU entity for alt: %d not found!", alt_setting_num);
-               ret = -ENODEV;
-               goto done;
-       }
-
-       ret = dfu_write_from_mem_addr(dfu, (void *)(uintptr_t)addr, len);
-
-done:
-       dfu_free_entities();
-
-       return ret;
-}
index 84abdc7..a4cd86c 100644 (file)
@@ -494,27 +494,27 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr,
 #endif
 
 /**
- * dfu_tftp_write() - write TFTP data to DFU medium
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:   Name of DFU entity to write
+ * @addr:              Address of data buffer to write
+ * @len:               Number of bytes
+ * @interface:         Destination DFU medium (e.g. "mmc")
+ * @devstring:         Instance number of destination DFU medium (e.g. "1")
  *
- * This function is storing data received via TFTP on DFU supported medium.
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
  *
- * @dfu_entity_name:   name of DFU entity to write
- * @addr:              address of data buffer to write
- * @len:               number of bytes
- * @interface:         destination DFU medium (e.g. "mmc")
- * @devstring:         instance number of destination DFU medium (e.g. "1")
- *
- * Return:             0 on success, otherwise error code
+ * Return:             0 - on success, error code - otherwise
  */
-#if CONFIG_IS_ENABLED(DFU_TFTP)
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-                  char *interface, char *devstring);
+#if CONFIG_IS_ENABLED(DFU_WRITE_ALT)
+int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+                     unsigned int len, char *interface, char *devstring);
 #else
-static inline int dfu_tftp_write(char *dfu_entity_name, unsigned int addr,
-                                unsigned int len, char *interface,
-                                char *devstring)
+static inline int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+                                   unsigned int len, char *interface,
+                                   char *devstring)
 {
-       puts("TFTP write support for DFU not available!\n");
+       puts("write support for DFU not available!\n");
        return -ENOSYS;
 }
 #endif