Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* [Patch] Changes to aboot to recognize DOS style partitions
@ 2001-01-08  5:15 Alan Young
  2001-01-08  6:57 ` W Bauske
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Young @ 2001-01-08  5:15 UTC (permalink / raw)
  To: axp-list

[-- Attachment #1: Type: text/plain, Size: 1137 bytes --]

Hi all,

Attached is a patch to aboot 0.7a that will give it the capability
to recognize a DOS style primary (not extended) partition table
on a hard disk.

After applying the patch and recompiling aboot, you can then boot
linux from SRM like so:

>>>boot dva0,dkb100 -fi vmlinux.gz -fl "root=/dev/sda1"

This is slightly different than the standard SRM boot command
as it specifies two boot devices.  (I don't know what Tru64
does with the second parm.)  What the changed aboot does is
this: SRM loads aboot off of dva0 (floppy), the the modified
aboot code will look at the SRM boot variable and see if a
second boot device is specified in the boot command.  If there
is one, then the second device is mounted and the kernel is
loaded from partition.  In the above example, dkb100 is a drive
on my second SCSI controller at ID 1.  You will need to do a
"show dev" on the SRM console and subsitute this for your disk
ID.  Also, you will want to change root= to point to you root
partition.

I've tested this on a LX164 with SRM 5.8.

If anyone is interested in binaries, please let me know and
I can upload them to alphalinux.org.

Alan

[-- Attachment #2: aboot-0.7a-dos-partition.patch --]
[-- Type: application/octet-stream, Size: 7356 bytes --]

diff -u aboot-0.7a/ChangeLog aboot-0.7a-alan/ChangeLog
--- aboot-0.7a/ChangeLog	Tue Jun 27 09:06:06 2000
+++ aboot-0.7a-alan/ChangeLog	Thu Jan  7 19:29:44 2021
@@ -1,3 +1,16 @@
+2001-01-07  Alan Young  <ayoung@teleport.com>
+        * disk.c: Added logic to look for and interpret a DOS style
+	partition.  A DOS partition will only be looked for if no BSD
+	disklabel is found on the boot disk.  These changes ONLY
+	SUPPORT PRIMARY PARTITIONS.  No extended partition support
+	has been coded.  In addition, the changes only support a EXT2
+	type filesystem as that is all aboot currently supports.
+	* disk.c: If two boot devices are specified on the SRM console
+	command line (i.e. boot dva0,dkb100 ), the second device is used
+	as the filesystem to load the kernel from.  This allows aboot to
+	boot from floppy and load a kernel from the hard disk (or CD).
+	* disk.c: Changed the help menu to be in alphabetical order. :)
+
 2000-06-27  David Huggins-Daines  <dhd@linuxcare.com>
 
 	* README: Removed the doc/ subdirectory, since it was out of sync
diff -u aboot-0.7a/aboot.c aboot-0.7a-alan/aboot.c
--- aboot-0.7a/aboot.c	Tue Jun 27 08:40:08 2000
+++ aboot-0.7a-alan/aboot.c	Sat Jan  6 23:42:54 2001
@@ -53,6 +53,7 @@
 struct segment* chunks;
 int             nchunks;
 
+char		boot_dev[256] = "";
 char		boot_file[256] = "";
 char		initrd_file[256] = "";
 char		kernel_args[256] = "";
diff -u aboot-0.7a/disk.c aboot-0.7a-alan/disk.c
--- aboot-0.7a/disk.c	Tue Jun 27 08:52:50 2000
+++ aboot-0.7a-alan/disk.c	Thu Jan  7 19:36:42 2021
@@ -3,6 +3,7 @@
  *
  * This file is part of aboot, the SRM bootloader for Linux/Alpha
  * Copyright (C) 1996 Linus Torvalds, David Mosberger, and Michael Schwingen.
+ * Modifications to read a DOS style partition completed by Alan Young.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -33,6 +34,7 @@
 #include <bootfs.h>
 #include <cons.h>
 #include <disklabel.h>
+#include <doslabel.h>
 #include <utils.h>
 
 #include <linux/elf.h>
@@ -46,6 +48,7 @@
 extern struct bootfs dummyfs;
 
 struct disklabel * label;
+struct doslabel  * DOS_label;
 int boot_part = -1;
 
 static struct bootfs *bootfs[] = {
@@ -297,6 +300,86 @@
 }
 
 
+static void
+get_DOS_partition (long dev)
+{
+	static char lsect[512], fake_lsect[512];
+	long nread;
+	long i;
+	struct d_partition               * BSDpart;
+	struct DOS_partition_table_entry * DOSpart;
+
+#ifdef DEBUG
+	printf("get_DOS_partition(dev=%lx)\n", dev);
+#endif
+	/* Read the partition table from device dev into lsect.			*/
+	/* The DOS partition table starts at the first sector of the hard disk. */
+	nread = cons_read(dev, &lsect, sizeof(*DOS_label), 0);
+	
+	if (nread != sizeof(*DOS_label)) {
+		printf("aboot: read of DOS disklabel sector failed (nread=%ld)\n",
+		       nread);
+		return;
+	}
+	
+	/* Overlay the sector read from the disk buffer with a structure format... */
+	DOS_label = (struct doslabel*) &lsect[0];
+	
+	/* Attempt to do some basic validation on the structure */
+	if (DOS_label->DOS_magic == 0xAA55)
+	{
+	  printf("aboot: DOS style disklabel found.\n");
+	  
+	  /* Fake out the rest of aboot by copying the DOS parition     */
+	  /* table values to the corresponding values in the disklabel. */
+	  label = (struct disklabel*) &fake_lsect[LABELOFFSET];
+	  
+	  /* set the magic bits */
+	  label->d_magic  = DISKLABELMAGIC;
+	  label->d_magic2 = DISKLABELMAGIC;
+	  
+	  label->d_secsize=512;		/* Not sure if the console translates > 512 */
+	  label->d_npartitions=0;
+
+	  /* copy the primary partition table entries to the disklabel table. */	  
+	  for(i=0;i < 4;i++) {
+
+	     DOSpart = &DOS_label->DOS_entry[i];
+
+#ifdef DEBUG
+	     printf("i=%ul DOSpart->sys_ind=%02X ->start_sector=%ul ->num_sects=%ul\n",
+	     	i,DOSpart->sys_ind,DOSpart->start_sector,DOSpart->num_sects);
+#endif
+
+	     if (DOSpart->sys_ind != 0x00) {
+	     
+		label->d_npartitions++;
+		BSDpart = &label->d_partitions[i];
+		BSDpart->p_size   = DOSpart->num_sects;
+		BSDpart->p_offset = DOSpart->start_sector;
+		BSDpart->p_fsize  = 1;
+	     
+		if (DOSpart->sys_ind == 0x83)		/* ext2 */
+			BSDpart->p_fstype = FS_EXT2;
+		else
+			if (DOSpart->sys_ind == 0x82)	/* swap */
+			  BSDpart->p_fstype = FS_SWAP;
+			else
+			  /* mark it as unused - i.e. FAT or something else */
+			  BSDpart->p_fstype = FS_UNUSED;
+		  
+		BSDpart->p_frag = 0x00;
+		BSDpart->p_cpg  = 0x00;
+	     }
+	  }	  
+	}
+	else {
+		printf("aboot: no DOS style disklabel found.\n");
+		DOS_label = 0;
+	}
+}
+
+
 struct bootfs *
 mount_fs (long dev, int partition)
 {
@@ -507,14 +590,15 @@
 print_help(void)
 {
 	printf("Commands:\n"
-	       " h, ?			Display this message\n"
-	       " q			Halt the system and return to SRM\n"
-	       " p 1-8			Look in partition <num> for configuration/kernel\n"
-	       " l			List preconfigured kernels\n"
-	       " d <dir>		List directory <dir> in current filesystem\n"
 	       " b <file> <args>	Boot kernel in <file> (- for raw boot)\n"
-	       " i <file>		Use <file> as initial ramdisk\n"
 	       "			with arguments <args>\n"
+	       " c <dev>		Change boot device to <dev>\n"
+	       " d <dir>		List directory <dir> in current filesystem\n"
+	       " h, ?			Display this message\n"
+	       " i <file>		Use <file> as initial ramdisk\n"
+	       " l			List preconfigured kernels\n"
+	       " p 1-8			Look in partition <num> for configuration/kernel\n"
+	       " q			Halt the system and return to SRM\n"
 	       " 0-9			Boot preconfiguration 0-9 (list with 'l')\n");
 }
 
@@ -674,6 +758,17 @@
 			case '0' ... '9':
 				preset = buf[0];
 				break;
+			case 'c':
+				/* skip past whitespace */
+				p = strchr(buf, ' ');
+				while (p && *p == ' ') ++p;
+				if (p)
+					strcpy(boot_dev, p);
+				else {
+					printf("Please specify a SRM device name to use as a boot device\n");
+				}
+				break;
+			
 			default:
 				break;
 
@@ -775,7 +870,8 @@
 long
 load_kernel (void)
 {
-	char envval[256];
+	char envval[256], envbootdev[256];
+	char *p;
 	long result;
 	long dev;
 
@@ -793,8 +889,30 @@
 		printf("aboot: Can't get BOOTED_DEV environment variable!\n");
 		return -1;
 	}
+	/*
+	 * check BOOT_DEV vs. BOOTED_DEV, if a second BOOT_DEV device was
+	 * specified, then use it to boot from.  This allows aboot to load
+	 * from one medium and boot a kernel from another.  An example
+	 * being booting aboot from floppy and loading the kernel from
+	 * a DOS partitioned hard disk.
+	 */
+	if (cons_getenv(ENV_BOOT_DEV, envbootdev, sizeof(envbootdev)) < 0) {
+		printf("aboot: Can't get BOOT_DEV environment variable!\n");
+	}
 #endif
 
+	/*
+	 * This loops through the boot dev string looking for a comma
+	 * that (may) seperate the two specified boot devices.
+	 */
+	p=&envbootdev[0];
+	while (p && *p != ',') ++p;
+	if (p) {
+	    strcpy(boot_dev, (++p));
+            printf("aboot: overriding ENV_BOOTED_DEV with '%s'\n", boot_dev);
+            strcpy(envval,boot_dev);
+        }
+
 	printf("aboot: booting from device '%s'\n", envval);
 	dev = cons_open(envval);
 	if (dev < 0) {
@@ -804,6 +922,9 @@
 	}
 	dev &= 0xffffffff;
 	get_disklabel(dev);
+	/* If no disklabel was found, then look for a DOS style partition format. */
+	if (label == 0)
+	   get_DOS_partition(dev);
 
 	while (1) {
 		get_options(dev);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-01-08 16:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-01-08  5:15 [Patch] Changes to aboot to recognize DOS style partitions Alan Young
2001-01-08  6:57 ` W Bauske
2001-01-08 16:21   ` Alan Young

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox