From a99815b57dee42e5b4167174ff5904a1dd3c2d61 Mon Sep 17 00:00:00 2001 From: Ye Li Date: Thu, 6 Apr 2017 00:54:58 +0800 Subject: MLK-14627 android: Fix cache unaligned warning The sparse image writing and boot image reading may have cache unaligned problem. The u-boot v2017 will print warning at runtime. This patch fixes the unaligned problem. Signed-off-by: Ye Li --- drivers/usb/gadget/f_fastboot.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 964448e..9f07940 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -877,9 +877,42 @@ static int is_sparse_partition(struct fastboot_ptentry *ptn) static lbaint_t mmc_sparse_write(struct sparse_storage *info, lbaint_t blk, lbaint_t blkcnt, const void *buffer) { +#define SPARSE_FILL_BUF_SIZE (2 * 1024 * 1024) + struct blk_desc *dev_desc = (struct blk_desc *)info->priv; + ulong ret = 0; + void *data; + int fill_buf_num_blks, cnt; + + if ((unsigned long)buffer & (CONFIG_SYS_CACHELINE_SIZE - 1)) { + + fill_buf_num_blks = SPARSE_FILL_BUF_SIZE / info->blksz; + + data = memalign(CONFIG_SYS_CACHELINE_SIZE, fill_buf_num_blks * info->blksz); + + while (blkcnt) { + + if (blkcnt > fill_buf_num_blks) + cnt = fill_buf_num_blks; + else + cnt = blkcnt; + + memcpy(data, buffer, cnt * info->blksz); - return blk_dwrite(dev_desc, blk, blkcnt, buffer); + ret += blk_dwrite(dev_desc, blk, cnt, data); + + blk += cnt; + blkcnt -= cnt; + buffer = (void *)((unsigned long)buffer + cnt * info->blksz); + + } + + free(data); + } else { + ret = blk_dwrite(dev_desc, blk, blkcnt, buffer); + } + + return ret; } static lbaint_t mmc_sparse_reserve(struct sparse_storage *info, @@ -1758,7 +1791,7 @@ int do_boota(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) goto fail; } /* flush cache after read */ - flush_cache((ulong)hdr->ramdisk_addr, hdr->ramdisk_size); /* FIXME */ + flush_cache((ulong)hdr->ramdisk_addr, ((hdr->ramdisk_size / 512) + 1) * 512); /* FIXME */ #ifdef CONFIG_OF_LIBFDT /* load the dtb file */ @@ -1771,7 +1804,7 @@ int do_boota(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) goto fail; } /* flush cache after read */ - flush_cache((ulong)hdr->second_addr, hdr->second_size); /* FIXME */ + flush_cache((ulong)hdr->second_addr, ((hdr->second_size / 512) + 1) * 512); /* FIXME */ } #endif /*CONFIG_OF_LIBFDT*/ -- cgit v1.1