From cce54a1f6b47eb5bb0e1e837bc51f4b61da4864c Mon Sep 17 00:00:00 2001 From: Dongjin Kim Date: Thu, 26 Jul 2018 22:56:12 +0900 Subject: [PATCH] ODROID-COMMON: mmc: read MPT partition from a certain sector Change-Id: Ibac5bb733270583f1a3a2ee7a24091c453261753 Signed-off-by: Dongjin Kim --- drivers/amlogic/Kconfig | 2 ++ drivers/amlogic/Makefile | 2 ++ drivers/amlogic/mmc/emmc_partitions.c | 33 ++++++++++++++++++++++++------ drivers/mmc/card/block.c | 38 +++++++++++++++++++++++++++++++++-- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/drivers/amlogic/Kconfig b/drivers/amlogic/Kconfig index 914146f..c7dde84 100644 --- a/drivers/amlogic/Kconfig +++ b/drivers/amlogic/Kconfig @@ -148,5 +148,7 @@ source "drivers/amlogic/pixel_probe/Kconfig" source "drivers/amlogic/firmware/Kconfig" +source "drivers/amlogic/media_modules/Kconfig" + endmenu endif diff --git a/drivers/amlogic/Makefile b/drivers/amlogic/Makefile index d2686b8..6fd4bc5 100644 --- a/drivers/amlogic/Makefile +++ b/drivers/amlogic/Makefile @@ -145,3 +145,5 @@ obj-$(CONFIG_AMLOGIC_IRCUT) += ircut/ obj-$(CONFIG_AMLOGIC_PIXEL_PROBE) += pixel_probe/ obj-$(CONFIG_AMLOGIC_FIRMWARE) += firmware/ + +obj-y += media_modules/ diff --git a/drivers/amlogic/mmc/emmc_partitions.c b/drivers/amlogic/mmc/emmc_partitions.c index b2bf502..12b11e5 100644 --- a/drivers/amlogic/mmc/emmc_partitions.c +++ b/drivers/amlogic/mmc/emmc_partitions.c @@ -716,12 +716,17 @@ static int mmc_read_partition_tbl(struct mmc_card *card, memset(pt_fmt, 0, sizeof(struct mmc_partitions_fmt)); memset(buf, 0, blk_size); +#if defined(CONFIG_ARCH_MESON64_ODROID_COMMON) + /* LBA unit */ + start_blk = 2048; +#else start_blk = get_reserve_partition_off(card); if (start_blk < 0) { ret = -EINVAL; goto exit_err; } start_blk >>= bit; +#endif size = sizeof(struct mmc_partitions_fmt); dst = (char *)pt_fmt; if (size >= blk_size) { @@ -929,22 +934,38 @@ static int add_emmc_partition(struct gendisk *disk, uint64_t offset, size, cap; struct partitions *pp; struct proc_dir_entry *proc_card; +#if defined(CONFIG_ARCH_MESON64_ODROID_COMMON) + int shift = 0; +#else + int shift = 9; +#endif + int partno = 1; pr_info("add_emmc_partition\n"); cap = get_capacity(disk); /* unit:512 bytes */ for (i = 0; i < pt_fmt->part_num; i++) { pp = &(pt_fmt->partitions[i]); - offset = pp->offset >> 9; /* unit:512 bytes */ - size = pp->size >> 9; /* unit:512 bytes */ +#if defined(CONFIG_ARCH_MESON64_ODROID_COMMON) + if (pp->name[0] == '@') { + /* It's hiden partition */ + continue; + } +#endif + + offset = pp->offset >> shift; /* unit:512 bytes */ + size = pp->size >> shift; /* unit:512 bytes */ if ((offset + size) <= cap) { - ret = add_emmc_each_part(disk, 1+i, offset, + ret = add_emmc_each_part(disk, partno, offset, size, 0, pp->name); pr_info("[%sp%02d] %20s offset 0x%012llx, size 0x%012llx %s\n", - disk->disk_name, 1+i, - pp->name, offset<<9, - size<<9, IS_ERR(ret) ? "add fail":""); + disk->disk_name, partno, + pp->name, offset<disk_name); diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 7774489..fcd27b8 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -3017,6 +3017,38 @@ static const struct mmc_fixup blk_fixups[] = END_FIXUP }; +#ifdef CONFIG_AMLOGIC_MMC +static int mmc_validate_mpt_partition(struct mmc_card *card) +{ + char *buf; + int ret; + + /* check only if 'card' is eMMC device */ + if (strcmp(mmc_hostname(card->host), "emmc")) + return -EINVAL; + + buf = (char*)kmalloc(1 << card->csd.read_blkbits, GFP_KERNEL); + if (buf == NULL) + return -ENOMEM; + + mmc_claim_host(card->host); + + /* FIXME: fix up the magic number for start block to check MPT partition */ + ret = mmc_read_internal(card, 8184, 1, buf); + if (ret == 0) { + if (strncmp(buf, MMC_PARTITIONS_MAGIC, + sizeof(((struct mmc_partitions_fmt*)0)->magic)) != 0) { + ret = -EINVAL; + } + } + + mmc_release_host(card->host); + + kfree(buf); + return ret; +} +#endif + static int mmc_blk_probe(struct mmc_card *card) { struct mmc_blk_data *md, *part_md; @@ -3049,8 +3081,10 @@ static int mmc_blk_probe(struct mmc_card *card) goto out; #ifdef CONFIG_AMLOGIC_MMC - /* amlogic add emmc partitions ops */ - aml_emmc_partition_ops(card, md->disk); + if (mmc_validate_mpt_partition(card) == 0) { + /* amlogic add emmc partitions ops */ + aml_emmc_partition_ops(card, md->disk); + } #endif list_for_each_entry(part_md, &md->part, part) { -- 2.7.4