]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
update: tftp: dfu: Extend update_tftp() function to support DFU
authorLukasz Majewski <l.majewski@majess.pl>
Sun, 23 Aug 2015 22:21:47 +0000 (00:21 +0200)
committerMarek Vasut <marex@denx.de>
Mon, 7 Sep 2015 11:41:05 +0000 (13:41 +0200)
This code allows using DFU defined mediums for storing data received via
TFTP protocol.

It reuses and preserves functionality of legacy code at common/update.c.

The update_tftp() function now accepts parameters - namely medium device
name and its number (e.g. mmc 1).

Without this information passed old behavior is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
common/Makefile
common/cmd_fitupd.c
common/main.c
common/update.c
include/net.h

index f4ba8782f543594a94c0ee995f293875b4ca1a20..556fb07592927f3bdee71782a10fe3651595e36b 100644 (file)
@@ -210,6 +210,7 @@ obj-$(CONFIG_LYNXKDI) += lynxkdi.o
 obj-$(CONFIG_MENU) += menu.o
 obj-$(CONFIG_MODEM_SUPPORT) += modem.o
 obj-$(CONFIG_UPDATE_TFTP) += update.o
+obj-$(CONFIG_DFU_TFTP) += update.o
 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
 obj-$(CONFIG_CMD_DFU) += cmd_dfu.o
 obj-$(CONFIG_CMD_GPT) += cmd_gpt.o
index b0459744d98d075f8257e01bc6683edbc5a5988d..78b8747336a871c9131501a8fb9c2ccb2c7a1219 100644 (file)
@@ -23,7 +23,7 @@ static int do_fitupd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        if (argc == 2)
                addr = simple_strtoul(argv[1], NULL, 16);
 
-       return update_tftp(addr);
+       return update_tftp(addr, NULL, NULL);
 }
 
 U_BOOT_CMD(fitupd, 2, 0, do_fitupd,
index 2979fbed630ca22d7ae9a208c18a06ab1a3e21f0..ead0cd17aa8e37e3889ef5da184415a3332e9476 100644 (file)
@@ -75,7 +75,7 @@ void main_loop(void)
        run_preboot_environment_command();
 
 #if defined(CONFIG_UPDATE_TFTP)
-       update_tftp(0UL);
+       update_tftp(0UL, NULL, NULL);
 #endif /* CONFIG_UPDATE_TFTP */
 
        s = bootdelay_process();
index 542915ce6ec6b88a5ca955b2af5350efe90b06fc..1da80b70f2db6d1f01b5dca3141240a01ef1d169 100644 (file)
 #error "CONFIG_FIT and CONFIG_OF_LIBFDT are required for auto-update feature"
 #endif
 
+#if defined(CONFIG_UPDATE_TFTP) && defined(CONFIG_SYS_NO_FLASH)
+#error "CONFIG_UPDATE_TFTP and CONFIG_SYS_NO_FLASH needed for legacy behaviour"
+#endif
+
 #include <command.h>
 #include <flash.h>
 #include <net.h>
 #include <net/tftp.h>
 #include <malloc.h>
+#include <dfu.h>
+#include <errno.h>
 
 /* env variable holding the location of the update file */
 #define UPDATE_FILE_ENV                "updatefile"
@@ -222,13 +228,24 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr,
        return 0;
 }
 
-int update_tftp(ulong addr)
+int update_tftp(ulong addr, char *interface, char *devstring)
 {
-       char *filename, *env_addr;
-       int images_noffset, ndepth, noffset;
+       char *filename, *env_addr, *fit_image_name;
        ulong update_addr, update_fladdr, update_size;
-       void *fit;
+       int images_noffset, ndepth, noffset;
+       bool update_tftp_dfu;
        int ret = 0;
+       void *fit;
+
+       if (interface == NULL && devstring == NULL) {
+               update_tftp_dfu = false;
+       } else if (interface && devstring) {
+               update_tftp_dfu = true;
+       } else {
+               error("Interface: %s and devstring: %s not supported!\n",
+                     interface, devstring);
+               return -EINVAL;
+       }
 
        /* use already present image */
        if (addr)
@@ -277,8 +294,8 @@ got_update_file:
                if (ndepth != 1)
                        goto next_node;
 
-               printf("Processing update '%s' :",
-                       fit_get_name(fit, noffset, NULL));
+               fit_image_name = (char *)fit_get_name(fit, noffset, NULL);
+               printf("Processing update '%s' :", fit_image_name);
 
                if (!fit_image_verify(fit, noffset)) {
                        printf("Error: invalid update hash, aborting\n");
@@ -294,10 +311,20 @@ got_update_file:
                        ret = 1;
                        goto next_node;
                }
-               if (update_flash(update_addr, update_fladdr, update_size)) {
-                       printf("Error: can't flash update, aborting\n");
-                       ret = 1;
-                       goto next_node;
+
+               if (!update_tftp_dfu) {
+                       if (update_flash(update_addr, update_fladdr,
+                                        update_size)) {
+                               printf("Error: can't flash update, aborting\n");
+                               ret = 1;
+                               goto next_node;
+                       }
+               } else if (fit_image_check_type(fit, noffset,
+                                               IH_TYPE_FIRMWARE)) {
+                       ret = dfu_tftp_write(fit_image_name, update_addr,
+                                            update_size, interface, devstring);
+                       if (ret)
+                               return ret;
                }
 next_node:
                noffset = fdt_next_node(fit, noffset, &ndepth);
index d09bec9de1560e8c2443269fb2045f95ea84e7f7..f1671e38deaf745224901ec9d252cccf62b179bd 100644 (file)
@@ -813,8 +813,18 @@ void copy_filename(char *dst, const char *src, int size);
 /* get a random source port */
 unsigned int random_port(void);
 
-/* Update U-Boot over TFTP */
-int update_tftp(ulong addr);
+/**
+ * update_tftp - Update firmware over TFTP (via DFU)
+ *
+ * This function updates board's firmware via TFTP
+ *
+ * @param addr - memory address where data is stored
+ * @param interface - the DFU medium name - e.g. "mmc"
+ * @param devstring - the DFU medium number - e.g. "1"
+ *
+ * @return - 0 on success, other value on failure
+ */
+int update_tftp(ulong addr, char *interface, char *devstring);
 
 /**********************************************************************/