From 70d09082cc6cbde3f4aaacad449cf27063080c45 Mon Sep 17 00:00:00 2001 From: Long Yu Date: Tue, 20 Jun 2017 15:52:54 +0800 Subject: [PATCH] emmc: refixed error reading dtb character device PD#146144: emmc: refixed error reading dtb character device 1. corrected the boot0 and boot1 partition property 2. refixed error reading dtb character device Change-Id: Icebdf35cbd7e779573a16ca0230015c907135d52 Signed-off-by: Long Yu --- drivers/amlogic/mmc/emmc_partitions.c | 57 ++++++++++++++++++++++++++--------- drivers/mmc/core/mmc.c | 2 +- include/linux/mmc/emmc_partitions.h | 1 + 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/drivers/amlogic/mmc/emmc_partitions.c b/drivers/amlogic/mmc/emmc_partitions.c index c97fc5d..702030f 100644 --- a/drivers/amlogic/mmc/emmc_partitions.c +++ b/drivers/amlogic/mmc/emmc_partitions.c @@ -54,6 +54,7 @@ int amlmmc_dtb_write(struct mmc_card *card, int ret = 0, start_blk, size, blk_cnt; int bit = card->csd.read_blkbits; unsigned char *src = NULL; + unsigned char *buffer = NULL; if (len > CONFIG_DTB_SIZE) { pr_err("%s dtb data len too much", __func__); @@ -64,22 +65,34 @@ int amlmmc_dtb_write(struct mmc_card *card, ret = -EINVAL; return ret; } + + buffer = kmalloc(DTB_CELL_SIZE, GFP_KERNEL); + if (buffer == NULL) { + pr_err("%s kmalloc dtb cell failed\n", __func__); + buffer = kmalloc(DTB_CELL_SIZE, GFP_DMA); + if (buffer == NULL) { + pr_err("%s retry kmalloc dtb cell failed\n", __func__); + return -ENOMEM; + } + } start_blk >>= bit; size = CONFIG_DTB_SIZE; blk_cnt = size>>bit; - src = (unsigned char *)buf; - do { - ret = mmc_write_internal(card, start_blk, EMMC_BLOCK_SIZE, src); + src = (unsigned char *)buffer; + while (blk_cnt != 0) { + memcpy(src, buf, DTB_CELL_SIZE); + ret = mmc_write_internal(card, start_blk, (DTB_CELL_SIZE>>bit), src); if (ret) { pr_err("%s: save dtb error", __func__); ret = -EFAULT; + kfree(buffer); return ret; } - start_blk += EMMC_BLOCK_SIZE; - blk_cnt -= EMMC_BLOCK_SIZE; - src = (unsigned char *)buf + MAX_EMMC_BLOCK_SIZE; - } while (blk_cnt != 0); - + start_blk += (DTB_CELL_SIZE>>bit); + blk_cnt -= (DTB_CELL_SIZE>>bit); + buf += DTB_CELL_SIZE; + } + kfree(buffer); return ret; } @@ -89,6 +102,7 @@ int amlmmc_dtb_read(struct mmc_card *card, int ret = 0, start_blk, size, blk_cnt; int bit = card->csd.read_blkbits; unsigned char *dst = NULL; + unsigned char *buffer = NULL; if (len > CONFIG_DTB_SIZE) { pr_err("%s dtb data len too much", __func__); @@ -102,21 +116,34 @@ int amlmmc_dtb_read(struct mmc_card *card, return ret; } + buffer = kmalloc(DTB_CELL_SIZE, GFP_KERNEL); + if (buffer == NULL) { + pr_err("%s kmalloc dtb cell failed\n", __func__); + buffer = kmalloc(DTB_CELL_SIZE, GFP_DMA); + if (buffer == NULL) { + pr_err("%s retry kmalloc dtb cell failed\n", __func__); + return -ENOMEM; + } + } start_blk >>= bit; size = CONFIG_DTB_SIZE; blk_cnt = size>>bit; - dst = (unsigned char *)buf; - do { - ret = mmc_read_internal(card, start_blk, EMMC_BLOCK_SIZE, dst); + dst = (unsigned char *)buffer; + while (blk_cnt != 0) { + memset(buffer, 0x0, DTB_CELL_SIZE); + ret = mmc_read_internal(card, start_blk, (DTB_CELL_SIZE>>bit), dst); if (ret) { pr_err("%s read dtb error", __func__); ret = -EFAULT; + kfree(buffer); return ret; } - start_blk += EMMC_BLOCK_SIZE; - blk_cnt -= EMMC_BLOCK_SIZE; - dst = (unsigned char *)buf + MAX_EMMC_BLOCK_SIZE; - } while (blk_cnt != 0); + start_blk += (DTB_CELL_SIZE>>bit); + blk_cnt -= (DTB_CELL_SIZE>>bit); + memcpy(buf, dst, DTB_CELL_SIZE); + buf += DTB_CELL_SIZE; + } + kfree(buffer); return ret; } static CLASS_ATTR(emmcdtb, 0644, NULL, NULL); diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index c856425..51deb93 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -450,7 +450,7 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; mmc_part_add(card, part_size, EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, - "boot%d", idx, true, + "boot%d", idx, false, MMC_BLK_DATA_AREA_BOOT); } } diff --git a/include/linux/mmc/emmc_partitions.h b/include/linux/mmc/emmc_partitions.h index 712c9f6..aea6f69 100644 --- a/include/linux/mmc/emmc_partitions.h +++ b/include/linux/mmc/emmc_partitions.h @@ -11,6 +11,7 @@ /* #include */ /* #include */ #define CONFIG_DTB_SIZE (256*1024U) +#define DTB_CELL_SIZE (16*1024U) #define STORE_CODE 1 #define STORE_CACHE (1<<1) #define STORE_DATA (1<<2) -- 2.7.4