[OpenBIOS] r542 - trunk/openbios-devel/modules

svn at openbios.org svn at openbios.org
Sun Aug 9 00:00:10 CEST 2009


Author: laurent
Date: 2009-08-09 00:00:10 +0200 (Sun, 09 Aug 2009)
New Revision: 542

Modified:
   trunk/openbios-devel/modules/mac-parts.c
   trunk/openbios-devel/modules/mac-parts.h
Log:
If the partition type is the mac partition type, this patch allows to
not select the partition to boot from but to boot from the first 
bootable partition.

"PowerPC Microprocessor Common Hardware Reference Platform (CHRP)
System binding to:
IEEE Std 1275-1994 Standard for Boot (Initialization, Configuration) 
Firmware
Revision: 1.8"

"Chapter 11.1.2. Open Method Algorith"

"[...] If the partition component is present, it selects the desired 
partition, where partition 0 refers to the entire disk, partition 1 
refers to the first partition, partition 2 to the second, and so forth. 
If the partition component is absent and the disk has an FDISK or Mac 
partition, the first "bootable" partition is used. [...]"



Modified: trunk/openbios-devel/modules/mac-parts.c
===================================================================
--- trunk/openbios-devel/modules/mac-parts.c	2009-08-08 21:56:26 UTC (rev 541)
+++ trunk/openbios-devel/modules/mac-parts.c	2009-08-08 22:00:10 UTC (rev 542)
@@ -45,23 +45,21 @@
 	char *str = my_args_copy();
 	xt_t seek_xt = find_parent_method("seek");
 	xt_t read_xt = find_parent_method("read");
-	int bs, parnum=-1;
+	int bs, parnum=0;
 	desc_map_t dmap;
 	part_entry_t par;
+	int ret = 0;
 
 	if( str ) {
 		parnum = atol(str);
-		if( !strlen(str) )
-			parnum = 1;
-		free( str );
+		if( *str == 0 || *str == ',' )
+			parnum = -1;
 	}
-	if( parnum < 0 )
-		parnum = 0;
 
 	DPRINTF("macparts_open %d\n", parnum);
 	SEEK( 0 );
 	if( READ(&dmap, sizeof(dmap)) != sizeof(dmap) )
-		RET(0);
+		goto out;
 
 	/* partition maps might support multiple block sizes; in this case,
 	 * pmPyPartStart is typically given in terms of 512 byte blocks.
@@ -70,33 +68,75 @@
 	if( bs != 512 ) {
 		SEEK( 512 );
 		READ( &par, sizeof(par) );
-		if( par.pmSig == 0x504d /* 'PM' */ )
+		if( par.pmSig == DESC_PART_SIGNATURE )
 			bs = 512;
 	}
+	SEEK( bs );
+	if( READ(&par, sizeof(par)) != sizeof(par) )
+		goto out;
+        if (par.pmSig != DESC_PART_SIGNATURE)
+		goto out;
+
+        if (parnum == -1) {
+		/* search a bootable partition */
+		/* see PowerPC Microprocessor CHRP bindings */
+
+		parnum = 1;
+		while (parnum <= par.pmMapBlkCnt) {
+			SEEK( (bs * parnum) );
+			READ( &par, sizeof(par) );
+			if( par.pmSig != DESC_PART_SIGNATURE ||
+                            !par.pmPartBlkCnt )
+				goto out;
+
+			if( (par.pmPartStatus & kPartitionAUXIsBootValid) &&
+			    (par.pmPartStatus & kPartitionAUXIsValid) &&
+			    (par.pmPartStatus & kPartitionAUXIsAllocated) &&
+			    (par.pmPartStatus & kPartitionAUXIsReadable) &&
+			    (strcmp(par.pmProcessor, "PowerPC") == 0) ) {
+				di->blocksize =(uint)bs;
+				di->offs = (llong)par.pmPyPartStart * bs;
+				di->size = (llong)par.pmPartBlkCnt * bs;
+				ret = -1;
+				goto out;
+			}
+
+			parnum++;
+		}
+		/* not found */
+		ret = 0;
+		goto out;
+        }
+
 	if (parnum == 0) {
 		di->blocksize =(uint)bs;
 		di->offs = (llong)0;
 		di->size = (llong)dmap.sbBlkCount * bs;
-		PUSH( -1 );
-		return;
+		ret = -1;
+		goto out;
 	}
-	SEEK( bs );
-	if( READ(&par, sizeof(par)) != sizeof(par) )
-		RET(0);
-	if( parnum > par.pmMapBlkCnt || par.pmSig != 0x504d /* 'PM' */ )
-		RET(0);
 
+	if( parnum > par.pmMapBlkCnt)
+		goto out;
+
 	SEEK( (bs * parnum) );
 	READ( &par, sizeof(par) );
+	if( par.pmSig != DESC_PART_SIGNATURE || !par.pmPartBlkCnt )
+		goto out;
+	if( !(par.pmPartStatus & kPartitionAUXIsValid) ||
+	    !(par.pmPartStatus & kPartitionAUXIsAllocated) ||
+	    !(par.pmPartStatus & kPartitionAUXIsReadable) )
+		goto out;
 
-	if( par.pmSig != 0x504d /* 'PM' */ || !par.pmPartBlkCnt )
-		RET(0);
-
+	ret = -1;
 	di->blocksize =(uint)bs;
 	di->offs = (llong)par.pmPyPartStart * bs;
 	di->size = (llong)par.pmPartBlkCnt * bs;
 
-	PUSH( -1 );
+out:
+	if (str)
+		free(str);
+	PUSH( ret);
 }
 
 /* ( block0 -- flag? ) */

Modified: trunk/openbios-devel/modules/mac-parts.h
===================================================================
--- trunk/openbios-devel/modules/mac-parts.h	2009-08-08 21:56:26 UTC (rev 541)
+++ trunk/openbios-devel/modules/mac-parts.h	2009-08-08 22:00:10 UTC (rev 542)
@@ -20,7 +20,23 @@
 /* This information is based upon IM vol V. */
 
 #define DESC_MAP_SIGNATURE	0x4552
+#define DESC_PART_SIGNATURE	0x504d
 
+enum {
+	kPartitionAUXIsValid         = 0x00000001,
+	kPartitionAUXIsAllocated     = 0x00000002,
+	kPartitionAUXIsInUse         = 0x00000004,
+	kPartitionAUXIsBootValid     = 0x00000008,
+	kPartitionAUXIsReadable      = 0x00000010,
+	kPartitionAUXIsWriteable     = 0x00000020,
+	kPartitionAUXIsBootCodePositionIndependent = 0x00000040,
+	kPartitionISMountedAtStartup = 0x40000000,
+	kPartitionIsStartup          = 0x80000000,
+	kPartitionIsChainCompatible  = 0x00000100,
+	kPartitionIsRealDeviceDriver = 0x00000200,
+	kPartitionCanChainToNext     = 0x00000400,
+};
+
 typedef struct {
 	long		ddBlock;		/* first block of driver */
 	short		ddSize;			/* driver size in blocks */




More information about the OpenBIOS mailing list