summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@HansenPartnership.com>2019-07-06 13:34:16 -0700
committerHelge Deller <deller@gmx.de>2019-07-07 16:19:59 +0200
commit459f0bb28a69702ce27cc57fdb681cc93d1b23f7 (patch)
tree8367848414da5daba5565e309d5e1f5518127229
parent0abec85fce0d9c744757ddd246c55a5e3c8359d6 (diff)
downloadpalo-459f0bb28a69702ce27cc57fdb681cc93d1b23f7.tar.gz
palo: place iplboot inside disk label if it's big enough
Ever since the widespread adoption of gpt and 4k emulation disks, we've been starting the first partition at sector 2048 instead of 63. Since we only need 512 sectors for iplboot, this offers the opportunity of placing iplboot directly inside the disk label. The way this patch works is that if no palo (F0) partition is found and the first partition starts high enough, initialise the disk with the ipl boot just below the first partition. If the disk isn't big enough, error out as previously and if an F0 partition is found, proceed as usual. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com> Signed-off-by: Helge Deller <deller@gmx.de>
-rw-r--r--ipl/ipl.c11
-rw-r--r--palo/palo.c53
2 files changed, 57 insertions, 7 deletions
diff --git a/ipl/ipl.c b/ipl/ipl.c
index 03fe4ba..2a25e7c 100644
--- a/ipl/ipl.c
+++ b/ipl/ipl.c
@@ -486,6 +486,7 @@ iplmain(int is_interactive, char *initialstackptr, int started_wide)
char kern_name[128], rd_name[128];
char kern_fullname[128+10];
int ok = 1;
+ const char *str;
/* BSS clear */
bzero(&_edata, &_end - &_edata);
@@ -527,8 +528,14 @@ iplmain(int is_interactive, char *initialstackptr, int started_wide)
print_ptab_pretty(partition, sizeof partition / sizeof partition[0]);
}
- printf("\n%s contains:\n",
- partitioned ? "PALO(F0) partition" : "Boot image");
+ if (partitioned && f.ipl_addr < partition[0].start * 512)
+ str = "PALO within boot label";
+ else if (partitioned)
+ str = "PALO(F0) partition";
+ else
+ str = "Boot image";
+
+ printf("\n%s contains:\n", str);
if(partitioned && f.version >= 4 && (f.flags & PFLAG_EXT2)) {
printf("PALO is formatted EXT2/3\n");
diff --git a/palo/palo.c b/palo/palo.c
index 26da01b..7f3260e 100644
--- a/palo/palo.c
+++ b/palo/palo.c
@@ -451,6 +451,30 @@ do_cdrom(int media, int kernel32, int kernel64,
#define EXT2_OFFSET (4*EXT2_BLOCKSIZE)
int
+do_at_start(int init, int media, int start,
+ int bootloaderfd, const char *commandline)
+{
+ struct firstblock f;
+
+ STRUCTREAD(media, f, 0);
+
+ if (init) {
+ fb_init(&f);
+ } else if (f.ipl_addr != start) {
+ printf("Current IPL start not consistent with disklabel, use -I to reinitialise\n");
+ error(11);
+ }
+
+ if(commandline)
+ strncpy(f.cmdline, commandline, sizeof(f.cmdline)-1);
+
+ write_bootloader(media, bootloaderfd, start,
+ start + MAXBLSIZE, &f);
+
+ STRUCTWRITE(media, f, 0);
+}
+
+int
do_formatted(int init, int media, const char *medianame, int partition,
int f0start, int f0length, int bootloaderfd, int do_format,
const char *commandline)
@@ -916,6 +940,7 @@ main(int argc, char *argv[])
int partitioned;
int f0;
struct firstblock f;
+ int at_start = 0; /* place ipl before first partition */
memset(ptab, 0, sizeof ptab);
@@ -943,16 +968,34 @@ main(int argc, char *argv[])
if (ptab[f0].id == PALO_PARTITION)
break;
}
- if (f0 == MAXPARTS)
- error(11);
+ if (f0 == MAXPARTS) {
+ /* is the partition layout sufficient to support
+ * iplboot before the first parition. Allow 64
+ * sectors for the gpt label (like we'll ever support
+ * gpt, but just in case) allow for 8 extra sectors to
+ * align the iplboot */
+ if (ptab[0].start > 64 + MAXBLSIZE/512 + 8)
+ at_start = (ptab[0].start * 512 - MAXBLSIZE) & ~0xfff;
+ else
+ error(11);
+ }
if(verbose) {
print_ptab_pretty(ptab, MAXPARTS);
- printf("F0 partition start sector %d length %d\n",
- ptab[f0].start, ptab[f0].length);
+ if (at_start)
+ printf("Placing bootloader within disk label at %d\n",
+ at_start/512);
+ else
+ printf("F0 partition start sector %d length %d\n",
+ ptab[f0].start, ptab[f0].length);
}
- if (format_as) {
+ if (at_start) {
+ if (format_as)
+ printf("No F0(palo) partition found, placing iplboot inside label\n");
+
+ do_at_start(init, media, at_start, bootloader, commandline);
+ } else if (format_as) {
/* if we're going to be a formatted partition, we can't
* load anything into it, so check we haven't been asked
* to */