From: Dmitry Osipenko <digetx@gmail.com>
To: "Jens Axboe" <axboe@kernel.dk>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Jonathan Hunter" <jonathanh@nvidia.com>,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"David Heidelberg" <david@ixit.cz>,
"Peter Geis" <pgwipeout@gmail.com>,
"Stephen Warren" <swarren@wwwdotorg.org>,
"Nicolas Chauvet" <kwizart@gmail.com>,
"Ulf Hansson" <ulf.hansson@linaro.org>,
"Adrian Hunter" <adrian.hunter@intel.com>,
"Billy Laws" <blaws05@gmail.com>,
"Nils Östlund" <nils@naltan.com>,
"Christoph Hellwig" <hch@infradead.org>,
"Ard Biesheuvel" <ard.biesheuvel@linaro.org>,
"Davidlohr Bueso" <dave@stgolabs.net>
Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org,
Andrey Danin <danindrey@mail.ru>,
Gilles Grandou <gilles@grandou.net>,
Ryan Grachek <ryan@edited.us>,
linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
Steve McIntyre <steve@einval.com>,
Randy Dunlap <rdunlap@infradead.org>,
linux-efi <linux-efi@vger.kernel.org>
Subject: [PATCH v5 5/6] partitions/tegra: Support enforced GPT scanning
Date: Sat, 16 May 2020 18:36:43 +0300 [thread overview]
Message-ID: <20200516153644.13748-6-digetx@gmail.com> (raw)
In-Reply-To: <20200516153644.13748-1-digetx@gmail.com>
Downstream NVIDIA bootloader provides gpt_sector=<sector> kernel command
line option to the kernel. This option should instruct the GPT partition
parser to look at the specified sector for a valid GPT header if the GPT
is not found at the beginning or the end of a block device. Support of
this feature is needed by Tegra-based devices that have TegraPT and GPT
placed in inaccessible by kernel locations. The GPT entry duplicates
TegraPT partitions.
Secondly, some Tegra-based devices have bootloader that enforces the GPT
scanning of the backup/alternative GPT entry by providing "gpt" cmdline
option to the kernel, but doesn't provide the "gpt_sector" option.
In this case GPT entry resides at a special offset from the end of eMMC
storage. It is a common situation for older bootloader versions.
The offset is calculated as a total number of eMMC sectors minus number of
eMMC boot sectors minus 1. This equation is explicitly defined and used
by the downstream Tegra kernels for locating GPT entry.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
block/partitions/check.h | 1 +
block/partitions/core.c | 1 +
block/partitions/efi.c | 6 +++++
block/partitions/tegra.c | 57 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 65 insertions(+)
diff --git a/block/partitions/check.h b/block/partitions/check.h
index 55acf6340e5b..1ce445d1c7f0 100644
--- a/block/partitions/check.h
+++ b/block/partitions/check.h
@@ -68,5 +68,6 @@ int osf_partition(struct parsed_partitions *state);
int sgi_partition(struct parsed_partitions *state);
int sun_partition(struct parsed_partitions *state);
int sysv68_partition(struct parsed_partitions *state);
+int tegra_partition_forced_gpt(struct parsed_partitions *state);
int tegra_partition(struct parsed_partitions *state);
int ultrix_partition(struct parsed_partitions *state);
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 0b4720372f07..1931647d9742 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -83,6 +83,7 @@ static int (*check_part[])(struct parsed_partitions *) = {
sysv68_partition,
#endif
#ifdef CONFIG_TEGRA_PARTITION
+ tegra_partition_forced_gpt,
tegra_partition,
#endif
NULL
diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index 3af4660bc11f..4eb4496fbb1b 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -98,6 +98,12 @@ static int force_gpt;
static int __init
force_gpt_fn(char *str)
{
+ /* This check allows to parse "gpt gpt_sector=" properly since
+ * "gpt" overlaps with "gpt_sector", see tegra_gpt_sector_fn().
+ */
+ if (force_gpt)
+ return 0;
+
force_gpt = 1;
return 1;
}
diff --git a/block/partitions/tegra.c b/block/partitions/tegra.c
index d3a00ade145a..831dedb9a11c 100644
--- a/block/partitions/tegra.c
+++ b/block/partitions/tegra.c
@@ -565,3 +565,60 @@ int tegra_partition(struct parsed_partitions *state)
return ret;
}
+
+/*
+ * This allows a kernel command line option 'gpt_sector=<sector>' to
+ * enable GPT header lookup at a non-standard location. This option
+ * is provided to kernel by NVIDIA's proprietary bootloader.
+ */
+static sector_t tegra_gpt_sector;
+static int __init tegra_gpt_sector_fn(char *str)
+{
+ WARN_ON(kstrtoull(str, 10, &tegra_gpt_sector) < 0);
+ return 1;
+}
+__setup("gpt_sector=", tegra_gpt_sector_fn);
+
+int tegra_partition_forced_gpt(struct parsed_partitions *state)
+{
+ int ret = 0;
+
+#ifdef CONFIG_EFI_PARTITION
+ struct tegra_partition_table_parser ptp = {};
+
+ if (!soc_is_tegra() || !tegra_boot_sdmmc)
+ return 0;
+
+ ptp.state = state;
+
+ ptp.boot_offset = tegra_partition_table_emmc_boot_offset(&ptp);
+ if (ptp.boot_offset < 0)
+ return 0;
+
+ /*
+ * Some Tegra devices do not use gpt_sector=<sector> kernel command
+ * line option. In this case these devices usually have a GPT entry
+ * at the end of the block device and the GPT entry address is
+ * calculated this way for eMMC:
+ *
+ * gpt_sector = ext_csd.sectors_num - ext_csd.boot_sectors_num - 1
+ *
+ * This algorithm is defined and used by NVIDIA in the downstream
+ * kernel of those devices.
+ *
+ * Please note that bootloader supplies the "gpt" cmdline option
+ * which enforces the GPT scanning, meaning that the scanning will
+ * be a NO-OP on devices that do not use GPT.
+ */
+ if (tegra_gpt_sector) {
+ state->force_gpt_sector = tegra_gpt_sector;
+ } else {
+ state->force_gpt_sector = get_capacity(state->bdev->bd_disk);
+ state->force_gpt_sector -= ptp.boot_offset + 1;
+ }
+
+ ret = efi_partition(state);
+ state->force_gpt_sector = 0;
+#endif
+ return ret;
+}
--
2.26.0
next prev parent reply other threads:[~2020-05-16 15:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-16 15:36 [PATCH v5 0/6] Introduce NVIDIA Tegra Partition Table Dmitry Osipenko
2020-05-16 15:36 ` [PATCH v5 1/6] mmc: core: Add raw_boot_mult field to mmc_ext_csd Dmitry Osipenko
2020-05-16 15:36 ` [PATCH v5 2/6] mmc: block: Add mmc_bdev_to_card() helper Dmitry Osipenko
2020-05-16 15:36 ` [PATCH v5 3/6] partitions: Introduce NVIDIA Tegra Partition Table Dmitry Osipenko
2020-05-16 15:36 ` [PATCH v5 4/6] partitions/efi: Support GPT entry lookup at a non-standard location Dmitry Osipenko
2020-05-16 15:51 ` Randy Dunlap
2020-05-16 16:50 ` Dmitry Osipenko
2020-05-16 16:58 ` Randy Dunlap
2020-05-17 0:11 ` Dmitry Osipenko
2020-05-17 2:07 ` Randy Dunlap
2020-05-16 15:36 ` Dmitry Osipenko [this message]
2020-05-16 15:52 ` [PATCH v5 5/6] partitions/tegra: Support enforced GPT scanning Randy Dunlap
2020-05-16 15:36 ` [PATCH v5 6/6] soc/tegra: Expose Boot Configuration Table via sysfs Dmitry Osipenko
2020-05-18 7:45 ` Michał Mirosław
2020-05-18 8:00 ` Dmitry Osipenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200516153644.13748-6-digetx@gmail.com \
--to=digetx@gmail.com \
--cc=adrian.hunter@intel.com \
--cc=ard.biesheuvel@linaro.org \
--cc=axboe@kernel.dk \
--cc=blaws05@gmail.com \
--cc=danindrey@mail.ru \
--cc=dave@stgolabs.net \
--cc=david@ixit.cz \
--cc=gilles@grandou.net \
--cc=hch@infradead.org \
--cc=jonathanh@nvidia.com \
--cc=kwizart@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mirq-linux@rere.qmqm.pl \
--cc=nils@naltan.com \
--cc=pgwipeout@gmail.com \
--cc=rdunlap@infradead.org \
--cc=ryan@edited.us \
--cc=steve@einval.com \
--cc=swarren@wwwdotorg.org \
--cc=thierry.reding@gmail.com \
--cc=ulf.hansson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).