From 2140694397c262c79ede4b6e3bb08bc2e5f82865 Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sat, 20 Nov 2010 22:19:06 +0000 Subject: convert to UUID; make panic-reboot-time a flag; prevent automatic fsck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit note: uuid.patch currently still panics ☹ Signed-off-by: Thorsten Glaser --- mk/rootfs.mk | 4 +- scripts/install.sh | 20 ++-- target/Config.in | 8 -- target/linux/patches/2.6.36/uuid.patch | 174 +++++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 17 deletions(-) create mode 100644 target/linux/patches/2.6.36/uuid.patch diff --git a/mk/rootfs.mk b/mk/rootfs.mk index e5c4c7089..30802e092 100644 --- a/mk/rootfs.mk +++ b/mk/rootfs.mk @@ -8,8 +8,6 @@ FS_CMDLINE:=$(3) endif endef -ADK_TARGET_ROOTFS_USB_DEVICE:=$(strip $(subst ",, $(ADK_TARGET_ROOTFS_USB_DEVICE))) - ifeq ($(ADK_LINUX_MIPS_RB532),y) ROOTFS:= root=/dev/sda2 MTDDEV:= root=/dev/mtdblock1 @@ -24,7 +22,7 @@ ROOTFS:= root=/dev/mmcblk0p2 rootwait endif $(eval $(call rootfs_template,ext2-block,EXT2_BLOCK,$(ROOTFS))) -$(eval $(call rootfs_template,usb,USB,root=$(ADK_TARGET_ROOTFS_USB_DEVICE) rootdelay=3)) +$(eval $(call rootfs_template,usb,USB,rootdelay=3)) $(eval $(call rootfs_template,archive,ARCHIVE)) $(eval $(call rootfs_template,initramfs,INITRAMFS)) $(eval $(call rootfs_template,initramfs-piggyback,INITRAMFS_PIGGYBACK)) diff --git a/scripts/install.sh b/scripts/install.sh index c7ab63eaa..7ade75c68 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -73,22 +73,28 @@ cfgfs=1 quiet=0 serial=0 speed=115200 +panicreboot=10 function usage { cat >&2 < 5 )); then print -u2 "$me: -c $OPTARG out of bounds" exit 1 fi ;; (h) usage 0 ;; + (p) if (( (panicreboot = OPTARG) < 0 || panicreboot > 300 )); then + print -u2 "$me: -p $OPTARG out of bounds" + exit 1 + fi ;; (q) quiet=1 ;; (+q) quiet=0 ;; (s) if [[ $OPTARG != @(96|192|384|576|1152)00 ]]; then @@ -281,7 +287,8 @@ dd if="$T/firsttrack" of="$tgt" q= (( quiet )) && q=-q mke2fs $q "$part" -#partuuid=$(tune2fs -l /dev/sd0i | sed -n '/^Filesystem UUID:[ ]*/s///p') +partuuid=$(tune2fs -l "$part" | sed -n '/^Filesystem UUID:[ ]*/s///p') +tune2fs -c 0 -i 0 "$part" (( quiet )) || print Extracting installation archive... mount_ext2fs "$part" "$T" @@ -311,8 +318,9 @@ mkdir -p boot/grub fi print print 'menuentry "GNU/Linux (OpenADK)" {' -# print "\tlinux /boot/vmlinuz-adk root=UUID=$partuuid $consargs panic=10" - print "\tlinux /boot/vmlinuz-adk $consargs panic=10" + linuxargs="root=UUID=$partuuid $consargs" + (( panicreboot )) && linuxargs="$linuxargs panic=$panicreboot" + print "\tlinux /boot/vmlinuz-adk $linuxargs" print '}' ) >boot/grub/grub.cfg set -A grubfiles diff --git a/target/Config.in b/target/Config.in index 50e72ef5f..8f4fc8951 100644 --- a/target/Config.in +++ b/target/Config.in @@ -770,14 +770,6 @@ config ADK_TARGET_ROOTFS_ENCRYPTED endchoice -config ADK_TARGET_ROOTFS_USB_DEVICE - prompt "Target device node for USB stick" - string - depends on ADK_TARGET_ROOTFS_USB - default "/dev/sdb1" - help - Target device node for the USB stick. - choice prompt "Compression method for initramfs and kernel" depends on ADK_TARGET_ROOTFS_INITRAMFS || ADK_TARGET_ROOTFS_INITRAMFS_PIGGYBACK diff --git a/target/linux/patches/2.6.36/uuid.patch b/target/linux/patches/2.6.36/uuid.patch new file mode 100644 index 000000000..2e6c61df9 --- /dev/null +++ b/target/linux/patches/2.6.36/uuid.patch @@ -0,0 +1,174 @@ +# DP: Add support for specifying the root device using UUIDs on the +# DP: kernel command line like this without the need for an initrd: +# DP: linux ... root=UUID=ce40d6b2-18eb-4a75-aefe-7ddb0995ce63 +# DP: +# DP: Written © 2010 by Thorsten Glaser +# DP: Idea from 1999 by David Balazic + +--- linux-2.6.36/block/genhd.c~ Wed Oct 20 22:30:22 2010 ++++ linux-2.6.36/block/genhd.c Sat Nov 20 23:14:03 2010 +@@ -35,7 +35,7 @@ struct kobject *block_depr; + static DEFINE_MUTEX(ext_devt_mutex); + static DEFINE_IDR(ext_devt_idr); + +-static struct device_type disk_type; ++struct device_type disk_type; + + /** + * disk_get_part - get partition +@@ -1019,7 +1019,7 @@ static char *block_devnode(struct device *dev, mode_t + return NULL; + } + +-static struct device_type disk_type = { ++struct device_type disk_type = { + .name = "disk", + .groups = disk_attr_groups, + .release = disk_release, +--- linux-2.6.36/init/do_mounts.c~ Wed Oct 20 22:30:22 2010 ++++ linux-2.6.36/init/do_mounts.c Sat Nov 20 23:16:07 2010 +@@ -32,6 +32,84 @@ static int __initdata root_wait; + + dev_t ROOT_DEV; + ++#ifdef CONFIG_EXT2_FS ++/* support for root=UUID=ce40d6b2-18eb-4a75-aefe-7ddb0995ce63 bootargs */ ++ ++#include ++#include ++ ++__u8 root_dev_label[16]; ++int root_dev_type; /* 0 = normal (/dev/hda1, 0301); 1 = UUID; 3 = bad */ ++ ++/* imported from block/genhd.c after removing its static qualifier */ ++extern struct device_type disk_type; ++ ++static __u8 __init fromhex(char c) ++{ ++ if (c >= '0' && c <= '9') ++ return (c - '0'); ++ c &= ~32; ++ if (c >= 'A' && c <= 'F') ++ return (c - 'A' + 10); ++ return (0xFF); ++} ++ ++static void __init parse_uuid(const char *s) ++{ ++ int i; ++ __u8 j, k; ++ ++ if (strlen(s) != 36 || s[8] != '-' || s[13] != '-' || ++ s[18] != '-' || s[23] != '-') ++ goto bad_uuid; ++ for (i = 0; i < 16; i++) { ++ if (*s == '-') ++ ++s; ++ j = fromhex(*s++); ++ k = fromhex(*s++); ++ if (j == 0xFF || k == 0xFF) ++ goto bad_uuid; ++ root_dev_label[i] = (j << 4) | k; ++ } ++ return; ++ bad_uuid: ++ /* we cannot panic here, defer */ ++ root_dev_type = 3; ++} ++ ++static int __init check_dev(dev_t devt, int blocksize) ++{ ++ /* most of this taken from fs/ext2/super.c */ ++ ++ struct buffer_head * bh; ++ struct ext2_super_block * es; ++ struct block_device *bdev; ++ unsigned long sb_block = 1; ++ unsigned long logic_sb_block; ++ unsigned long offset = 0; ++ int rv = 0; ++ ++ bdev = bdget(devt); ++ ++ if (blocksize != BLOCK_SIZE) { ++ logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize; ++ offset = (sb_block*BLOCK_SIZE) % blocksize; ++ } else { ++ logic_sb_block = sb_block; ++ } ++ ++ if (!(bh = __bread(bdev, logic_sb_block, blocksize))) ++ return (0); ++ es = (struct ext2_super_block *)(((char *)bh->b_data) + offset); ++ if (le16_to_cpu(es->s_magic) == EXT2_SUPER_MAGIC) { ++ if (!memcmp(es->s_uuid, root_dev_label, 16)) ++ rv = 1; ++ } ++ brelse(bh); ++ return (rv); ++} ++#endif /* CONFIG_EXT2_FS for UUID support */ ++ + static int __init load_ramdisk(char *str) + { + rd_doload = simple_strtol(str,NULL,0) & 3; +@@ -148,6 +226,13 @@ done: + static int __init root_dev_setup(char *line) + { + strlcpy(saved_root_name, line, sizeof(saved_root_name)); ++#ifdef CONFIG_EXT2_FS ++ root_dev_type = 0; ++ if (!strncmp(line, "UUID=", 5)) { ++ root_dev_type = 1; ++ parse_uuid(line + 5); ++ } ++#endif /* CONFIG_EXT2_FS for UUID support */ + return 1; + } + +@@ -333,6 +418,45 @@ void __init change_floppy(char *fmt, ...) + + void __init mount_root(void) + { ++#ifdef CONFIG_EXT2_FS ++ /* UUID support */ ++ if (root_dev_type == 1) { ++ int blocksize; ++ ++ /* from block/genhd.c printk_all_partitions */ ++ struct class_dev_iter iter; ++ struct device *dev; ++ ++ class_dev_iter_init(&iter, &block_class, NULL, &disk_type); ++ while (root_dev_type && (dev = class_dev_iter_next(&iter))) { ++ struct gendisk *disk = dev_to_disk(dev); ++ struct disk_part_iter piter; ++ struct hd_struct *part; ++ if (get_capacity(disk) == 0 || ++ (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)) ++ continue; ++ blocksize = queue_logical_block_size(disk->queue); ++ ++ disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); ++ while (root_dev_type && (part = disk_part_iter_next(&piter))) { ++ /* avoid empty or too small partitions */ ++ if (part->nr_sects < 8) ++ continue; ++ if (check_dev(part_devt(part), blocksize)) { ++ ROOT_DEV = part_devt(part); ++ root_dev_type = 0; ++ } ++ } ++ disk_part_iter_exit(&piter); ++ } ++ class_dev_iter_exit(&iter); ++ } ++ if (root_dev_type == 1) ++ printk(KERN_ERR "VFS: Unable to find root by UUID %s.\n", saved_root_name + 5); ++ else if (root_dev_type == 3) ++ panic("Badly formatted UUID %s was supplied as kernel parameter root", saved_root_name + 5); ++#endif /* CONFIG_EXT2_FS for UUID support */ ++ + #ifdef CONFIG_ROOT_NFS + if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) { + if (mount_nfs_root()) -- cgit v1.2.3 From 16e7dc58f0a843761e536aa2119116462472f868 Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sun, 21 Nov 2010 16:00:46 +0000 Subject: fix unlimit datasize Signed-off-by: Thorsten Glaser --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 449d3eb8a..26f80c7cf 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ # This file is part of the OpenADK project. OpenADK is copyrighted # material, please see the LICENCE file in the top-level directory. -_UNLIMIT= ulimit -dS $(shell ulimit -dH >/dev/null 2>/dev/null ) >/dev/null 2>/dev/null; +_UNLIMIT= __limit=$$(ulimit -dH 2>/dev/null); \ + test -n "$$__limit" && ulimit -dS $$__limit; all: .prereq_done @${_UNLIMIT} ${GMAKE_INV} all -- cgit v1.2.3 From d7b9445db33c1f0472a07ab6127b8d89103eff1e Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sun, 21 Nov 2010 16:10:07 +0000 Subject: add hack to be able to use /dev/svnd0c as target device on MirBSD/OpenBSD Signed-off-by: Thorsten Glaser --- scripts/install.sh | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 7ade75c68..b8f21a0c6 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -224,18 +224,28 @@ if (( coreimgsz > 65024 )); then exit 1 fi (( coreendsec = (coreimgsz + 511) / 512 )) +if [[ $basedev = /dev/svnd+([0-9]) ]]; then + # BSD svnd0 mode: protect sector #1 + corestartsec=2 + (( ++coreendsec )) + corepatchofs=$((0x614)) +else + corestartsec=1 + corepatchofs=$((0x414)) +fi # partition offset: at least coreendsec+1 but aligned on a multiple of secs (( partofs = ((coreendsec / secs) + 1) * secs )) (( quiet )) || print Preparing MBR and GRUB2... dd if=/dev/zero of="$T/firsttrack" count=$partofs 2>/dev/null -echo 1 $coreendsec | mksh "$TOPDIR/scripts/bootgrub.mksh" \ +echo $corestartsec $coreendsec | mksh "$TOPDIR/scripts/bootgrub.mksh" \ -A -g $((cyls-cfgfs)):$heads:$secs -M 1:0x83 -O $partofs | \ dd of="$T/firsttrack" conv=notrunc 2>/dev/null -dd if="$T/core.img" of="$T/firsttrack" conv=notrunc seek=1 2>/dev/null +dd if="$T/core.img" of="$T/firsttrack" conv=notrunc seek=$corestartsec \ + 2>/dev/null # set partition where it can find /boot/grub print -n '\0\0\0\0' | \ - dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x414)) 2>/dev/null + dd of="$T/firsttrack" conv=notrunc bs=1 seek=$corepatchofs 2>/dev/null # create cfgfs partition (mostly taken from bootgrub.mksh) set -A thecode @@ -283,6 +293,18 @@ print -n "$ostr" | \ (( quiet )) || print Writing MBR and GRUB2 to target device... dd if="$T/firsttrack" of="$tgt" +if [[ $basedev = /dev/svnd+([0-9]) ]]; then + print + fdisk -c $cyls -h $heads -s $secs ${basedev#/dev/} + print + print "This is a BSD vnd(4) device. You MUST now use" + print "\t\$ sudo disklabel -E svnd0" + print "to create a valid BSD disklabel on it. Make" + print "two slices i for the ext2fs partition and j" + print "for the cfgfs partition. Then press Enter." + read dummy +fi + (( quiet )) || print "Creating ext2fs on ${part}..." q= (( quiet )) && q=-q -- cgit v1.2.3 From 60f67d3883bc11f93419a97a7ae1d5103ca7efc2 Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sun, 21 Nov 2010 16:45:25 +0000 Subject: automate BSD disklabel creation; display UUID at end of the script Signed-off-by: Thorsten Glaser --- scripts/install.sh | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index b8f21a0c6..ab9c4f2cf 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -294,15 +294,37 @@ print -n "$ostr" | \ dd if="$T/firsttrack" of="$tgt" if [[ $basedev = /dev/svnd+([0-9]) ]]; then - print - fdisk -c $cyls -h $heads -s $secs ${basedev#/dev/} - print - print "This is a BSD vnd(4) device. You MUST now use" - print "\t\$ sudo disklabel -E svnd0" - print "to create a valid BSD disklabel on it. Make" - print "two slices i for the ext2fs partition and j" - print "for the cfgfs partition. Then press Enter." - read dummy + (( quiet )) || print "Creating BSD disklabel on target device..." + # c: whole device (must be so) + # i: ext2fs (matching first partition) + # j: cfgfs (matching second partition) + # p: MBR and GRUB2 area (by tradition) + cat >"$T/bsdlabel" <<-EOF + type: vnd + disk: vnd device + label: OpenADK + flags: + bytes/sector: 512 + sectors/track: $secs + tracks/cylinder: $heads + sectors/cylinder: $((heads * secs)) + cylinders: $cyls + total sectors: $((cyls * heads * secs)) + rpm: 3600 + interleave: 1 + trackskew: 0 + cylinderskew: 0 + headswitch: 0 + track-to-track seek: 0 + drivedata: 0 + + 16 partitions: + c: $((cyls * heads * secs)) 0 unused + i: $(((cyls - cfgfs) * heads * secs - partofs)) $partofs ext2fs + j: $((cfgfs * heads * secs)) $(((cyls - cfgfs) * heads * secs)) unknown + p: $partofs 0 unknown +EOF + disklabel -R ${basedev#/dev/} "$T/bsdlabel" fi (( quiet )) || print "Creating ext2fs on ${part}..." @@ -355,5 +377,7 @@ cp "${grubfiles[@]}" boot/grub/ cd "$TOPDIR" umount "$T" +(( quiet )) || print "\nNote: the rootfs UUID is: $partuuid" + rm -rf "$T" exit 0 -- cgit v1.2.3 From 57d965ea9d26e31d3a6b526cea53596494762e8e Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sun, 21 Nov 2010 17:40:26 +0000 Subject: fix a typo Signed-off-by: Thorsten Glaser --- target/linux/patches/2.6.35.7/startup.patch | 2 +- target/linux/patches/2.6.36/startup.patch | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/target/linux/patches/2.6.35.7/startup.patch b/target/linux/patches/2.6.35.7/startup.patch index cbfd4b5bf..68e8987b0 100644 --- a/target/linux/patches/2.6.35.7/startup.patch +++ b/target/linux/patches/2.6.35.7/startup.patch @@ -13,7 +13,7 @@ diff -Nur linux-2.6.34.orig/init/main.c linux-2.6.34/init/main.c if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) printk(KERN_WARNING "Warning: unable to open an initial console.\n"); -+ printk(KERN_WARNING "Starting Linux (build with OpenADK).\n"); ++ printk(KERN_WARNING "Starting Linux (built with OpenADK).\n"); + (void) sys_dup(0); (void) sys_dup(0); diff --git a/target/linux/patches/2.6.36/startup.patch b/target/linux/patches/2.6.36/startup.patch index cbfd4b5bf..68e8987b0 100644 --- a/target/linux/patches/2.6.36/startup.patch +++ b/target/linux/patches/2.6.36/startup.patch @@ -13,7 +13,7 @@ diff -Nur linux-2.6.34.orig/init/main.c linux-2.6.34/init/main.c if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) printk(KERN_WARNING "Warning: unable to open an initial console.\n"); -+ printk(KERN_WARNING "Starting Linux (build with OpenADK).\n"); ++ printk(KERN_WARNING "Starting Linux (built with OpenADK).\n"); + (void) sys_dup(0); (void) sys_dup(0); -- cgit v1.2.3 From 657cec41e61aaf926e39f8be8931df5e3422a097 Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sun, 21 Nov 2010 18:39:50 +0000 Subject: let the UUID code correctly load sectors from disc using BIO Signed-off-by: Thorsten Glaser --- target/linux/patches/2.6.36/uuid.patch | 133 +++++++++++++++++++++++++++------ 1 file changed, 110 insertions(+), 23 deletions(-) diff --git a/target/linux/patches/2.6.36/uuid.patch b/target/linux/patches/2.6.36/uuid.patch index 2e6c61df9..cf2869ed2 100644 --- a/target/linux/patches/2.6.36/uuid.patch +++ b/target/linux/patches/2.6.36/uuid.patch @@ -1,6 +1,7 @@ # DP: Add support for specifying the root device using UUIDs on the # DP: kernel command line like this without the need for an initrd: # DP: linux ... root=UUID=ce40d6b2-18eb-4a75-aefe-7ddb0995ce63 +# DP: Note: debugging code is kept in, commented out “//” style. # DP: # DP: Written © 2010 by Thorsten Glaser # DP: Idea from 1999 by David Balazic @@ -25,24 +26,24 @@ .name = "disk", .groups = disk_attr_groups, .release = disk_release, ---- linux-2.6.36/init/do_mounts.c~ Wed Oct 20 22:30:22 2010 -+++ linux-2.6.36/init/do_mounts.c Sat Nov 20 23:16:07 2010 -@@ -32,6 +32,84 @@ static int __initdata root_wait; +--- linux-2.6.36/init/do_mounts.c~ Wed Oct 20 20:29:58 2010 ++++ linux-2.6.36/init/do_mounts.c Sun Nov 21 18:37:36 2010 +@@ -32,6 +32,132 @@ static int __initdata root_wait; dev_t ROOT_DEV; +#ifdef CONFIG_EXT2_FS +/* support for root=UUID=ce40d6b2-18eb-4a75-aefe-7ddb0995ce63 bootargs */ + -+#include +#include + -+__u8 root_dev_label[16]; ++__u8 root_dev_uuid[16]; +int root_dev_type; /* 0 = normal (/dev/hda1, 0301); 1 = UUID; 3 = bad */ + +/* imported from block/genhd.c after removing its static qualifier */ +extern struct device_type disk_type; + ++/* helper function */ +static __u8 __init fromhex(char c) +{ + if (c >= '0' && c <= '9') @@ -68,7 +69,7 @@ + k = fromhex(*s++); + if (j == 0xFF || k == 0xFF) + goto bad_uuid; -+ root_dev_label[i] = (j << 4) | k; ++ root_dev_uuid[i] = (j << 4) | k; + } + return; + bad_uuid: @@ -76,19 +77,54 @@ + root_dev_type = 3; +} + -+static int __init check_dev(dev_t devt, int blocksize) ++/* from drivers/md/md.c */ ++static void __init initcode_bi_complete(struct bio *bio, int error) +{ -+ /* most of this taken from fs/ext2/super.c */ ++ complete((struct completion*)bio->bi_private); ++} ++ ++static int __init initcode_sync_page_read(struct block_device *bdev, ++ sector_t sector, int size, struct page *page) ++{ ++ struct bio *bio = bio_alloc(GFP_NOIO, 1); ++ struct completion event; ++ int ret, rw = READ; ++ ++ rw |= REQ_SYNC | REQ_UNPLUG; ++ ++ bio->bi_bdev = bdev; ++ bio->bi_sector = sector; ++ bio_add_page(bio, page, size, 0); ++ init_completion(&event); ++ bio->bi_private = &event; ++ bio->bi_end_io = initcode_bi_complete; ++ submit_bio(rw, bio); ++ wait_for_completion(&event); + -+ struct buffer_head * bh; ++ ret = test_bit(BIO_UPTODATE, &bio->bi_flags); ++ bio_put(bio); ++ /* 0 = failure */ ++ return ret; ++} ++ ++/* most of this taken from fs/ext2/super.c */ ++static int __init check_dev(struct gendisk *thedisk, dev_t devt, ++ int blocksize, struct page *page) ++{ + struct ext2_super_block * es; + struct block_device *bdev; + unsigned long sb_block = 1; + unsigned long logic_sb_block; + unsigned long offset = 0; -+ int rv = 0; ++ int rv = /* not found */ 0; ++ char bff[22]; + + bdev = bdget(devt); ++ if (blkdev_get(bdev, FMODE_READ)) { ++ printk(KERN_ERR "VFS: opening block device %s failed!\n", ++ format_dev_t(bff, devt)); ++ return (0); ++ } + + if (blocksize != BLOCK_SIZE) { + logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize; @@ -97,14 +133,27 @@ + logic_sb_block = sb_block; + } + -+ if (!(bh = __bread(bdev, logic_sb_block, blocksize))) -+ return (0); -+ es = (struct ext2_super_block *)(((char *)bh->b_data) + offset); ++// printk(KERN_ERR "D: attempting to read %d @%lu from " ++// "bdev %p devt %08X %s\n", blocksize, logic_sb_block, ++// bdev, devt, format_dev_t(bff, devt)); ++ if (!initcode_sync_page_read(bdev, logic_sb_block, blocksize, page)) { ++// printk(KERN_ERR "D: failed!\n"); ++ goto out; ++ } ++ es = (struct ext2_super_block *)(((char *)page_address(page)) + offset); + if (le16_to_cpu(es->s_magic) == EXT2_SUPER_MAGIC) { -+ if (!memcmp(es->s_uuid, root_dev_label, 16)) -+ rv = 1; ++// printk(KERN_ERR "D: has uuid " ++// "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n", ++// es->s_uuid[0], es->s_uuid[1], es->s_uuid[2], es->s_uuid[3], ++// es->s_uuid[4], es->s_uuid[5], es->s_uuid[6], es->s_uuid[7], ++// es->s_uuid[8], es->s_uuid[9], es->s_uuid[10], es->s_uuid[11], ++// es->s_uuid[12], es->s_uuid[13], es->s_uuid[14], es->s_uuid[15]); ++ if (!memcmp(es->s_uuid, root_dev_uuid, 16)) ++ rv = /* found */ 1; + } -+ brelse(bh); ++// else printk(KERN_ERR "D: bad ext2fs magic\n"); ++ out: ++ blkdev_put(bdev, FMODE_READ); + return (rv); +} +#endif /* CONFIG_EXT2_FS for UUID support */ @@ -112,7 +161,7 @@ static int __init load_ramdisk(char *str) { rd_doload = simple_strtol(str,NULL,0) & 3; -@@ -148,6 +226,13 @@ done: +@@ -148,6 +274,13 @@ done: static int __init root_dev_setup(char *line) { strlcpy(saved_root_name, line, sizeof(saved_root_name)); @@ -126,12 +175,13 @@ return 1; } -@@ -333,6 +418,45 @@ void __init change_floppy(char *fmt, ...) +@@ -333,6 +466,83 @@ void __init change_floppy(char *fmt, ... void __init mount_root(void) { +#ifdef CONFIG_EXT2_FS + /* UUID support */ ++// printk_all_partitions(); + if (root_dev_type == 1) { + int blocksize; + @@ -139,34 +189,71 @@ + struct class_dev_iter iter; + struct device *dev; + ++ /* from drivers/md/md.c */ ++ struct page *sb_page; ++ ++ if (!(sb_page = alloc_page(GFP_KERNEL))) { ++ printk(KERN_ERR "VFS: no memory for bio page\n"); ++ goto nomemforbio; ++ } ++ ++// printk(KERN_ERR "D: root is: " ++// "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n", ++// root_dev_uuid[0], root_dev_uuid[1], root_dev_uuid[2], root_dev_uuid[3], ++// root_dev_uuid[4], root_dev_uuid[5], root_dev_uuid[6], root_dev_uuid[7], ++// root_dev_uuid[8], root_dev_uuid[9], root_dev_uuid[10], root_dev_uuid[11], ++// root_dev_uuid[12], root_dev_uuid[13], root_dev_uuid[14], root_dev_uuid[15]); ++ /* from block/genhd.c printk_all_partitions */ ++// printk(KERN_ERR "D: begin iter\n"); + class_dev_iter_init(&iter, &block_class, NULL, &disk_type); + while (root_dev_type && (dev = class_dev_iter_next(&iter))) { ++// char bff[22]; + struct gendisk *disk = dev_to_disk(dev); + struct disk_part_iter piter; + struct hd_struct *part; + if (get_capacity(disk) == 0 || -+ (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)) ++ (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)) { ++// printk(KERN_ERR "D: ignoring\n"); + continue; ++ } + blocksize = queue_logical_block_size(disk->queue); -+ ++// printk(KERN_ERR "D: gendisk, blocksize %d " ++// "name '%s' devt %08X %s #part %d\n", blocksize, ++// disk->disk_name, dev->devt, ++// format_dev_t(bff, dev->devt), ++// disk_max_parts(disk)); + disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); + while (root_dev_type && (part = disk_part_iter_next(&piter))) { + /* avoid empty or too small partitions */ ++// printk(KERN_ERR "D: part #%d start %llu " ++// "nr %llu\n", part->partno, ++// (__u64)part->start_sect, ++// (__u64)part->nr_sects); + if (part->nr_sects < 8) + continue; -+ if (check_dev(part_devt(part), blocksize)) { ++ if (check_dev(disk, MKDEV(MAJOR(dev->devt), ++ MINOR(dev->devt) + part->partno), ++ blocksize, sb_page)) { + ROOT_DEV = part_devt(part); ++// printk(KERN_ERR "D: got match!\n"); ++ // comment out below for debugging + root_dev_type = 0; + } + } + disk_part_iter_exit(&piter); + } ++// printk(KERN_ERR "D: end iter\n"); + class_dev_iter_exit(&iter); ++ put_page(sb_page); + } ++ nomemforbio: + if (root_dev_type == 1) -+ printk(KERN_ERR "VFS: Unable to find root by UUID %s.\n", saved_root_name + 5); ++ printk(KERN_ERR "VFS: Unable to find root by UUID %s.\n", ++ saved_root_name + 5); + else if (root_dev_type == 3) -+ panic("Badly formatted UUID %s was supplied as kernel parameter root", saved_root_name + 5); ++ /* execute deferred panic from parse_uuid */ ++ panic("Badly formatted UUID %s was supplied as kernel " ++ "parameter root", saved_root_name + 5); +#endif /* CONFIG_EXT2_FS for UUID support */ + #ifdef CONFIG_ROOT_NFS -- cgit v1.2.3