From: Neal Andrew Crook Date: Thu, 19 May 2016 18:32:48 +0000 (+0100) Subject: Rejig CONFIG_MBR_OFFSET behaviour. It now defines a fall-back location for X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=26c5e03c9b37eef4d24fe5cdc2b153b38ff83ba7;p=FUZIX.git Rejig CONFIG_MBR_OFFSET behaviour. It now defines a fall-back location for the MBR. Location 0 is always checked first, and a valid MBR found there will be used in preference. --- diff --git a/Kernel/PORTING b/Kernel/PORTING index 90154d0f..ae994f68 100644 --- a/Kernel/PORTING +++ b/Kernel/PORTING @@ -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 diff --git a/Kernel/dev/mbr.c b/Kernel/dev/mbr.c index 5c36cd1f..f914ec25 100644 --- a/Kernel/dev/mbr.c +++ b/Kernel/dev/mbr.c @@ -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) diff --git a/Kernel/platform-multicomp09/config.h b/Kernel/platform-multicomp09/config.h index e0a53a79..0d19992a 100644 --- a/Kernel/platform-multicomp09/config.h +++ b/Kernel/platform-multicomp09/config.h @@ -48,20 +48,20 @@ /* 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)