mk9660: add -E option to create EFI boot entry

This commit is contained in:
cinap_lenrek 2014-10-31 03:06:09 +01:00
parent 4bfa18a5d1
commit 2cfbc3c1cb
5 changed files with 67 additions and 31 deletions

View file

@ -18,6 +18,10 @@ dump9660, mk9660 \- create an ISO-9660 CD image
.I bootfile
]
[
.B -E
.I bootfile
]
[
.B -p
.I proto
]
@ -193,6 +197,17 @@ boot block.
This gives the program in the boot block full (ATA) LBA access
to the CD filesystem, not just the initial blocks that would fit on a floppy.
.PP
In addition to
.B -b
and
.B -B
a boot entry for UEFI systems can be created with the
.B -E
option and with
.I bootfile
pointing to a FAT image containing the contents of
the efi system partition.
.PP
The
.B -D
flag creates immense amounts of debugging output

View file

@ -149,23 +149,16 @@ enum {
Emusectsz = 512, /* bytes per emulated sector */
};
void
Cupdatebootcat(Cdimg *cd)
static void
Caddbootentry(Cdimg *cd, Direc *bootrec, int bios)
{
uvlong o;
int n;
if(cd->bootdirec == nil)
return;
o = Cwoffset(cd);
Cwseek(cd, cd->bootimageptr);
Cputc(cd, 0x88);
if(cd->flags & CDbootnoemu)
Cputc(cd, 0); /* no disk emulation */
else
switch(cd->bootdirec->length){
switch(bootrec->length){
default:
fprint(2, "warning: boot image is not 1.44MB or 2.88MB; "
"pretending 1.44MB\n");
@ -183,28 +176,53 @@ Cupdatebootcat(Cdimg *cd)
n = 1;
if(cd->flags & CDbootnoemu){
n = (cd->bootdirec->length + Emusectsz - 1) / Emusectsz;
if(n > 4){
n = (bootrec->length + Emusectsz - 1) / Emusectsz;
if(bios && n > 4){
fprint(2, "warning: boot image too big; "
"will only load the first 2K\n");
n = 4;
}
}
Cputnl(cd, n, 2); /* Emusectsz-byte sector count for load */
Cputnl(cd, cd->bootdirec->block, 4); /* ptr to disk image */
Cwseek(cd, o);
Cputnl(cd, bootrec->block, 4); /* ptr to disk image */
}
void
findbootimage(Cdimg *cd, Direc *root)
Cupdatebootcat(Cdimg *cd, Direc *root)
{
Direc *d;
Direc *bootrec;
uvlong o;
d = walkdirec(root, cd->bootimage);
if(d == nil){
bootrec = nil;
if(cd->bootimage)
bootrec = walkdirec(root, cd->bootimage);
else if(cd->efibootimage)
bootrec = walkdirec(root, cd->efibootimage);
if(bootrec == nil){
fprint(2, "warning: did not encounter boot image\n");
return;
}
cd->bootdirec = d;
o = Cwoffset(cd);
Cwseek(cd, cd->bootimageptr);
Caddbootentry(cd, bootrec, cd->bootimage != nil);
bootrec = nil;
if(cd->efibootimage && cd->bootimage){
bootrec = walkdirec(root, cd->efibootimage);
if(bootrec == nil)
fprint(2, "warning: did not encounter efi boot image\n");
}
if(bootrec != nil) {
Crepeat(cd, 0, 20); /* Unused */
Cputc(cd, 0x91);
Cputc(cd, 0xef); /* platform id */
Cputnl(cd, 1, 2); /* num entries */
Crepeat(cd, 0, 28); /* ID string */
Caddbootentry(cd, bootrec, 0);
Crepeat(cd, 0, 20); /* vendor unique selection criteria. */
}
Cwseek(cd, o);
}

View file

@ -44,6 +44,7 @@ createcd(char *file, Cdinfo info)
Cputisopvd(cd, info);
if(info.flags & CDbootable){
cd->bootimage = info.bootimage;
cd->efibootimage = info.efibootimage;
cd->flags |= info.flags & (CDbootable|CDbootnoemu);
Cputbootvol(cd);
}

View file

@ -23,7 +23,7 @@ void
usage(void)
{
if(mk9660)
fprint(2, "usage: disk/mk9660 [-D:] [-9cjr] [-b bootfile] [-o offset blocksize] [-p proto] [-s src] cdimage\n");
fprint(2, "usage: disk/mk9660 [-D:] [-9cjr] [-[EBb] bootfile] [-o offset blocksize] [-p proto] [-s src] cdimage\n");
else
fprint(2, "usage: disk/dump9660 [-D:] [-9cjr] [-m maxsize] [-n now] [-p proto] [-s src] cdimage\n");
exits("usage");
@ -86,6 +86,14 @@ main(int argc, char **argv)
info.flags |= CDbootable;
info.bootimage = EARGF(usage());
break;
case 'E':
/* efi fat image */
if(!mk9660)
usage();
info.flags |= CDbootable;
info.flags |= CDbootnoemu;
info.efibootimage = EARGF(usage());
break;
case 'c':
info.flags |= CDconform;
break;
@ -204,10 +212,8 @@ main(int argc, char **argv)
Cwseek(cd, (vlong)cd->nextblock * Blocksize);
writefiles(dump, cd, &iroot);
if(cd->bootimage){
findbootimage(cd, &iroot);
Cupdatebootcat(cd);
}
if(cd->bootimage || cd->efibootimage)
Cupdatebootcat(cd, &iroot);
/* create Joliet tree */
if(cd->flags & CDjoliet)

View file

@ -114,8 +114,8 @@ struct Cdimg {
uvlong bootcatptr;
ulong bootcatblock;
uvlong bootimageptr;
Direc *bootdirec;
char *bootimage;
char *efibootimage;
Biobuf brd;
Biobuf bwr;
@ -157,12 +157,9 @@ struct Cdinfo {
char *preparer;
char *application;
char *bootimage;
char *efibootimage;
};
//enum {
// Blocklen = 2048, /* unused */
//};
/*
* This is a doubly binary tree.
* We have a tree keyed on the MD5 values
@ -293,8 +290,7 @@ enum { /* CputrripNM flag types */
void Cputbootvol(Cdimg*);
void Cputbootcat(Cdimg*);
void Cupdatebootvol(Cdimg*);
void Cupdatebootcat(Cdimg*);
void findbootimage(Cdimg*, Direc*);
void Cupdatebootcat(Cdimg*, Direc*);
/* cdrdwr.c */
Cdimg *createcd(char*, Cdinfo);