Merge tag 'efi-2020-07-rc6' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
[oweals/u-boot.git] / drivers / dfu / dfu.c
index 4f4a07b790c75aaed1bb6bed22f196e689f9fc74..a298c2c43999bd0970ba3e7ac55bbb554a97a890 100644 (file)
@@ -9,6 +9,7 @@
 #include <common.h>
 #include <env.h>
 #include <errno.h>
+#include <log.h>
 #include <malloc.h>
 #include <mmc.h>
 #include <fat.h>
@@ -21,6 +22,25 @@ static LIST_HEAD(dfu_list);
 static int dfu_alt_num;
 static int alt_num_cnt;
 static struct hash_algo *dfu_hash_algo;
+#ifdef CONFIG_DFU_TIMEOUT
+static unsigned long dfu_timeout = 0;
+#endif
+
+/*
+ * The purpose of the dfu_flush_callback() function is to
+ * provide callback for dfu user
+ */
+__weak void dfu_flush_callback(struct dfu_entity *dfu)
+{
+}
+
+/*
+ * The purpose of the dfu_initiated_callback() function is to
+ * provide callback for dfu user
+ */
+__weak void dfu_initiated_callback(struct dfu_entity *dfu)
+{
+}
 
 /*
  * The purpose of the dfu_usb_get_reset() function is to
@@ -42,6 +62,18 @@ __weak bool dfu_usb_get_reset(void)
 #endif
 }
 
+#ifdef CONFIG_DFU_TIMEOUT
+void dfu_set_timeout(unsigned long timeout)
+{
+       dfu_timeout = timeout;
+}
+
+unsigned long dfu_get_timeout(void)
+{
+       return dfu_timeout;
+}
+#endif
+
 static int dfu_find_alt_num(const char *s)
 {
        int i = 0;
@@ -263,6 +295,7 @@ int dfu_transaction_initiate(struct dfu_entity *dfu, bool read)
        }
 
        dfu->inited = 1;
+       dfu_initiated_callback(dfu);
 
        return 0;
 }
@@ -282,6 +315,8 @@ int dfu_flush(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
                printf("\nDFU complete %s: 0x%08x\n", dfu_hash_algo->name,
                       dfu->crc);
 
+       dfu_flush_callback(dfu);
+
        dfu_transaction_cleanup(dfu);
 
        return ret;
@@ -474,6 +509,9 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
        } else if (strcmp(interface, "sf") == 0) {
                if (dfu_fill_entity_sf(dfu, devstr, s))
                        return -1;
+       } else if (strcmp(interface, "virt") == 0) {
+               if (dfu_fill_entity_virt(dfu, devstr, s))
+                       return -1;
        } else {
                printf("%s: Device %s not (yet) supported!\n",
                       __func__,  interface);
@@ -569,7 +607,7 @@ int dfu_config_entities(char *env, char *interface, char *devstr)
 const char *dfu_get_dev_type(enum dfu_device_type t)
 {
        const char *const dev_t[] = {NULL, "eMMC", "OneNAND", "NAND", "RAM",
-                                    "SF", "MTD"};
+                                    "SF", "MTD", "VIRT"};
        return dev_t[t];
 }