[coreboot-gerrit] Change in coreboot[master]: util/cbfstool: Add bzImage header detection

Patrick Rudolph (Code Review) gerrit at coreboot.org
Mon Feb 26 12:15:46 CET 2018


Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/23868


Change subject: util/cbfstool: Add bzImage header detection
......................................................................

util/cbfstool: Add bzImage header detection

Only handle payload as bzImage if it looks like one.

Change-Id: I9fc96caedb872b14f3238e4a7a96f0d32d17f7ee
Signed-off-by: Patrick Rudolph <patrick.rudolph at 9elements.com>
---
M util/cbfstool/cbfs-payload-linux.c
M util/cbfstool/cbfstool.c
M util/cbfstool/common.h
3 files changed, 46 insertions(+), 1 deletion(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/68/23868/1

diff --git a/util/cbfstool/cbfs-payload-linux.c b/util/cbfstool/cbfs-payload-linux.c
index 9646384..17e18ca 100644
--- a/util/cbfstool/cbfs-payload-linux.c
+++ b/util/cbfstool/cbfs-payload-linux.c
@@ -50,6 +50,49 @@
 	struct cbfs_payload_segment *out_seg;
 };
 
+/** bzImage boot flag value */
+#define BZI_BOOT_FLAG 0xaa55
+
+/** bzImage magic signature value */
+#define BZI_SIGNATURE 0x53726448
+
+struct bzimage_header {
+	/** The size of the setup in sectors
+	 *
+	 * If this field contains 0, assume it contains 4.
+	 */
+	uint8_t setup_sects;
+	/** If set, the root is mounted readonly */
+	uint16_t root_flags;
+	/** DO NOT USE - for bootsect.S use only */
+	uint16_t syssize;
+	/** DO NOT USE - obsolete */
+	uint16_t swap_dev;
+	/** DO NOT USE - for bootsect.S use only */
+	uint16_t ram_size;
+	/** Video mode control */
+	uint16_t vid_mode;
+	/** Default root device number */
+	uint16_t root_dev;
+	/** 0xAA55 magic number */
+	uint16_t boot_flag;
+	/** Jump instruction */
+	uint16_t jump;
+	/** Magic signature "HdrS" */
+	uint32_t header;
+};
+
+/* Return true if buffer looks like a bzImage */
+int probe_for_bzImage_header(const struct buffer *input)
+{
+	const struct bzimage_header *header =
+	    (const struct bzimage_header *)input->data;
+	if (input->size < sizeof(*header))
+		return 0;
+	return (header->boot_flag == BZI_BOOT_FLAG) &&
+	       (header->header == BZI_SIGNATURE);
+}
+
 static int bzp_init(struct bzpayload *bzp, enum comp_algo algo)
 {
 	memset(bzp, 0, sizeof(*bzp));
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 1f71906..91b0290 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -636,7 +636,7 @@
 		ret = parse_fv_to_payload(buffer, &output, param.compression);
 
 	/* If it's neither ELF nor UEFI Fv, try bzImage */
-	if (ret != 0)
+	if (ret != 0 && probe_for_bzImage_header(buffer))
 		ret = parse_bzImage_to_payload(buffer, &output,
 				param.initrd, param.cmdline, param.compression);
 
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index 85dfdeb..6e366a1 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -188,6 +188,8 @@
 			 enum comp_algo algo);
 int parse_fv_to_payload(const struct buffer *input, struct buffer *output,
 			enum comp_algo algo);
+
+int probe_for_bzImage_header(const struct buffer *input);
 int parse_bzImage_to_payload(const struct buffer *input,
 			     struct buffer *output, const char *initrd,
 			     char *cmdline, enum comp_algo algo);

-- 
To view, visit https://review.coreboot.org/23868
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9fc96caedb872b14f3238e4a7a96f0d32d17f7ee
Gerrit-Change-Number: 23868
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <patrick.rudolph at 9elements.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180226/9a48027a/attachment.html>


More information about the coreboot-gerrit mailing list