Support EFI partition on NVIDIA Tegra devices
Subsystems (6)
v7 cover Support EFI partition on NVIDIA Tegra devices
This series adds the most minimal EFI partition support for NVIDIA Tegra consumer devices, like Android tablets and game consoles, making theirs eMMC accessible out-of-the-box using downstream bootloader and mainline Linux kernel. eMMC now works on Acer A500 tablet and Ouya game console that are already well supported in mainline and internal storage is the only biggest thing left to support.
Changelog:
v7: - Added r-b from Christoph Hellwig.
- Added ack from Davidlohr Bueso.
- Renamed MMC_CAP2_ALT_GPT_SECTOR to MMC_CAP2_ALT_GPT_TEGRA, like it was suggested by Ulf Hansson and Thierry Reding.
- Squashed MMC raw_boot_mult patch into alternative_gpt_sector() since both now belong to MMC core and it's cleaner to have them in a single change.
v6: - Added comment for the alternative_gpt_sector() callback, which
was asked by Christoph Hellwig.
- Changed alternative_gpt_sector() to take disk for the argument instead of blkdev. This was asked by Christoph Hellwig.
- Dropped mmc_bdops check as it was suggested by Christoph Hellwig.
- Added missing mmc_blk_put() that was spotted by Christoph Hellwig.
- Moved GPT calculation into MMC core and added MMC_CAP2_ALT_GPT_SECTOR flag, like it was asked by Ulf Hansson. Me and Thierry have concerns about whether it's better to have Tegra-specific function in a core instead of Tegra driver, but it also works, so I decided to try that variant.
v5: - Implemented alternative_gpt_sector() blk/mmc callback that was
suggested by Christoph Hellwig in a comment to v4.
- mmc_bdev_to_card() now checks blk fops instead of the major number, like it was suggested by Christoph Hellwig in a comment to v4.
- Emailed Rob Herring, which was asked by Ulf Hansson in a comment to v4. Although the of-match change is gone now in v5, the matching is transformed into the new SDHCI quirk of the Tegra driver.
v4: - Rebased on top of recent linux-next.
v3: - Removed unnecessary v1 hunk that was left by accident in efi.c of v2.
v2: - This is continuation of [1] where Davidlohr Bueso suggested that it
should be better to avoid supporting in mainline the custom gpt_sector kernel cmdline parameter that downstream Android kernels use. We can do this for the devices that are already mainlined, so I dropped the cmdline from the v2 and left only the variant with a fixed GPT address.
[1] https://lore.kernel.org/linux-efi/[email protected]/T/
Dmitry Osipenko (4):
block: Add alternative_gpt_sector() operation partitions/efi: Support non-standard GPT location
mmc: block: Support alternative_gpt_sector() operation
mmc: sdhci-tegra: Enable MMC_CAP2_ALT_GPT_TEGRA
block/partitions/efi.c | 12 ++++++++++++ drivers/mmc/core/block.c | 21 ++++++++++++++++++++ drivers/mmc/core/core.c | 35 ++++++++++++++++++++++++++++++++++ drivers/mmc/core/core.h | 2 ++ drivers/mmc/core/mmc.c | 2 ++ drivers/mmc/host/sdhci-tegra.c | 9 +++++++++ include/linux/blkdev.h | 7 +++++++ include/linux/mmc/card.h | 1 + include/linux/mmc/host.h | 1 + 9 files changed, 90 insertions(+)
Signature · 1 line
2.32.0
PATCH v7 1/4 block: Add alternative_gpt_sector() operation
Add alternative_gpt_sector() block device operation which specifies alternative location of a GPT entry. This allows us to support Android devices that have GPT entry at a non-standard location and can't be repartitioned easily.
--- include/linux/blkdev.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/blkdev.h +7 -0
@@ -1850,6 +1850,13 @@ struct block_device_operations {char *(*devnode)(struct gendisk *disk,umode_t *mode);struct module *owner;const struct pr_ops *pr_ops; + +/* +* Special callback for probing GPT entry at a given sector. +* Needed by Android devices, used by GPT scanner and MMC blk +* driver. +*/ +int (*alternative_gpt_sector)(struct gendisk *disk,sector_t *sector); };#ifdef CONFIG_COMPAT
Signature · 1 line
2.32.0
PATCH v7 2/4 partitions/efi: Support non-standard GPT location
In reply to Dmitry OsipenkoSupport looking up GPT at a non-standard location specified by a block device driver.
--- block/partitions/efi.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
block/partitions/efi.c +12 -0
@@ -585,6 +585,8 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,gpt_header *pgpt =NULL , *agpt =NULL ;gpt_entry *pptes =NULL , *aptes =NULL ;legacy_mbr *legacymbr; +struct gendisk *disk = state->disk; +const struct block_device_operations *fops = disk->fops;sector_t total_sectors =get_capacity (state->disk);u64 lastlba;
@@ -619,6 +621,16 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,if (!good_agpt && force_gpt) good_agpt =is_gpt_valid (state, lastlba, &agpt, &aptes); +if (!good_agpt && force_gpt && fops->alternative_gpt_sector) { +sector_t agpt_sector; +int err; + + err = fops->alternative_gpt_sector (disk, &agpt_sector); +if (!err) + good_agpt =is_gpt_valid (state, agpt_sector, + &agpt, &aptes); + } +/* The obviously unsuccessful case */ if (!good_pgpt && !good_agpt) goto fail;
Signature · 1 line
2.32.0
PATCH v7 3/4 mmc: block: Support alternative_gpt_sector() operation
In reply to Dmitry OsipenkoSupport generic alternative_gpt_sector() block device operation. It calculates location of GPT entry for eMMC of NVIDIA Tegra Android devices. Add new MMC_CAP2_ALT_GPT_TEGRA flag that enables scanning of alternative GPT sector and add raw_boot_mult field to mmc_ext_csd which allows to get size of the boot partitions that is needed for the calculation.
--- drivers/mmc/core/block.c | 21 +++++++++++++++++++++ drivers/mmc/core/core.c | 35 +++++++++++++++++++++++++++++++++++ drivers/mmc/core/core.h | 2 ++ drivers/mmc/core/mmc.c | 2 ++ include/linux/mmc/card.h | 1 + include/linux/mmc/host.h | 1 + 6 files changed, 62 insertions(+)
drivers/mmc/core/block.c +21 -0
@@ -801,6 +801,26 @@ static int mmc_blk_compat_ioctl(struct block_device *bdev, fmode_t mode, }#endif +static int mmc_blk_alternative_gpt_sector (struct gendisk *disk, +sector_t *sector) +{ +struct mmc_blk_data *md; +int ret; + + md =mmc_blk_get (disk); +if (!md) +return -EINVAL ; + +if (md->queue.card) + ret =mmc_card_alternative_gpt_sector (md->queue.card, sector); +else + ret = -ENODEV ; + +mmc_blk_put (md); + +return ret; +} +static const struct block_device_operations mmc_bdops = { .open = mmc_blk_open, .release = mmc_blk_release,
@@ -810,6 +830,7 @@ static const struct block_device_operations mmc_bdops = {#ifdef CONFIG_COMPAT .compat_ioctl = mmc_blk_compat_ioctl, #endif + .alternative_gpt_sector = mmc_blk_alternative_gpt_sector, }; static int mmc_blk_part_switch_pre(struct mmc_card *card,
drivers/mmc/core/core.c +35 -0
@@ -2150,6 +2150,41 @@ int mmc_detect_card_removed(struct mmc_host *host) }EXPORT_SYMBOL (mmc_detect_card_removed); +int mmc_card_alternative_gpt_sector (struct mmc_card *card,sector_t *gpt_sector) +{ +unsigned int boot_sectors_num; + +if ((!(card->host->caps2 &MMC_CAP2_ALT_GPT_TEGRA ))) +return -EOPNOTSUPP ; + +/* filter out unrelated cards */ +if (card->ext_csd.rev <3 || + !mmc_card_mmc (card) || + !mmc_card_is_blockaddr (card) || +mmc_card_is_removable (card->host)) +return -ENOENT ; + +/* +* eMMC storage has two special boot partitions in addition to the +* main one. NVIDIA's bootloader linearizes eMMC boot0->boot1->main +* accesses, this means that the partition table addresses are shifted +* by the size of boot partitions. In accordance with the eMMC +* specification, the boot partition size is calculated as follows: +* +* boot partition size = 128K byte x BOOT_SIZE_MULT +* +* Calculate number of sectors occupied by the both boot partitions. +*/ + boot_sectors_num = card->ext_csd.raw_boot_mult *SZ_128K / +SZ_512 *MMC_NUM_BOOT_PARTITION ; + +/* Defined by NVIDIA and used by Android devices. */ + *gpt_sector = card->ext_csd.sectors - boot_sectors_num -1 ; + +return 0 ; +} +EXPORT_SYMBOL (mmc_card_alternative_gpt_sector); +void mmc_rescan (struct work_struct *work) { struct mmc_host *host =
drivers/mmc/core/core.h +2 -0
@@ -119,6 +119,8 @@ void mmc_release_host(struct mmc_host *host);void mmc_get_card (struct mmc_card *card,struct mmc_ctx *ctx);void mmc_put_card (struct mmc_card *card,struct mmc_ctx *ctx); +int mmc_card_alternative_gpt_sector (struct mmc_card *card,sector_t *sector); +/** * mmc_claim_host - exclusively claim a host * @host: mmc host to claim
drivers/mmc/core/mmc.c +2 -0
@@ -418,6 +418,8 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT ]; card->ext_csd.raw_hc_erase_grp_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE ]; + card->ext_csd.raw_boot_mult = + ext_csd[EXT_CSD_BOOT_MULT ];if (card->ext_csd.rev >=3 ) {u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT ]; card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG ];
include/linux/mmc/card.h +1 -0
@@ -109,6 +109,7 @@ struct mmc_ext_csd {u8 raw_hc_erase_gap_size;/* 221 */ u8 raw_erase_timeout_mult;/* 223 */ u8 raw_hc_erase_grp_size;/* 224 */ +u8 raw_boot_mult;/* 226 */ u8 raw_sec_trim_mult;/* 229 */ u8 raw_sec_erase_mult;/* 230 */ u8 raw_sec_feature_support;/* 231 */
include/linux/mmc/host.h +1 -0
@@ -398,6 +398,7 @@ struct mmc_host {#else #define MMC_CAP2_CRYPTO 0#endif +#define MMC_CAP2_ALT_GPT_TEGRA (1 << 28)/* Host with eMMC that has GPT entry at a non-standard location */ int fixed_drv_type;/* fixed driver type for non-removable media */
Signature · 1 line
2.32.0
PATCH v7 4/4 mmc: sdhci-tegra: Enable MMC_CAP2_ALT_GPT_TEGRA
In reply to Dmitry OsipenkoTegra20/30/114/124 Android devices place GPT at a non-standard location. Enable GPT entry scanning at that location.
--- drivers/mmc/host/sdhci-tegra.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/mmc/host/sdhci-tegra.c +9 -0
@@ -116,6 +116,8 @@*/ #define NVQUIRK_HAS_TMCLK BIT(10) +#define NVQUIRK_HAS_ANDROID_GPT_SECTOR BIT(11) +/* SDMMC CQE Base Address for Tegra Host Ver 4.1 and Higher */ #define SDHCI_TEGRA_CQE_BASE_ADDR 0xF000
@@ -1361,6 +1363,7 @@ static const struct sdhci_tegra_soc_data soc_data_tegra20 = { .pdata = &sdhci_tegra20_pdata, .dma_mask = DMA_BIT_MASK(32), .nvquirks =NVQUIRK_FORCE_SDHCI_SPEC_200 | +NVQUIRK_HAS_ANDROID_GPT_SECTOR | NVQUIRK_ENABLE_BLOCK_GAP_DET, };
@@ -1390,6 +1393,7 @@ static const struct sdhci_tegra_soc_data soc_data_tegra30 = { .nvquirks = NVQUIRK_ENABLE_SDHCI_SPEC_300 |NVQUIRK_ENABLE_SDR50 |NVQUIRK_ENABLE_SDR104 | +NVQUIRK_HAS_ANDROID_GPT_SECTOR | NVQUIRK_HAS_PADCALIB, };
@@ -1422,6 +1426,7 @@ static const struct sdhci_pltfm_data sdhci_tegra114_pdata = {static const struct sdhci_tegra_soc_data soc_data_tegra114 = { .pdata = &sdhci_tegra114_pdata, .dma_mask =DMA_BIT_MASK (32 ), + .nvquirks =NVQUIRK_HAS_ANDROID_GPT_SECTOR , };static const struct sdhci_pltfm_data sdhci_tegra124_pdata = {
@@ -1438,6 +1443,7 @@ static const struct sdhci_pltfm_data sdhci_tegra124_pdata = {static const struct sdhci_tegra_soc_data soc_data_tegra124 = { .pdata = &sdhci_tegra124_pdata, .dma_mask =DMA_BIT_MASK (34 ), + .nvquirks =NVQUIRK_HAS_ANDROID_GPT_SECTOR , };static const struct sdhci_ops tegra210_sdhci_ops = {
@@ -1616,6 +1622,9 @@ static int sdhci_tegra_probe(struct platform_device *pdev) tegra_host->pad_control_available = false; tegra_host->soc_data = soc_data; +if (soc_data->nvquirks &NVQUIRK_HAS_ANDROID_GPT_SECTOR ) + host->mmc->caps2 |=MMC_CAP2_ALT_GPT_TEGRA ; +if (soc_data->nvquirks &NVQUIRK_NEEDS_PAD_CONTROL ) { rc =tegra_sdhci_init_pinctrl_info (&pdev->dev, tegra_host);if (rc ==0 )
Signature · 1 line
2.32.0
Re: [PATCH v7 4/4] mmc: sdhci-tegra: Enable MMC_CAP2_ALT_GPT_TEGRA
Quoted 13 lines · Dmitry Osipenko
Tegra20/30/114/124 Android devices place GPT at a non-standard location. Enable GPT entry scanning at that location.
Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/mmc/host/sdhci-tegra.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/mmc/host/sdhci-tegra.c +0
-0
drivers/mmc/host/sdhci-tegra.c line 119
Quoted 4 lines
drivers/mmc/host/sdhci-tegra.c +1
-0@@ -116,6 +116,8 @@*/ #define NVQUIRK_HAS_TMCLK BIT(10) +#define NVQUIRK_HAS_ANDROID_GPT_SECTOR BIT(11)
_HAS_ could be taken to imply that it always has that GPT sector, whereas it really depends on how the system was flashed. But that's a bit pedantic, so I think this is okay:
Quoted 12 lines · Dmitry Osipenko
This series adds the most minimal EFI partition support for NVIDIA Tegra consumer devices, like Android tablets and game consoles, making theirs eMMC accessible out-of-the-box using downstream bootloader and mainline Linux kernel. eMMC now works on Acer A500 tablet and Ouya game console that are already well supported in mainline and internal storage is the only biggest thing left to support.
Changelog:
v7: - Added r-b from Christoph Hellwig.
Quoted 8 lines
- Added ack from Davidlohr Bueso.
- Renamed
MMC_CAP2_ALT_GPT_SECTORtoMMC_CAP2_ALT_GPT_TEGRA, like it was suggested by Ulf Hansson and Thierry Reding.- Squashed MMC
raw_boot_multpatch intoalternative_gpt_sector()since both now belong to MMC core and it's cleaner to have them in a single change.
Jens, these changes looks good to me. If you have no objections, feel free to queue them via your tree (I don't think there will be any conflicts with my mmc tree).
For the series:
Kind regards
Uffe
Quoted 59 lines
v6: - Added comment for the
alternative_gpt_sector()callback, which
was asked by Christoph Hellwig.- Changed
alternative_gpt_sector()to take disk for the argument instead of blkdev. This was asked by Christoph Hellwig.- Dropped
mmc_bdopscheck as it was suggested by Christoph Hellwig.- Added missing
mmc_blk_put()that was spotted by Christoph Hellwig.- Moved GPT calculation into MMC core and added
MMC_CAP2_ALT_GPT_SECTORflag, like it was asked by Ulf Hansson. Me and Thierry have concerns about whether it's better to have Tegra-specific function in a core instead of Tegra driver, but it also works, so I decided to try that variant.v5: - Implemented
alternative_gpt_sector()blk/mmc callback that was
suggested by Christoph Hellwig in a comment to v4.-
mmc_bdev_to_card()now checks blk fops instead of the major number, like it was suggested by Christoph Hellwig in a comment to v4.- Emailed Rob Herring, which was asked by Ulf Hansson in a comment to v4. Although the of-match change is gone now in v5, the matching is transformed into the new SDHCI quirk of the Tegra driver.
v4: - Rebased on top of recent linux-next.
v3: - Removed unnecessary v1 hunk that was left by accident in
efi.cof v2.v2: - This is continuation of [1] where Davidlohr Bueso suggested that it
should be better to avoid supporting in mainline the customgpt_sectorkernel cmdline parameter that downstream Android kernels use. We can do this for the devices that are already mainlined, so I dropped the cmdline from the v2 and left only the variant with a fixed GPT address.[1] https://lore.kernel.org/linux-efi/[email protected]/T/
Dmitry Osipenko (4):
block: Addalternative_gpt_sector()operation partitions/efi: Support non-standard GPT location
mmc: block: Supportalternative_gpt_sector()operation
mmc: sdhci-tegra: EnableMMC_CAP2_ALT_GPT_TEGRAblock/partitions/efi.c | 12 ++++++++++++ drivers/mmc/core/block.c | 21 ++++++++++++++++++++ drivers/mmc/core/core.c | 35 ++++++++++++++++++++++++++++++++++ drivers/mmc/core/core.h | 2 ++ drivers/mmc/core/mmc.c | 2 ++ drivers/mmc/host/sdhci-tegra.c | 9 +++++++++ include/linux/blkdev.h | 7 +++++++ include/linux/mmc/card.h | 1 + include/linux/mmc/host.h | 1 + 9 files changed, 90 insertions(+)--
2.32.0
Jens Axboe
maintainerQuoted 22 lines · Ulf Hansson
Quoted 12 lines · Dmitry Osipenko
This series adds the most minimal EFI partition support for NVIDIA Tegra consumer devices, like Android tablets and game consoles, making theirs eMMC accessible out-of-the-box using downstream bootloader and mainline Linux kernel. eMMC now works on Acer A500 tablet and Ouya game console that are already well supported in mainline and internal storage is the only biggest thing left to support.
Changelog:
v7: - Added r-b from Christoph Hellwig.
Quoted 8 lines
- Added ack from Davidlohr Bueso.
- Renamed
MMC_CAP2_ALT_GPT_SECTORtoMMC_CAP2_ALT_GPT_TEGRA, like it was suggested by Ulf Hansson and Thierry Reding.- Squashed MMC
raw_boot_multpatch intoalternative_gpt_sector()since both now belong to MMC core and it's cleaner to have them in a single change.
Quoted 6 lines
Jens, these changes looks good to me. If you have no objections, feel free to queue them via your tree (I don't think there will be any conflicts with my mmc tree).
For the series:
Reviewed-by Ulf Hansson <[email protected]>
Added and queued up, thanks everyone.
Signature · 1 line
Jens Axboe