diff mbox

[U-Boot,1/4] part: efi: Fix offset

Message ID 20170823140133.1506-1-maxime.ripard@free-electrons.com
State Accepted
Commit 89d33a2c0dce785b8c503399db91eec520def249
Delegated to: Tom Rini
Headers show

Commit Message

Maxime Ripard Aug. 23, 2017, 2:01 p.m. UTC
Both the config option and the DT options specify the offset to set the GPT
at in bytes, yet the code treats those values as block numbers.

Fix that.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 disk/part_efi.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Tom Rini Aug. 25, 2017, 1:05 a.m. UTC | #1
On Wed, Aug 23, 2017 at 04:01:30PM +0200, Maxime Ripard wrote:

> Both the config option and the DT options specify the offset to set the GPT
> at in bytes, yet the code treats those values as block numbers.
> 
> Fix that.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Philipp Tomsich Aug. 25, 2017, 11:39 a.m. UTC | #2
> On 23 Aug 2017, at 16:01, Maxime Ripard <maxime.ripard@free-electrons.com> wrote:
> 
> Both the config option and the DT options specify the offset to set the GPT
> at in bytes, yet the code treats those values as block numbers.
> 
> Fix that.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Maxime Ripard Aug. 28, 2017, 7:01 a.m. UTC | #3
Hi Tom,

On Thu, Aug 24, 2017 at 09:05:06PM -0400, Tom Rini wrote:
> On Wed, Aug 23, 2017 at 04:01:30PM +0200, Maxime Ripard wrote:
> 
> > Both the config option and the DT options specify the offset to set the GPT
> > at in bytes, yet the code treats those values as block numbers.
> > 
> > Fix that.
> > 
> > Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> 
> Reviewed-by: Tom Rini <trini@konsulko.com>

I think that patch should be in the next release, as this option is
unusable (or at least in the way it's documented) without it.

Maxime
Tom Rini Sept. 4, 2017, 12:41 a.m. UTC | #4
On Wed, Aug 23, 2017 at 04:01:30PM +0200, Maxime Ripard wrote:

> Both the config option and the DT options specify the offset to set the GPT
> at in bytes, yet the code treats those values as block numbers.
> 
> Fix that.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 71c3cb3f78d9..75d0a78f0a1f 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -534,6 +534,7 @@  int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
 static uint32_t partition_entries_offset(struct blk_desc *dev_desc)
 {
 	uint32_t offset_blks = 2;
+	uint32_t __maybe_unused offset_bytes;
 	int __maybe_unused config_offset;
 
 #if defined(CONFIG_EFI_PARTITION_ENTRIES_OFF)
@@ -545,8 +546,9 @@  static uint32_t partition_entries_offset(struct blk_desc *dev_desc)
 	 * the disk) for the entries can be set in
 	 * CONFIG_EFI_PARTITION_ENTRIES_OFF.
 	 */
-	offset_blks =
+	offset_bytes =
 		PAD_TO_BLOCKSIZE(CONFIG_EFI_PARTITION_ENTRIES_OFF, dev_desc);
+	offset_blks = offset_bytes / dev_desc->blksz;
 #endif
 
 #if defined(CONFIG_OF_CONTROL)
@@ -558,8 +560,10 @@  static uint32_t partition_entries_offset(struct blk_desc *dev_desc)
 	config_offset = fdtdec_get_config_int(gd->fdt_blob,
 					      "u-boot,efi-partition-entries-offset",
 					      -EINVAL);
-	if (config_offset != -EINVAL)
-		offset_blks = PAD_TO_BLOCKSIZE(config_offset, dev_desc);
+	if (config_offset != -EINVAL) {
+		offset_bytes = PAD_TO_BLOCKSIZE(config_offset, dev_desc);
+		offset_blks = offset_bytes / dev_desc->blksz;
+	}
 #endif
 
 	debug("efi: partition entries offset (in blocks): %d\n", offset_blks);