[haiku-commits] haiku: hrev54519 - src/tools/fixup_next_boot_floppy

  • From: Alex von Gluck IV <kallisti5@xxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 19 Aug 2020 09:37:52 -0400 (EDT)

hrev54519 adds 1 changeset to branch 'master'
old head: 86776c1ebea6e85590faa6f091c3d531a0bbad86
new head: ea3142ecbadfaf6f195ceda6af5c6147077fe821
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=ea3142ecbadf+%5E86776c1ebea6

----------------------------------------------------------------------------

ea3142ecbadf: m68k: fixup_next_boot_floppy tool (actually writes the disklabel)
  
  Next floppies actually do have a "disk label" (partitionning scheme),
  the boot block being later on the disk.
  
  This commit generates an identical label to the image I have here (but
  not the copies at other sectors), including the checksum.
  
  Change-Id: I7f939c26e70e3626d9af7a3eb342cfd32c298e3d
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3098
  Reviewed-by: Alex von Gluck IV <kallisti5@xxxxxxxxxxx>

                                          [ François Revol <revol@xxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev54519
Commit:      ea3142ecbadfaf6f195ceda6af5c6147077fe821
URL:         https://git.haiku-os.org/haiku/commit/?id=ea3142ecbadf
Author:      François Revol <revol@xxxxxxx>
Date:        Sun Jul 26 22:17:16 2020 UTC
Committer:   Alex von Gluck IV <kallisti5@xxxxxxxxxxx>
Commit-Date: Wed Aug 19 13:37:39 2020 UTC

----------------------------------------------------------------------------

3 files changed, 115 insertions(+)
src/tools/Jamfile                                |  1 +
src/tools/fixup_next_boot_floppy/Jamfile         | 16 ++++
.../fixup_next_boot_floppy.c                     | 98 ++++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/src/tools/Jamfile b/src/tools/Jamfile
index b5227d92a3..dda70d0d36 100644
--- a/src/tools/Jamfile
+++ b/src/tools/Jamfile
@@ -95,6 +95,7 @@ SubInclude HAIKU_TOP src tools cppunit ;
 SubInclude HAIKU_TOP src tools create_repository_config ;
 SubInclude HAIKU_TOP src tools elfsymbolpatcher ;
 SubInclude HAIKU_TOP src tools fixup_amiga_boot_checksum ;
+SubInclude HAIKU_TOP src tools fixup_next_boot_floppy ;
 SubInclude HAIKU_TOP src tools fixup_tos_boot_checksum ;
 SubInclude HAIKU_TOP src tools fs_shell ;
 SubInclude HAIKU_TOP src tools gensyscalls ;
diff --git a/src/tools/fixup_next_boot_floppy/Jamfile 
b/src/tools/fixup_next_boot_floppy/Jamfile
new file mode 100644
index 0000000000..40578f68f6
--- /dev/null
+++ b/src/tools/fixup_next_boot_floppy/Jamfile
@@ -0,0 +1,16 @@
+SubDir HAIKU_TOP src tools fixup_next_boot_floppy ;
+
+#UseHeaders [ FDirName $(HAIKU_TOP) headers build ] : true ;
+
+#if ! $(HOST_PLATFORM_HAIKU_COMPATIBLE) {
+#      UseHeaders [ FDirName $(HAIKU_TOP) headers build os ] : true ;
+#      UseHeaders [ FDirName $(HAIKU_TOP) headers build os support ] : true ;
+#}
+
+#UsePrivateHeaders kernel ;
+UseHeaders [ FDirName $(HAIKU_TOP) headers private kernel platform next_m68k ] 
: true ;
+
+BuildPlatformMain <build>fixup_next_boot_floppy
+       : fixup_next_boot_floppy.c
+       :
+;
diff --git a/src/tools/fixup_next_boot_floppy/fixup_next_boot_floppy.c 
b/src/tools/fixup_next_boot_floppy/fixup_next_boot_floppy.c
new file mode 100644
index 0000000000..6ccaf51616
--- /dev/null
+++ b/src/tools/fixup_next_boot_floppy/fixup_next_boot_floppy.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2020, François Revol, revol@xxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+
+#include <disklabel.h>
+
+/* 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))
+
+// 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)
+{
+       uint32_t sum = 0;
+       for (;count--;)
+               sum += B2H16(*p++);
+       // sum both shorts
+       sum = (sum & 0x0ffff) + (sum >> 16);
+       if (sum > 65535)
+               sum -= 65535;
+       return sum;
+}
+
+int main(int argc, char **argv)
+{
+       int fd;
+       unsigned int i;
+       uint16_t sum;
+       struct disk_label disklabel = {
+               H2B32(DL_V3),
+               H2B32(0),
+               H2B32(0),
+               "NextBoot",//"HaikuBoot",
+               H2B32(0),
+               H2B32(0xa991637a), //H2B32(0x4841494b), // dl_tag: 'HAIK'
+               "Sony MPX-111N 2880-512", // same as NS image, not sure it 
matters
+               "removable_rw_floppy",
+               H2B32(1024), // !! 1024 bytes / sector !!
+               H2B32(2),
+               H2B32(9),
+               H2B32(80),
+               H2B32(300),
+               H2B16(96),
+               H2B16(0),
+               H2B16(0),
+               H2B16(0),
+               H2B16(0),
+               H2B16(0),
+               H2B32(0x20),H2B32(0xffffffff),  // boot block locations XXX: 
move it closer to start?
+               "fdmach", //"haiku_loader",
+               "silly", //"schredder",
+               '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(-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, ""}
+               }
+       };
+       fd = open(argv[1], O_RDWR);
+       if (fd < 0) {
+               return 1;
+       }
+       //XXX: implement support simple checksum of existing label?
+       /*
+       if (read(fd, bootblock, DL_SIZE) < DL_SIZE) {
+               perror("read");
+               return 1;
+       }
+       */
+       sum = checksum_16((uint16_t *)&disklabel, SUM_CNT);
+       fprintf(stderr, "checksum: 0x%04x\n", sum);
+       disklabel.dl_un.DL_v3_checksum = H2B16(sum);
+       lseek(fd, 0LL, SEEK_SET);
+       write(fd, &disklabel, DL_SIZE);
+       return 0;
+}


Other related posts:

  • » [haiku-commits] haiku: hrev54519 - src/tools/fixup_next_boot_floppy - Alex von Gluck IV