@@ -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");
@@ -450,6 +450,30 @@ do_cdrom(int media, int kernel32, int kernel64,
* filesystem or define EXT2_OFFSET to (259*EXT2_BLOCKSIZE)*/
#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,
@@ -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 */
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> --- ipl/ipl.c | 11 +++++++++-- palo/palo.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 7 deletions(-)