Skip to contentSkip to conversation

sparc: unify sparc/boot/piggyback

PATCH In review Sam Ravnborg 4 participants 9 messages Jan 1, 2011 – Jan 5, 2011 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

v2 cover sparc: unify sparc/boot/piggyback

I decided to complete the unification of piggyback. This was inspired by comments from Julian Calaby.

The patchset documents my findings while reverse engineering piggyback. And some limited refactoring also increased readability a lot.
piggyback now takes an argument that tell if this is for sparc or sparc64 and uses this info to adjust behaviour as sparc and sparc64 differs in a few places.

With these additions we can now use the same piggyback for both sparc and sparc64.

My testing turned out that piggyback_64 was broken on my x86 box, because it was hardcoded to assume a big-endian host.
I also found a few code-spots that assuemd the host was big-endian. All cases are fixed to be endian neutral.

Julian Calaby acknowledged that piggyback_64 had endian troubles.

This is boot tested on my sparc box.
I have only build tested the sparc64 bits!

Since v1 of the patchset I have included 4 additional patches, the original 5 patches has not seen any updates.
And the patches are properly numbered this time.

Sam

Sam Ravnborg (9):
sparc: refactor piggy_32.c
sparc: use trapbase in setup_arch
sparc: use _start for the start entry (like 64 bit does)
sparc: additional comments to piggyback_32.c
sparc: remove obsolete ELF support in piggyback_32.c
sparc: add $BITS to piggyback arguments
sparc: use piggyback_32 for sparc64
sparc: rename piggyback_32 to piggyback
sparc: unify strip command in boot/Makefile

 arch/sparc/boot/Makefile       |   28 ++---
 arch/sparc/boot/piggyback.c    |  266 ++++++++++++++++++++++++++++++++++++++++
 arch/sparc/boot/piggyback_32.c |  137 ---------------------
 arch/sparc/boot/piggyback_64.c |  110 -----------------
 arch/sparc/kernel/head_32.S    |    3 +-
 arch/sparc/kernel/setup_32.c   |    3 +-
 arch/sparc/mm/sun4c.c          |    8 +-
 7 files changed, 280 insertions(+), 275 deletions(-)
#1 lore raw
Quoted 2 lines · Sam Ravnborg

I decided to complete the unification of piggyback. This was inspired by comments from Julian Calaby.

=)

Quoted 9 lines

The patchset documents my findings while reverse engineering piggyback. And some limited refactoring also increased readability a lot.
piggyback now takes an argument that tell if this is for sparc or sparc64 and uses this info to adjust behaviour as sparc and sparc64 differs in a few places.

With these additions we can now use the same piggyback for both sparc and sparc64.

Yay!

Quoted 6 lines

My testing turned out that piggyback_64 was broken on my x86 box, because it was hardcoded to assume a big-endian host.
I also found a few code-spots that assuemd the host was big-endian. All cases are fixed to be endian neutral.

Julian Calaby acknowledged that piggyback_64 had endian troubles.

Well, in as much as it'd never been fixed like _32 had.

Quoted 2 lines

This is boot tested on my sparc box.
I have only build tested the sparc64 bits!

I'll try to get my box running in the near future and give you an update on this.

That said, I know that my old endian fixed version of piggyback_64 works, so I'll do a quick check first to ensure that your version produces the same output.

Thanks,

Signature · 5 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/
#2 lore raw
In reply to Sam Ravnborg
Quoted 4 lines

That said, I know that my old endian fixed version of piggyback_64 works, so I'll do a quick check first to ensure that your version produces the same output.

Testing like this would be great.

Sam

#3 lore raw
In reply to Sam Ravnborg
Quoted 18 lines · Sam Ravnborg

I decided to complete the unification of piggyback. This was inspired by comments from Julian Calaby.

The patchset documents my findings while reverse engineering piggyback. And some limited refactoring also increased readability a lot.
piggyback now takes an argument that tell if this is for sparc or sparc64 and uses this info to adjust behaviour as sparc and sparc64 differs in a few places.

With these additions we can now use the same piggyback for both sparc and sparc64.

My testing turned out that piggyback_64 was broken on my x86 box, because it was hardcoded to assume a big-endian host.
I also found a few code-spots that assuemd the host was big-endian. All cases are fixed to be endian neutral.

Quoted 8 lines

Julian Calaby acknowledged that piggyback_64 had endian troubles.

This is boot tested on my sparc box.
I have only build tested the sparc64 bits!

Since v1 of the patchset I have included 4 additional patches, the original 5 patches has not seen any updates.
And the patches are properly numbered this time.

I have a v3 pending - so please do not apply this serie. I will post it soon - awaiting any additional feedback.

Updates planned:
- addess Josip's comments
- redo changelog to document that we fix pggyback on little-endian host.

Sam

#5 lore raw
In reply to Sam Ravnborg
Quoted 6 lines · Sam Ravnborg
Quoted 4 lines

That said, I know that my old endian fixed version of piggyback_64 works, so I'll do a quick check first to ensure that your version produces the same output.

Testing like this would be great.

Update:

I've found an old laptop with a serial port to use as a serial console and resurrected my Ultra 1e. I decided to upgrade it to the latest Debian Squeeze, and it now won't load SILO. *sigh*. On boot, it fails with the message "Fast data access MMU miss" before SILO even prints anything. Apparently these messages are due to things being too large according to the ubuntu forums, but this occurs before SILO even loads, which makes me suspicious. I'll have to investigate further, but that means I'll have to take a trip to an installer environment - and given that I now lack the machine I had set up for installing them off, that's going to be difficult at best. I'm thinking a complete re-install might be an idea, but I've had persistent issues getting my Ultra 5 to install in the past, so I'm concerned that this might not happen.

So, the net result of that machine becoming FUBAR is that I now have no way to compile anything for SPARC as that was my last working SPARC compilation platform. ARGH!

I've attached my endian fix patch for piggyback_64.c. I have previously confirmed - by generating piggyback files with an empty root-image - that this produces identical files (same SHA1 sums) to the original version before any cleanup patches under a sparc64 environment. If you'd perform the same test between the output of a version with this patch and your new version you should be able to confirm that it's working properly.

Sorry about all this fuckup, but .... that's life =(

At least it gives me more reason to get my Ultra 5 running. (It's the one that I've been unable to install)

Thanks,

Signature · 5 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/
arch/sparc/boot/piggyback_64.c +30 -12
index a26a686..06e0917 100644
@@ -32,6 +32,24 @@
 /* Note: run this on an a.out kernel (use elftoaout for it), as PROM looks for a.out image onlly
    usage: piggyback vmlinux System.map tail, where tail is gzipped fs of the initial ramdisk */
 
+unsigned short ld2(char *p)
+{
+	return (p[0] << 8) | p[1];
+}
+
+unsigned int ld4(char *p)
+{
+	return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+}
+
+void st4(char *p, unsigned int x)
+{
+	p[0] = x >> 24;
+	p[1] = x >> 16;
+	p[2] = x >> 8;
+	p[3] = x;
+}
+
 static void die(char *str)
 {
 	perror (str);
@@ -40,6 +58,7 @@ static void die(char *str)
 
 int main(int argc,char **argv)
 {
+	static char aout_magic[] = { 0x01, 0x03, 0x01, 0x07 };
 	char buffer [1024], *q, *r;
 	unsigned int i, j, k, start, end, offset;
 	FILE *map;
@@ -60,13 +79,12 @@ int main(int argc,char **argv)
 	if ((image = open(argv[1],O_RDWR)) < 0) die(argv[1]);
 	if (read(image,buffer,512) != 512) die(argv[1]);
 	if (!memcmp (buffer, "\177ELF", 4)) {
-		unsigned int *p = (unsigned int *)(buffer + *(unsigned int *)(buffer + 28));
-		
-		i = p[1] + *(unsigned int *)(buffer + 24) - p[2];
+		q = buffer + ld4(buffer + 28);
+		i = ld4(q + 4) + ld4(buffer + 24) - ld4(q + 8);
 		if (lseek(image,i,0) < 0) die("lseek");
 		if (read(image,buffer,512) != 512) die(argv[1]);
 		j = 0;
-	} else if (*(unsigned int *)buffer == 0x01030107) {
+	} else if (memcmp(buffer, aout_magic, 4) == 0) {
 		i = j = 32;
 	} else {
 		fprintf (stderr, "Not ELF nor a.out. Don't blame me.\n");
@@ -76,7 +94,7 @@ int main(int argc,char **argv)
 	if (j == 32 && buffer[40] == 'H' && buffer[41] == 'd' && buffer[42] == 'r' && buffer[43] == 'S') {
 		offset = 40 + 10;
 	} else {
-		i += ((*(unsigned short *)(buffer + j + 2))<<2) - 512;
+		i += (ld2(buffer + j + 2) << 2) - 512;
 		if (lseek(image,i,0) < 0) die("lseek");
 		if (read(image,buffer,1024) != 1024) die(argv[1]);
 		for (q = buffer, r = q + 512; q < r; q += 4) {
@@ -90,15 +108,15 @@ int main(int argc,char **argv)
 		offset = i + (q - buffer) + 10;
 	}
 	if (lseek(image, offset, 0) < 0) die ("lseek");
-	*(unsigned *)buffer = 0;
-	*(unsigned *)(buffer + 4) = 0x01000000;
-	*(unsigned *)(buffer + 8) = ((end + 32 + 8191) & ~8191);
-	*(unsigned *)(buffer + 12) = s.st_size;
+	st4(buffer, 0);
+	st4(buffer + 4, 0x01000000);
+	st4(buffer + 8, (end + 32 + 8191) & ~8191);
+	st4(buffer + 12, s.st_size);
 	if (write(image,buffer+2,14) != 14) die (argv[1]);
 	if (lseek(image, 4, 0) < 0) die ("lseek");
-	*(unsigned *)buffer = ((end + 32 + 8191) & ~8191) - (start & ~0x3fffffUL) + s.st_size;
-	*(unsigned *)(buffer + 4) = 0;
-	*(unsigned *)(buffer + 8) = 0;
+	st4(buffer, ((end + 32 + 8191) & ~8191) - (start & ~0x3fffffUL) + s.st_size);
+	st4(buffer + 4, 0);
+	st4(buffer + 8, 0);
 	if (write(image,buffer,12) != 12) die (argv[1]);
 	if (lseek(image, k - start + ((end + 32 + 8191) & ~8191), 0) < 0) die ("lseek");
 	if ((tail = open(argv[3],O_RDONLY)) < 0) die(argv[3]);
#6 lore raw
In reply to Sam Ravnborg
Quoted 5 lines · Julian Calaby

I've found an old laptop with a serial port to use as a serial console and resurrected my Ultra 1e. I decided to upgrade it to the latest Debian Squeeze, and it now won't load SILO. *sigh*. On boot, it fails with the message "Fast data access MMU miss" before SILO even prints anything. Apparently these messages are due to things being too large

Quoted 8 lines

according to the ubuntu forums, but this occurs before SILO even loads, which makes me suspicious. I'll have to investigate further, but that means I'll have to take a trip to an installer environment - and given that I now lack the machine I had set up for installing them off, that's going to be difficult at best. I'm thinking a complete re-install might be an idea, but I've had persistent issues getting my Ultra 5 to install in the past, so I'm concerned that this might not happen.

Have seen this happening on different sparc boxes, several times.

Boot the install cd, now in rescue mode. Chrooting the installed partition and run # silo -u -f again. Next reboot the Ultra.

Thanks,

Frans van Berckel

#7 lore raw
In reply to Sam Ravnborg
Quoted 4 lines · Frans van Berckel

Have seen this happening on different sparc boxes, several times.

Boot the install cd, now in rescue mode. Chrooting the installed partition and run # silo -u -f again. Next reboot the Ultra.

You can find more about it ... http://tinyurl.com/382l2sf

"The Debian bug was caused by kernel 2.6.30 incorrectly reporting the machine type via uname, so SILO was installing the 32-bit second stage boot loader instead of 64-bit one, which leads to a failure like that"

Thanks,

Frans van Berckel

#8 lore raw
In reply to Sam Ravnborg
Quoted 15 lines · Frans van Berckel
Quoted 5 lines · Julian Calaby

I've found an old laptop with a serial port to use as a serial console and resurrected my Ultra 1e. I decided to upgrade it to the latest Debian Squeeze, and it now won't load SILO. *sigh*. On boot, it fails with the message "Fast data access MMU miss" before SILO even prints anything. Apparently these messages are due to things being too large

Quoted 8 lines

according to the ubuntu forums, but this occurs before SILO even loads, which makes me suspicious. I'll have to investigate further, but that means I'll have to take a trip to an installer environment - and given that I now lack the machine I had set up for installing them off, that's going to be difficult at best. I'm thinking a complete re-install might be an idea, but I've had persistent issues getting my Ultra 5 to install in the past, so I'm concerned that this might not happen.

Quoted 4 lines

Have seen this happening on different sparc boxes, several times.

Boot the install cd, now in rescue mode. Chrooting the installed partition and run # silo -u -f again. Next reboot the Ultra.

Thanks!!!!!

After a bit of stuffing around involving a broken CD-ROM drive, a very slow laptop, broken installer images and the realisation that TFTPboot images are not ISOs, I managed to finally get in and do that and it works like a charm

Thanks!

Signature · 5 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/