m68k: fixup_next_boot_floppy: force bootblock at 8k to fit before tgz

We don't have room for disklabel copies anymore.

+ style fixes

Change-Id: I22502167a4f5f8bc3df1b017072461d77a299b16
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3100
Reviewed-by: Alex von Gluck IV <[email protected]>
This commit is contained in:
François Revol
2020-08-19 13:39:04 +00:00
committed by Alex von Gluck IV
parent 50addaaab6
commit ab51e305e9
@@ -14,15 +14,16 @@
/* for now we actually write all of the disk label here. */
//#define DL_SIZE (sizeof(disklabel))
#define DL_SIZE (offsetof(struct disk_label, dl_un.DL_v3_checksum) + sizeof(uint16_t))
#define SUM_CNT (offsetof(struct disk_label, dl_un.DL_v3_checksum) / sizeof(uint16_t))
#define DL_SIZE (offsetof(struct disk_label, dl_un.DL_v3_checksum) \
+ sizeof(uint16_t))
#define SUM_CNT (offsetof(struct disk_label, dl_un.DL_v3_checksum) \
/ sizeof(uint16_t))
// could not get ByteOrder.h to include
#define H2B32 htonl
#define H2B16 htons
#define B2H16 ntohs
// see https://unix.superglobalmegacorp.com/darwin01/newsrc/machdep/i386/checksum_16.c.html
static uint16_t checksum_16(uint16_t *p, int count)
{
@@ -36,12 +37,16 @@ static uint16_t checksum_16(uint16_t *p, int count)
return sum;
}
int main(int argc, char **argv)
{
int fd;
uint16_t sum;
int labelOffsets[] = { 0, 15, 30, 45 };
int numLabels = sizeof(labelOffsets) / sizeof(int);
// HACK: for now we force a single label plus the bootlock at 8kb
// (min offset the ROM allows) to fit before the tgz
int numLabels = 1; // sizeof(labelOffsets) / sizeof(int);
uint32_t bootBlockStart = 0x8; // usually 0x20
struct disk_label disklabel = {
H2B32(DL_V3),
@@ -49,7 +54,8 @@ int main(int argc, char **argv)
H2B32(0),
"HaikuBoot",//"NextBoot",
H2B32(0),
H2B32(0x4841494b),//H2B32(0xa991637a), // dl_tag: 'HAIK'
// dl_tag, we use 'HAIK'
H2B32(0x4841494b), // H2B32(0xa991637a),
"Sony MPX-111N 2880-512", // same as NS image, not sure it matters
"removable_rw_floppy",
H2B32(1024), // !! 1024 bytes / sector !!
@@ -63,41 +69,51 @@ int main(int argc, char **argv)
H2B16(0),
H2B16(0),
H2B16(0),
H2B32(0x20),H2B32(0xffffffff), // boot blocks in 1024 bytes sectors
// XXX: move it closer to start?
"haiku_loader",//"fdmach"
"schredder",//"silly"
// boot blocks in 1024 bytes sectors
H2B32(bootBlockStart),H2B32(0xffffffff),
"haiku_loader", // "fdmach"
"schredder", // "silly"
'a', 'b',
// partitions
{
// Nextstep uses this:
//{ H2B32(0), H2B32(0x540), H2B16(0x2000), H2B16(0x400), 't', H2B16(0x20), H2B16(0x800), 0, 1, "", 1, "4.3BSD"},
//{ H2B32(0), H2B32(0x540), H2B16(0x2000), H2B16(0x400), 't',
// H2B16(0x20), H2B16(0x800), 0, 1, "", 1, "4.3BSD"},
// XXX: should we fake an fs anyway?
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0, H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0, H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0, H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0, H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0, H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0, H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0, H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0, H2B16(-1), H2B16(-1), -1, 0, "", 0, ""}
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0,
H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0,
H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0,
H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0,
H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0,
H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0,
H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0,
H2B16(-1), H2B16(-1), -1, 0, "", 0, ""},
{ H2B32(-1), H2B32(-1), H2B16(-1), H2B16(-1), 0,
H2B16(-1), H2B16(-1), -1, 0, "", 0, ""}
},
{ 0 },
0
};
fd = open(argv[1], O_RDWR);
if (fd < 0) {
perror("open");
return 1;
}
//XXX: support simple checksum of existing label?
/*
#if 0
if (read(fd, bootblock, DL_SIZE) < DL_SIZE) {
perror("read");
return 1;
}
*/
#endif
// TODO: update boot block offsets!
// TODO: take boot block offsets as arg?
sum = checksum_16((uint16_t *)&disklabel, SUM_CNT);
fprintf(stderr, "checksum: 0x%04x\n", sum);