Skip to content

image-hd: populate hd file size right after creating GPT header#324

Open
showier-drastic wants to merge 1 commit intopengutronix:masterfrom
showier-drastic:master
Open

image-hd: populate hd file size right after creating GPT header#324
showier-drastic wants to merge 1 commit intopengutronix:masterfrom
showier-drastic:master

Conversation

@showier-drastic
Copy link

@showier-drastic showier-drastic commented Feb 25, 2026

The current code cannot handle config file like this (this is when I only want to create a GPT partition table without any content):

image partition.img {
	hdimage {
		partition-table-type = "gpt"
		gpt-no-backup = true
	}

	partition uboot {
		offset = 4M
		size = 2M
	}
}

Error log: ERROR: hdimage(partition.img): unexpected output file size: 0 != 17408

Reason: When gpt-no-backup = true and no partition has an image file, hd->file_size was never set from its initial value of 0. This makes it impossible to create an image with only GPT header.

Fix: Initialize hd->file_size to now (= partition_end(gpt_array) = 17408) right after the primary GPT structures are set up. This ensures the file will always be at least large enough to hold the primary GPT header and partition array.

When gpt-no-backup = true and no partition has an image file, hd->file_size
was never set from its initial value of 0. This makes it impossible to
create an image with only GPT header.

Fix: Initialize hd->file_size to now (= partition_end(gpt_array) = 17408)
right after the primary GPT structures are set up. This ensures the file
will always be at least large enough to hold the primary GPT header and
partition array.
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.

1 participant