diff options
author | Tom Rini <trini@konsulko.com> | 2020-02-05 07:18:12 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-02-05 07:18:12 -0500 |
commit | c95215a6ca1cc7bb53cc634159e222abc06fddff (patch) | |
tree | 885fff6c0bf5e22adb4a037873174dd70ca2ccd9 /drivers/dfu | |
parent | d4827fcd4c1b04c338e4019e412f495aa4231d24 (diff) | |
parent | 095c6eba9d02688e7a1c3cd2093f826d05fe961f (diff) | |
download | u-boot-c95215a6ca1cc7bb53cc634159e222abc06fddff.tar.gz u-boot-c95215a6ca1cc7bb53cc634159e222abc06fddff.tar.bz2 u-boot-c95215a6ca1cc7bb53cc634159e222abc06fddff.zip |
Merge tag 'rpi-next-2020.04' of https://gitlab.denx.de/u-boot/custodians/u-boot-raspberrypi
- DFU support file operations lager then the default max size
- add dfu support to dwc2 for bcm2835
- enable DFU for RPi4
- Fix RPi4 memory map to include the genet device
- add driver for the genet ethernet device
- enable network support in RPi4 config
Diffstat (limited to 'drivers/dfu')
-rw-r--r-- | drivers/dfu/dfu_mmc.c | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index 5b551f6ae1..0d495a785b 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -17,7 +17,7 @@ static unsigned char *dfu_file_buf; static u64 dfu_file_buf_len; -static long dfu_file_buf_filled; +static u64 dfu_file_buf_offset; static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu, u64 offset, void *buf, long *len) @@ -91,22 +91,8 @@ static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu, return 0; } -static int mmc_file_buffer(struct dfu_entity *dfu, void *buf, long *len) -{ - if (dfu_file_buf_len + *len > CONFIG_SYS_DFU_MAX_FILE_SIZE) { - dfu_file_buf_len = 0; - return -EINVAL; - } - - /* Add to the current buffer. */ - memcpy(dfu_file_buf + dfu_file_buf_len, buf, *len); - dfu_file_buf_len += *len; - - return 0; -} - static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu, - void *buf, u64 *len) + u64 offset, void *buf, u64 *len) { char dev_part_str[8]; int ret; @@ -137,7 +123,7 @@ static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu, switch (op) { case DFU_OP_READ: - ret = fs_read(dfu->name, (size_t)buf, 0, 0, &size); + ret = fs_read(dfu->name, (size_t)buf, offset, *len, &size); if (ret) { puts("dfu: fs_read error!\n"); return ret; @@ -145,7 +131,7 @@ static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu, *len = size; break; case DFU_OP_WRITE: - ret = fs_write(dfu->name, (size_t)buf, 0, *len, &size); + ret = fs_write(dfu->name, (size_t)buf, offset, *len, &size); if (ret) { puts("dfu: fs_write error!\n"); return ret; @@ -166,6 +152,43 @@ static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu, return ret; } +static int mmc_file_buf_write(struct dfu_entity *dfu, u64 offset, void *buf, long *len) +{ + int ret = 0; + + if (offset == 0) { + dfu_file_buf_len = 0; + dfu_file_buf_offset = 0; + } + + /* Add to the current buffer. */ + if (dfu_file_buf_len + *len > CONFIG_SYS_DFU_MAX_FILE_SIZE) + *len = CONFIG_SYS_DFU_MAX_FILE_SIZE - dfu_file_buf_len; + memcpy(dfu_file_buf + dfu_file_buf_len, buf, *len); + dfu_file_buf_len += *len; + + if (dfu_file_buf_len == CONFIG_SYS_DFU_MAX_FILE_SIZE) { + ret = mmc_file_op(DFU_OP_WRITE, dfu, dfu_file_buf_offset, + dfu_file_buf, &dfu_file_buf_len); + dfu_file_buf_offset += dfu_file_buf_len; + dfu_file_buf_len = 0; + } + + return ret; +} + +static int mmc_file_buf_write_finish(struct dfu_entity *dfu) +{ + int ret = mmc_file_op(DFU_OP_WRITE, dfu, dfu_file_buf_offset, + dfu_file_buf, &dfu_file_buf_len); + + /* Now that we're done */ + dfu_file_buf_len = 0; + dfu_file_buf_offset = 0; + + return ret; +} + int dfu_write_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf, long *len) { @@ -177,7 +200,7 @@ int dfu_write_medium_mmc(struct dfu_entity *dfu, break; case DFU_FS_FAT: case DFU_FS_EXT4: - ret = mmc_file_buffer(dfu, buf, len); + ret = mmc_file_buf_write(dfu, offset, buf, len); break; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, @@ -193,11 +216,7 @@ int dfu_flush_medium_mmc(struct dfu_entity *dfu) if (dfu->layout != DFU_RAW_ADDR) { /* Do stuff here. */ - ret = mmc_file_op(DFU_OP_WRITE, dfu, dfu_file_buf, - &dfu_file_buf_len); - - /* Now that we're done */ - dfu_file_buf_len = 0; + ret = mmc_file_buf_write_finish(dfu); } return ret; @@ -213,12 +232,9 @@ int dfu_get_medium_size_mmc(struct dfu_entity *dfu, u64 *size) return 0; case DFU_FS_FAT: case DFU_FS_EXT4: - dfu_file_buf_filled = -1; - ret = mmc_file_op(DFU_OP_SIZE, dfu, NULL, size); + ret = mmc_file_op(DFU_OP_SIZE, dfu, 0, NULL, size); if (ret < 0) return ret; - if (*size > CONFIG_SYS_DFU_MAX_FILE_SIZE) - return -1; return 0; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, @@ -227,23 +243,28 @@ int dfu_get_medium_size_mmc(struct dfu_entity *dfu, u64 *size) } } -static int mmc_file_unbuffer(struct dfu_entity *dfu, u64 offset, void *buf, + +static int mmc_file_buf_read(struct dfu_entity *dfu, u64 offset, void *buf, long *len) { int ret; - u64 file_len; - if (dfu_file_buf_filled == -1) { - ret = mmc_file_op(DFU_OP_READ, dfu, dfu_file_buf, &file_len); + if (offset == 0 || offset >= dfu_file_buf_offset + dfu_file_buf_len || + offset + *len < dfu_file_buf_offset) { + u64 file_len = CONFIG_SYS_DFU_MAX_FILE_SIZE; + + ret = mmc_file_op(DFU_OP_READ, dfu, offset, dfu_file_buf, + &file_len); if (ret < 0) return ret; - dfu_file_buf_filled = file_len; + dfu_file_buf_len = file_len; + dfu_file_buf_offset = offset; } - if (offset + *len > dfu_file_buf_filled) + if (offset + *len > dfu_file_buf_offset + dfu_file_buf_len) return -EINVAL; /* Add to the current buffer. */ - memcpy(buf, dfu_file_buf + offset, *len); + memcpy(buf, dfu_file_buf + offset - dfu_file_buf_offset, *len); return 0; } @@ -259,7 +280,7 @@ int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf, break; case DFU_FS_FAT: case DFU_FS_EXT4: - ret = mmc_file_unbuffer(dfu, offset, buf, len); + ret = mmc_file_buf_read(dfu, offset, buf, len); break; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, |