Rejig CONFIG_MBR_OFFSET behaviour. It now defines a fall-back location for
authorNeal Andrew Crook <neal@pippaluk.org.uk>
Thu, 19 May 2016 18:32:48 +0000 (19:32 +0100)
committerNeal Andrew Crook <neal@pippaluk.org.uk>
Thu, 19 May 2016 18:32:48 +0000 (19:32 +0100)
the MBR. Location 0 is always checked first, and a valid MBR found there will
be used in preference.

Kernel/PORTING
Kernel/dev/mbr.c
Kernel/platform-multicomp09/config.h

index 90154d0..ae994f6 100644 (file)
@@ -102,7 +102,8 @@ Porting Fuzix to a new Z80 based machine generally requires the following
  CONFIG_MBR_OFFSET tells dev/mbr.c where to find the MBR. FUZIX knows how to
  parse a standard DOS master boot record and extract partition table entries
  to locate and mount drives. A well-behaved disk will have its MBR at block 0.
- If you need to put your MBR elsewhere, use this.
+ If you need to put your MBR elsewhere, use this. Even with this defined,
+ block 0 is still checked first and a valid MBR there is used in preference.
 
 - Set the basic system parameters
 
index 5c36cd1..f914ec2 100644 (file)
@@ -38,15 +38,22 @@ void mbr_parse(char letter)
     blk_op.is_read = true;
     blk_op.is_user = false;
     blk_op.addr = (uint8_t *)br;
-#ifdef CONFIG_MBR_OFFSET
-    blk_op.lba = CONFIG_MBR_OFFSET;
-#else
     blk_op.lba = 0;
-#endif
+
     do{
         blk_op.nblock = 1;
-        if(!blk_op.blkdev->transfer() || le16_to_cpu(br->signature) != MBR_SIGNATURE)
+        if(!blk_op.blkdev->transfer() || le16_to_cpu(br->signature) != MBR_SIGNATURE){
+#ifdef CONFIG_MBR_OFFSET
+            if (blk_op.lba == 0) {
+                /* failed to find MBR on block 0. Go round again but this time
+                   look at the fall-back location for this badly-behaved media
+                */
+                blk_op.lba = CONFIG_MBR_OFFSET;
+                continue;
+            }
+#endif
            break;
+        }
 
        /* avoid an infinite loop where extended boot records form a loop */
        if(seen >= 50)
index e0a53a7..0d19992 100644 (file)
 /* Boot devices */
 #define BOOTDEVICENAMES "hd#,,,,,,,,dw"
 
-/* [NAC HACK 2016Apr24] nicer if I didn't hard-wire this? */
-/* This must be a 16-bit number, not a string! See start.c for examples/encoding */
-/* so this is hda1 */
-/* Without this defined, get prompted for root device at boot time */
+/* This must be a 16-bit number, not a string! See start.c for examples/encoding
+   -- so 0x0001 is hda1
+   Without this defined, get prompted for root device at boot time
+*/
 #define BOOTDEVICE 0x0001
 
 /* We need a tidier way to do this from the loader */
-/* [NAC HACK 2016Apr24] 0 because we don't have one */
 #define CMDLINE         NULL     /* Location of root dev name */
 
 /* Allow MBR to be other than at block 0. If so, the start LBA of partitions
    defined in the MBR are defined relative to the position of the MBR, not
    relative to the start of the disk (ie, the values they'd have if the
-   MBR was in block 0)
+   MBR was in block 0). Even with this defined, it only acts as a back-up:
+   block 0 is still checked first.
 */
 #define CONFIG_MBR_OFFSET (0x30000)