]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - drivers/dfu/dfu.c
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / drivers / dfu / dfu.c
index 56b21c78abc68676710eb90f003bb26bead26ea4..07011e99a850fafa7475d02451c8f358986b7f3c 100644 (file)
@@ -67,14 +67,19 @@ int dfu_init_env_entities(char *interface, int dev)
 static unsigned char *dfu_buf;
 static unsigned long dfu_buf_size = CONFIG_SYS_DFU_DATA_BUF_SIZE;
 
-static unsigned char *dfu_free_buf(void)
+unsigned char *dfu_free_buf(void)
 {
        free(dfu_buf);
        dfu_buf = NULL;
        return dfu_buf;
 }
 
-static unsigned char *dfu_get_buf(void)
+unsigned long dfu_get_buf_size(void)
+{
+       return dfu_buf_size;
+}
+
+unsigned char *dfu_get_buf(void)
 {
        char *s;
 
@@ -229,6 +234,7 @@ static int dfu_read_buffer_fill(struct dfu_entity *dfu, void *buf, int size)
                        dfu->crc = crc32(dfu->crc, buf, chunk);
                        dfu->i_buf += chunk;
                        dfu->b_left -= chunk;
+                       dfu->r_left -= chunk;
                        size -= chunk;
                        buf += chunk;
                        readn += chunk;
@@ -287,7 +293,7 @@ int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
                dfu->offset = 0;
                dfu->i_buf_end = dfu_get_buf() + dfu_buf_size;
                dfu->i_buf = dfu->i_buf_start;
-               dfu->b_left = 0;
+               dfu->b_left = min(dfu_buf_size, dfu->r_left);
 
                dfu->bad_skip = 0;
 
@@ -330,7 +336,7 @@ int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
 }
 
 static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
-                           char *interface, int num)
+                          char *interface, int num)
 {
        char *st;
 
@@ -440,3 +446,15 @@ struct dfu_entity *dfu_get_entity(int alt)
 
        return NULL;
 }
+
+int dfu_get_alt(char *name)
+{
+       struct dfu_entity *dfu;
+
+       list_for_each_entry(dfu, &dfu_list, list) {
+               if (!strncmp(dfu->name, name, strlen(dfu->name)))
+                       return dfu->alt;
+       }
+
+       return -ENODEV;
+}