Hi tech@,

This adds support for UEFI.

>From NetBSD 
>http://mail-index.netbsd.org/source-changes/2017/01/24/msg081292.html

----
you can make BIOS/UEFI dual boot ISO image like this,

 mkdir -p efiboot/EFI/BOOT
 cp /usr/mdec/BOOT*.EFI efiboot/EFI/BOOT/
 makefs -M 1m -t msdos efiboot.img efiboot
 
 mkdir -p cd-dir/etc
 echo 'set image /bsd.rd' > cd-dir/etc/boot.conf
 cp /bsd.rd cd-dir/
 makefs -t cd9660 -o 
'rockridge,bootimage=i386;/usr/mdec/cdboot,no-emul-boot,allow-multidot,bootimage=i386;efiboot.img,platformid=efi,no-emul-boot'
 cd.iso cd-dir

Index: usr.sbin/makefs/cd9660.c
===================================================================
RCS file: /cvs/src/usr.sbin/makefs/cd9660.c,v
retrieving revision 1.20
diff -u -p -r1.20 cd9660.c
--- usr.sbin/makefs/cd9660.c    6 Apr 2017 19:09:45 -0000       1.20
+++ usr.sbin/makefs/cd9660.c    21 Jul 2017 05:57:45 -0000
@@ -1,5 +1,5 @@
 /*     $OpenBSD: cd9660.c,v 1.20 2017/04/06 19:09:45 natano Exp $      */
-/*     $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
@@ -265,6 +265,7 @@ cd9660_prep_opts(fsinfo_t *fsopts)
                OPT_STR("no-emul-boot"),
                OPT_BOOL("no-trailing-padding", include_padding_areas),
                OPT_BOOL("omit-trailing-period", omit_trailing_period),
+               OPT_STR("platformid"),
                OPT_STR("preparer"),
                OPT_STR("publisher"),
                OPT_BOOL("rockridge", rock_ridge_enabled),
@@ -341,7 +342,8 @@ cd9660_parse_opts(const char *option, fs
        if (strcmp(name, "applicationid") == 0) {
                rv = cd9660_arguments_set_string(buf, name, 128, 'a',
                    diskStructure->primaryDescriptor.application_id);
-       } 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: usr.sbin/makefs/makefs.8
===================================================================
RCS file: /cvs/src/usr.sbin/makefs/makefs.8,v
retrieving revision 1.18
diff -u -p -r1.18 makefs.8
--- usr.sbin/makefs/makefs.8    13 Nov 2016 10:22:21 -0000      1.18
+++ usr.sbin/makefs/makefs.8    21 Jul 2017 05:57:45 -0000
@@ -235,6 +235,8 @@ ElTorito image.
 Do not pad the image (apparently Linux needs the padding).
 .It Sy omit-trailing-period
 Omit trailing periods in filenames.
+.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: usr.sbin/makefs/cd9660/cd9660_eltorito.c
===================================================================
RCS file: /cvs/src/usr.sbin/makefs/cd9660/cd9660_eltorito.c,v
retrieving revision 1.9
diff -u -p -r1.9 cd9660_eltorito.c
--- usr.sbin/makefs/cd9660/cd9660_eltorito.c    17 Dec 2016 16:22:04 -0000      
1.9
+++ usr.sbin/makefs/cd9660/cd9660_eltorito.c    21 Jul 2017 05:57:45 -0000
@@ -1,5 +1,5 @@
 /*     $OpenBSD: cd9660_eltorito.c,v 1.9 2016/12/17 16:22:04 krw Exp $ */
-/*     $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
@@ -57,11 +57,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)
 {
@@ -163,9 +164,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;
 }
 
@@ -199,6 +206,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;
        }
@@ -330,12 +344,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))
@@ -373,14 +387,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");
@@ -391,14 +416,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;
@@ -408,6 +437,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__);
@@ -416,7 +448,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");
@@ -441,8 +473,10 @@ 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 */
 
Index: usr.sbin/makefs/cd9660/cd9660_eltorito.h
===================================================================
RCS file: /cvs/src/usr.sbin/makefs/cd9660/cd9660_eltorito.h,v
retrieving revision 1.3
diff -u -p -r1.3 cd9660_eltorito.h
--- usr.sbin/makefs/cd9660/cd9660_eltorito.h    17 Dec 2016 16:22:04 -0000      
1.3
+++ usr.sbin/makefs/cd9660/cd9660_eltorito.h    21 Jul 2017 05:57:45 -0000
@@ -1,5 +1,5 @@
 /*     $OpenBSD: cd9660_eltorito.h,v 1.3 2016/12/17 16:22:04 krw Exp $ */
-/*     $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
@@ -41,6 +41,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
 
@@ -146,6 +147,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