patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Alyssa Ross <hi@alyssa.is>
To: devel@spectrum-os.org
Cc: Yuriy Nesterov <yuriy.nesterov@unikie.com>,
	Ville Ilvonen <ville.ilvonen@unikie.com>
Subject: [PATCH] scripts/make-gpt.sh: reserve 8 MiB at start of GPT
Date: Fri, 26 Aug 2022 13:09:25 +0000	[thread overview]
Message-ID: <20220826130923.1840670-1-hi@alyssa.is> (raw)

In some cases (e.g. a product built on Spectrum where updates to both
firmware and OS are delivered by the same vendor), it makes sense to
include firmware in the same image as the OS.  This firmware tends to
live in the start of the image, after the GPT header.  (The exact
location varies by board.)

The 1 MiB reserved by sfdisk by default is not enough for this.  The
conventional value seems to be 8 MiB.  On NixOS, this is configurable
with the sdImage.firmwarePartitionOffset option, but this defaults to
8 MiB and I wasn't able to find any examples in searches on DuckDuckGo
and GitHub of anybody using any other value, so it looks like 8 MiB is
broadly acceptable.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
Yuriy, if you'd like to test this patch, here's some documentation
about how to do that. :)

https://spectrum-os.org/doc/testing-patches.html

 scripts/make-gpt.sh | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/scripts/make-gpt.sh b/scripts/make-gpt.sh
index 56076d3..55f38d6 100755
--- a/scripts/make-gpt.sh
+++ b/scripts/make-gpt.sh
@@ -1,12 +1,13 @@
 #!/bin/sh -eu
 #
 # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2022 Unikie
 # SPDX-License-Identifier: EUPL-1.2+
 #
 # usage: make-gpt.sh GPT_PATH PATH:PARTTYPE[:PARTUUID]...
 
 ONE_MiB=1048576
-TWO_MiB=2097152
+NINE_MiB=9437184
 
 # Prints the number of 1MiB blocks required to store the file named
 # $1.  We use 1MiB blocks because that's what sfdisk uses for
@@ -41,8 +42,9 @@ shift
 nl=$'\n'
 table="label: gpt"
 
-# Keep 1MiB free at the start, and 1MiB free at the end.
-gptBytes=$TWO_MiB
+# Keep 8MiB free at the start (to provide space for firmware if
+# required), and 1MiB free at the end.
+gptBytes=$NINE_MiB
 for partition; do
 	sizeMiB="$(sizeMiB "$(partitionPath "$partition")")"
 	table="$table${nl}size=${sizeMiB}MiB,$(awk -f "$scriptsDir/sfdisk-field.awk" -v partition="$partition")"
@@ -52,6 +54,7 @@ done
 rm -f "$out"
 truncate -s "$gptBytes" "$out"
 sfdisk "$out" <<EOF
+first-lba: 16384
 $table
 EOF
 
-- 
2.37.1



             reply	other threads:[~2022-08-26 13:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26 13:09 Alyssa Ross [this message]
2022-08-28 16:49 ` [PATCH] scripts/make-gpt.sh: reserve 8 MiB at start of GPT Alyssa Ross
2022-09-26 15:06 ` Ville Ilvonen

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=20220826130923.1840670-1-hi@alyssa.is \
    --to=hi@alyssa.is \
    --cc=devel@spectrum-os.org \
    --cc=ville.ilvonen@unikie.com \
    --cc=yuriy.nesterov@unikie.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

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).