Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ptgen GPT improvements #37

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

mkshevetskiy
Copy link

This patch series improves GPT support by ptgen utility.
The most focus is done on specific case where primary GPT entry table placed with a gap from GPT header.
The gap is used by a vendor for bootloader code.

Also one ptgen bug was fixed.

Mikhail Kshevetskiy (5):

  • ptgen: fix protective MBR partition size
  • ptgen: do not create stab partition to fill a gap if gap caused by alignment
  • ptgen: allow non-default placement of gpt entry table
  • ptgen: allow image generation for a specified disk size
  • ptgen: create separate images for gpt data structure

@mkshevetskiy mkshevetskiy force-pushed the master branch 4 times, most recently from 8e08aca to ba6a377 Compare January 9, 2025 10:25
@Rondom
Copy link

Rondom commented Jan 9, 2025

@Ansuel This is useful for AN7581 mostly

2 << ((10 * exp) - 1) is equal to 1 << (10 * exp). This allows us
simplify a formula and remove extra if.

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
This is necessary to support large disks.

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
Creating gpt partition with ptgen results in invalid PMBR.

Steps to reproduce:
1) compile ptgen with WANT_ALTERNATE_PTABLE

   gcc -Wall -DWANT_ALTERNATE_PTABLE -o ptgen ptgen.c cyg_crc32.c

2) Create an image with ptgen

   ./ptgen -g -o s.img -p 509m

3) Investigate an image with /sbin/fdisk

   /sbin/fdisk s.img

4) fdisk reports GPT PMBR size mismatch

   Welcome to fdisk (util-linux 2.40.2).
   Changes will remain in memory only, until you decide to write them.
   Be careful before using the write command.

   GPT PMBR size mismatch (1042497 != 1042498) will be corrected by write.

   Command (m for help):

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
…ignment

ptgen tends to create stub partitions between the end of GPT entry table
and the start of the first disk. Normally fdisk/gdisk aligns partition
to 1MB boundary, so there is 2014 sectors gap before the first partition.
It is absolutely normal.

This patch somehow mimics fdisk/gdisk behavior and does NOT create stub
partition in the gap caused by alignment.

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
Usually, the primary GPT entries places in the sector 2 (next sector after
the primary GPT header). The boot ROM of some SoCs (like Airoha AN7581) on
the other hand reads the bootloader code from only one fixed offset which
overlaps with the normal position of the primary GPT entries.

This patch adds a parameter to ptgen to customise the position of the primary
GPT entries.

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
Sometimes we know an exact size of the disk and want to create a proper
disk image. This patch allows such operation.

A special case of zero disk size is supported. In this case the disk
size will be automatically calculated on the base of provided partitions
list.

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
This patch creates 2 or 3 gpt images:
 image.start: PMBR + GPT Header
 image.entry: GPT Entry Table
 image.end:   GPT Entry Table + Alternative GPT HEADER

If GPT Entry table follow GPT Header without gap, then
image.entry will be joined to the end of image.start file.

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants