1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-27 11:55:06 +00:00

Synchronise with NetBSD's version of EFI handling for El Torito images.

When I implemented my EFI support I failed to check if the upstream version
of makefs in NetBSD had done the same. Override my version with theirs to
make it easier to stay in sync with them in the future.

Reviewed by:	imp, mav
Obtained from:	NetBSD
MFC after:	1 week
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D14913
This commit is contained in:
Benno Rice 2018-03-31 15:04:41 +00:00
parent 28da5c6d7a
commit 756e49c303
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=331843
4 changed files with 63 additions and 28 deletions

View File

@ -309,6 +309,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 }
};
@ -444,7 +445,8 @@ cd9660_parse_opts(const char *option, fsinfo_t *fsopts)
/* 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);

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd9660_eltorito.c,v 1.17 2011/06/23 02:35:56 enami Exp $ */
/* $NetBSD: cd9660_eltorito.c,v 1.23 2018/03/28 06:48:55 nonaka Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-NetBSD
@ -47,16 +47,19 @@ __FBSDID("$FreeBSD$");
#define ELTORITO_DPRINTF(__x)
#endif
#include <util.h>
static struct boot_catalog_entry *cd9660_init_boot_catalog_entry(void);
static struct boot_catalog_entry *cd9660_boot_setup_validation_entry(char);
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)
{
@ -104,12 +107,9 @@ cd9660_add_boot_disk(iso9660_disk *diskStructure, const char *boot_info)
else if (strcmp(sysname, "macppc") == 0 ||
strcmp(sysname, "mac68k") == 0)
new_image->system = ET_SYS_MAC;
else if (strcmp(sysname, "efi") == 0 ||
strcmp(sysname, "uefi") == 0)
new_image->system = ET_SYS_UEFI;
else {
warnx("boot disk system must be "
"efi, i386, powerpc, macppc, mac68k");
"i386, powerpc, macppc, or mac68k");
free(temp);
free(new_image);
return 0;
@ -174,9 +174,15 @@ cd9660_add_boot_disk(iso9660_disk *diskStructure, const char *boot_info)
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;
}
@ -210,6 +216,13 @@ cd9660_eltorito_add_boot_option(iso9660_disk *diskStructure,
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;
}
@ -232,6 +245,7 @@ cd9660_boot_setup_validation_entry(char sys)
size_t i;
entry = cd9660_init_boot_catalog_entry();
entry->entry_type = ET_ENTRY_VE;
ve = &entry->entry_data.VE;
ve->header_id[0] = 1;
@ -266,6 +280,7 @@ cd9660_boot_setup_default_entry(struct cd9660_boot_image *disk)
if (default_entry == NULL)
return NULL;
default_entry->entry_type = ET_ENTRY_IE;
ie = &default_entry->entry_data.IE;
ie->boot_indicator[0] = disk->bootable;
@ -293,6 +308,7 @@ cd9660_boot_setup_section_head(char platform)
if (entry == NULL)
return NULL;
entry->entry_type = ET_ENTRY_SH;
sh = &entry->entry_data.SH;
/*
* More by default.
@ -312,6 +328,7 @@ cd9660_boot_setup_section_entry(struct cd9660_boot_image *disk)
if ((entry = cd9660_init_boot_catalog_entry()) == NULL)
return NULL;
entry->entry_type = ET_ENTRY_SE;
se = &entry->entry_data.SE;
se->boot_indicator[0] = ET_BOOTABLE;
@ -344,12 +361,12 @@ cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
int used_sectors;
int num_entries = 0;
int catalog_sectors;
struct boot_catalog_entry *x86_head, *mac_head, *ppc_head, *uefi_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 = uefi_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))
@ -393,14 +410,25 @@ cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
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");
@ -411,14 +439,18 @@ cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
/* 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;
@ -428,8 +460,8 @@ cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
case ET_SYS_MAC:
headp = &mac_head;
break;
case ET_SYS_UEFI:
headp = &uefi_head;
case ET_SYS_EFI:
headp = &efi_head;
break;
default:
warnx("%s: internal error: unknown system type",
@ -439,7 +471,7 @@ cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
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");
@ -464,7 +496,6 @@ cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
head = next;
LIST_INSERT_AFTER(head, temp, ll_struct);
tmp_disk = TAILQ_NEXT(tmp_disk, image_list);
}
/* Find the last Section Header entry and mark it as the last. */
@ -474,8 +505,7 @@ cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
head = next;
}
if (head != NULL)
head->entry_data.SH.header_indicator[0] =
ET_SECTION_HEADER_LAST;
head->entry_data.SH.header_indicator[0] = ET_SECTION_HEADER_LAST;
/* TODO: Remaining boot disks when implemented */
@ -577,13 +607,13 @@ cd9660_write_apm_partition_entry(FILE *fd, int idx, int total_partitions,
apm32 = 0;
/* pmLgDataStart */
fwrite(&apm32, sizeof(apm32), 1, fd);
fwrite(&apm32, sizeof(apm32), 1, fd);
/* pmDataCnt */
apm32 = htobe32(nsectors);
fwrite(&apm32, sizeof(apm32), 1, fd);
fwrite(&apm32, sizeof(apm32), 1, fd);
/* pmPartStatus */
apm32 = htobe32(part_status);
fwrite(&apm32, sizeof(apm32), 1, fd);
fwrite(&apm32, sizeof(apm32), 1, fd);
return 0;
}
@ -700,8 +730,9 @@ cd9660_write_boot(iso9660_disk *diskStructure, FILE *fd)
t->num_sectors * (diskStructure->sectorSize / 512),
512, "CD Boot", "Apple_Bootstrap");
}
/* Write ISO9660 descriptor, enclosing the whole disk */
cd9660_write_apm_partition_entry(fd, 2 + apm_partitions,
cd9660_write_apm_partition_entry(fd, 2 + apm_partitions,
total_parts, 0, diskStructure->totalSectors *
(diskStructure->sectorSize / 512), 512, "ISO9660",
"CD_ROM_Mode_1");
@ -709,4 +740,3 @@ cd9660_write_boot(iso9660_disk *diskStructure, FILE *fd)
return 0;
}

View File

@ -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 $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-NetBSD
@ -44,7 +44,7 @@
#define ET_SYS_X86 0
#define ET_SYS_PPC 1
#define ET_SYS_MAC 2
#define ET_SYS_UEFI 0xef
#define ET_SYS_EFI 0xef /* Platform ID at section header entry */
#define ET_BOOT_ENTRY_SIZE 0x20
@ -150,6 +150,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

View File

@ -35,7 +35,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd May 26, 2017
.Dd March 30, 2018
.Dt MAKEFS 8
.Os
.Sh NAME
@ -394,6 +394,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