Module Name:    src
Committed By:   nonaka
Date:           Tue Jan 24 11:22:43 UTC 2017

Modified Files:
        src/usr.sbin/makefs: cd9660.c makefs.8
        src/usr.sbin/makefs/cd9660: cd9660_eltorito.c cd9660_eltorito.h

Log Message:
makefs(8): add cd9660 eltorito-alt-boot option for EFI boot.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/usr.sbin/makefs/cd9660.c
cvs rdiff -u -r1.57 -r1.58 src/usr.sbin/makefs/makefs.8
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/makefs/cd9660/cd9660_eltorito.c
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/makefs/cd9660/cd9660_eltorito.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/makefs/cd9660.c
diff -u src/usr.sbin/makefs/cd9660.c:1.53 src/usr.sbin/makefs/cd9660.c:1.54
--- src/usr.sbin/makefs/cd9660.c:1.53	Fri Nov 25 23:02:44 2016
+++ src/usr.sbin/makefs/cd9660.c	Tue Jan 24 11:22:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660.c,v 1.53 2016/11/25 23:02:44 christos Exp $	*/
+/*	$NetBSD: cd9660.c,v 1.54 2017/01/24 11:22:43 nonaka Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -103,7 +103,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660.c,v 1.53 2016/11/25 23:02:44 christos Exp $");
+__RCSID("$NetBSD: cd9660.c,v 1.54 2017/01/24 11:22:43 nonaka Exp $");
 #endif  /* !__lint */
 
 #include <string.h>
@@ -321,6 +321,7 @@ cd9660_prep_opts(fsinfo_t *fsopts)
 		OPT_STR('\0', "no-boot", "No boot support"),
 		OPT_STR('\0', "hard-disk-boot", "Boot from hard disk"),
 		OPT_STR('\0', "boot-load-segment", "Boot load segment"),
+		OPT_STR('\0', "platformid", "Section Header Platform ID"),
 
 		{ .name = NULL }
 	};
@@ -458,7 +459,8 @@ cd9660_parse_opts(const char *option, fs
 			/* RRIP */
 			cd9660_eltorito_add_boot_option(diskStructure, name, 0);
 			rv = 1;
-		} else if (strcmp(name, "boot-load-segment") == 0) {
+		} else if (strcmp(name, "boot-load-segment") == 0 ||
+		    strcmp(name, "platformid") == 0) {
 			if (buf[0] == '\0') {
 				warnx("Option `%s' doesn't contain a value",
 				    name);

Index: src/usr.sbin/makefs/makefs.8
diff -u src/usr.sbin/makefs/makefs.8:1.57 src/usr.sbin/makefs/makefs.8:1.58
--- src/usr.sbin/makefs/makefs.8:1.57	Wed Jan 11 13:47:27 2017
+++ src/usr.sbin/makefs/makefs.8	Tue Jan 24 11:22:43 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: makefs.8,v 1.57 2017/01/11 13:47:27 wiz Exp $
+.\"	$NetBSD: makefs.8,v 1.58 2017/01/24 11:22:43 nonaka Exp $
 .\"
 .\" Copyright (c) 2001-2003 Wasabi Systems, Inc.
 .\" All rights reserved.
@@ -366,6 +366,8 @@ ElTorito image.
 Do not pad the image (apparently Linux needs the padding).
 .\" .It Sy omit-trailing-period
 .\" Unknown
+.It Sy platformid
+Set platform ID of section header entry of the boot image.
 .It Sy preparer
 Preparer ID of the image.
 .It Sy publisher

Index: src/usr.sbin/makefs/cd9660/cd9660_eltorito.c
diff -u src/usr.sbin/makefs/cd9660/cd9660_eltorito.c:1.20 src/usr.sbin/makefs/cd9660/cd9660_eltorito.c:1.21
--- src/usr.sbin/makefs/cd9660/cd9660_eltorito.c:1.20	Mon Jan 28 21:03:28 2013
+++ src/usr.sbin/makefs/cd9660/cd9660_eltorito.c	Tue Jan 24 11:22:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660_eltorito.c,v 1.20 2013/01/28 21:03:28 christos Exp $	*/
+/*	$NetBSD: cd9660_eltorito.c,v 1.21 2017/01/24 11:22:43 nonaka Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660_eltorito.c,v 1.20 2013/01/28 21:03:28 christos Exp $");
+__RCSID("$NetBSD: cd9660_eltorito.c,v 1.21 2017/01/24 11:22:43 nonaka Exp $");
 #endif  /* !__lint */
 
 #ifdef DEBUG
@@ -56,11 +56,12 @@ static struct boot_catalog_entry *cd9660
 static struct boot_catalog_entry *cd9660_boot_setup_default_entry(
     struct cd9660_boot_image *);
 static struct boot_catalog_entry *cd9660_boot_setup_section_head(char);
-static struct boot_catalog_entry *cd9660_boot_setup_validation_entry(char);
 #if 0
 static u_char cd9660_boot_get_system_type(struct cd9660_boot_image *);
 #endif
 
+static struct cd9660_boot_image *default_boot_image;
+
 int
 cd9660_add_boot_disk(iso9660_disk *diskStructure, const char *boot_info)
 {
@@ -175,9 +176,15 @@ cd9660_add_boot_disk(iso9660_disk *diskS
 
 	new_image->serialno = diskStructure->image_serialno++;
 
+	new_image->platform_id = new_image->system;
+
 	/* TODO : Need to do anything about the boot image in the tree? */
 	diskStructure->is_bootable = 1;
 
+	/* First boot image is initial/default entry. */
+	if (default_boot_image == NULL)
+		default_boot_image = new_image;
+
 	return 1;
 }
 
@@ -211,6 +218,13 @@ cd9660_eltorito_add_boot_option(iso9660_
 			warn("%s: strtoul", __func__);
 			return 0;
 		}
+	} else if (strcmp(option_string, "platformid") == 0) {
+		if (strcmp(value, "efi") == 0)
+			image->platform_id = ET_SYS_EFI;
+		else {
+			warn("%s: unknown platform: %s", __func__, value);
+			return 0;
+		}
 	} else {
 		return 0;
 	}
@@ -342,12 +356,12 @@ cd9660_setup_boot(iso9660_disk *diskStru
 	int used_sectors;
 	int num_entries = 0;
 	int catalog_sectors;
-	struct boot_catalog_entry *x86_head, *mac_head, *ppc_head,
+	struct boot_catalog_entry *x86_head, *mac_head, *ppc_head, *efi_head,
 		*valid_entry, *default_entry, *temp, *head, **headp, *next;
 	struct cd9660_boot_image *tmp_disk;
 
 	headp = NULL;
-	x86_head = mac_head = ppc_head = NULL;
+	x86_head = mac_head = ppc_head = efi_head = NULL;
 
 	/* If there are no boot disks, don't bother building boot information */
 	if (TAILQ_EMPTY(&diskStructure->boot_images))
@@ -391,14 +405,25 @@ cd9660_setup_boot(iso9660_disk *diskStru
 	sector = first_sector + catalog_sectors;
 	TAILQ_FOREACH(tmp_disk, &diskStructure->boot_images, image_list) {
 		tmp_disk->sector = sector;
-		sector += tmp_disk->num_sectors;
+		sector += tmp_disk->num_sectors /
+		    (diskStructure->sectorSize / 512);
 	}
 
 	LIST_INSERT_HEAD(&diskStructure->boot_entries, valid_entry, ll_struct);
 
 	/* Step 1b: Initial/default entry */
 	/* TODO : PARAM */
-	tmp_disk = TAILQ_FIRST(&diskStructure->boot_images);
+	if (default_boot_image != NULL) {
+		struct cd9660_boot_image *tcbi;
+		TAILQ_FOREACH(tcbi, &diskStructure->boot_images, image_list) {
+			if (tcbi == default_boot_image) {
+				tmp_disk = tcbi;
+				break;
+			}
+		}
+	}
+	if (tmp_disk == NULL)
+		tmp_disk = TAILQ_FIRST(&diskStructure->boot_images);
 	default_entry = cd9660_boot_setup_default_entry(tmp_disk);
 	if (default_entry == NULL) {
 		warnx("Error: memory allocation failed in cd9660_setup_boot");
@@ -409,14 +434,18 @@ cd9660_setup_boot(iso9660_disk *diskStru
 
 	/* Todo: multiple default entries? */
 
-	tmp_disk = TAILQ_NEXT(tmp_disk, image_list);
+	tmp_disk = TAILQ_FIRST(&diskStructure->boot_images);
 
+	head = NULL;
 	temp = default_entry;
 
 	/* If multiple boot images are given : */
-	while (tmp_disk != NULL) {
+	for (; tmp_disk != NULL; tmp_disk = TAILQ_NEXT(tmp_disk, image_list)) {
+		if (tmp_disk == default_boot_image)
+			continue;
+
 		/* Step 2: Section header */
-		switch (tmp_disk->system) {
+		switch (tmp_disk->platform_id) {
 		case ET_SYS_X86:
 			headp = &x86_head;
 			break;
@@ -426,6 +455,9 @@ cd9660_setup_boot(iso9660_disk *diskStru
 		case ET_SYS_MAC:
 			headp = &mac_head;
 			break;
+		case ET_SYS_EFI:
+			headp = &efi_head;
+			break;
 		default:
 			warnx("%s: internal error: unknown system type",
 			    __func__);
@@ -434,7 +466,7 @@ cd9660_setup_boot(iso9660_disk *diskStru
 
 		if (*headp == NULL) {
 			head =
-			    cd9660_boot_setup_section_head(tmp_disk->system);
+			  cd9660_boot_setup_section_head(tmp_disk->platform_id);
 			if (head == NULL) {
 				warnx("Error: memory allocation failed in "
 				      "cd9660_setup_boot");
@@ -459,9 +491,11 @@ cd9660_setup_boot(iso9660_disk *diskStru
 			head = next;
 
 		LIST_INSERT_AFTER(head, temp, ll_struct);
-		tmp_disk = TAILQ_NEXT(tmp_disk, image_list);
 	}
 
+	if (head != NULL)
+		head->entry_data.SH.header_indicator[0] = ET_SECTION_HEADER_LAST;
+
 	/* TODO: Remaining boot disks when implemented */
 
 	return first_sector + used_sectors;

Index: src/usr.sbin/makefs/cd9660/cd9660_eltorito.h
diff -u src/usr.sbin/makefs/cd9660/cd9660_eltorito.h:1.5 src/usr.sbin/makefs/cd9660/cd9660_eltorito.h:1.6
--- src/usr.sbin/makefs/cd9660/cd9660_eltorito.h:1.5	Sat Jul  4 14:31:38 2009
+++ src/usr.sbin/makefs/cd9660/cd9660_eltorito.h	Tue Jan 24 11:22:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660_eltorito.h,v 1.5 2009/07/04 14:31:38 ahoka Exp $	*/
+/*	$NetBSD: cd9660_eltorito.h,v 1.6 2017/01/24 11:22:43 nonaka Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -40,6 +40,7 @@
 #define	ET_SYS_X86	0
 #define	ET_SYS_PPC	1
 #define	ET_SYS_MAC	2
+#define	ET_SYS_EFI	0xef	/* Platform ID at section header entry */
 
 #define ET_BOOT_ENTRY_SIZE 0x20
 
@@ -145,6 +146,7 @@ struct cd9660_boot_image {
 	u_char targetMode;
 	u_char system;
 	u_char bootable;
+	u_char platform_id;		/* for section header entry */
 	/*
 	 * If the boot image exists in the filesystem
 	 * already, this is a pointer to that node. For the sake

Reply via email to