From patchwork Fri Dec 31 09:39:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Ravnborg X-Patchwork-Id: 77052 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 6A0E4B70B3 for ; Fri, 31 Dec 2010 21:05:59 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752179Ab0LaKF6 (ORCPT ); Fri, 31 Dec 2010 05:05:58 -0500 Received: from pqueuea.post.tele.dk ([193.162.153.9]:35521 "EHLO pqueuea.post.tele.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752161Ab0LaKF6 (ORCPT ); Fri, 31 Dec 2010 05:05:58 -0500 X-Greylist: delayed 1560 seconds by postgrey-1.27 at vger.kernel.org; Fri, 31 Dec 2010 05:05:57 EST Received: from pfepb.post.tele.dk (pfepb.post.tele.dk [195.41.46.236]) by pqueuea.post.tele.dk (Postfix) with ESMTP id E6267DB98A for ; Fri, 31 Dec 2010 10:39:58 +0100 (CET) Received: from localhost.localdomain (x1-6-00-1e-2a-84-ae-3e.k225.webspeed.dk [80.163.61.94]) by pfepb.post.tele.dk (Postfix) with ESMTP id 09E36F84028; Fri, 31 Dec 2010 10:39:41 +0100 (CET) From: Sam Ravnborg To: "David S. Miller" , sparclinux Cc: Sam Ravnborg Subject: [PATCH] sparc: additional comments to piggyback_32.c Date: Fri, 31 Dec 2010 10:39:38 +0100 Message-Id: <1293788379-32709-4-git-send-email-sam@ravnborg.org> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: <20101231093628.GA19496@merkur.ravnborg.org> References: <20101231093628.GA19496@merkur.ravnborg.org> Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org While reverse engineering the functionality of piggyback I missed that the code was actually commented. So I added a few comments. Signed-off-by: Sam Ravnborg --- arch/sparc/boot/piggyback_32.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/sparc/boot/piggyback_32.c b/arch/sparc/boot/piggyback_32.c index 5c86a7d..5e856f2 100644 --- a/arch/sparc/boot/piggyback_32.c +++ b/arch/sparc/boot/piggyback_32.c @@ -36,6 +36,8 @@ * as PROM looks for a.out image only. */ +#define AOUT_TEXT_OFFSET 32 + /* read two bytes as big endian */ static unsigned short ld2(char *p) { @@ -154,12 +156,20 @@ int main(int argc,char **argv) die(argv[1]); j = 0; } else if (memcmp(buffer, aout_magic, 4) == 0) { - i = j = 32; + i = j = AOUT_TEXT_OFFSET; } else { fprintf (stderr, "Not ELF nor a.out. Don't blame me.\n"); exit(1); } k = i; + /* + * We need to fill in values for sparc_ramdisk_image + sparc_ramdisk_size + * To locate these symbols search for the "HdrS" text which appear + * in the image a little before the gokernel symbol. + * See definition of these in init_32.S + */ + + /* Find the gokernel label */ i += (ld2(buffer + j + 2) << 2) - 512; if (lseek(image, i, 0) < 0) die("lseek"); @@ -177,6 +187,13 @@ int main(int argc,char **argv) if (lseek(image, offset, 0) < 0) die("lseek"); + /* + * root_flags = 0 + * root_dev = 1 (RAMDISK_MAJOR) + * ram_flags = 0 + * sparc_ramdisk_image = "PAGE aligned address after _end") + * sparc_ramdisk_size = size of image + */ st4(buffer, 0); st4(buffer + 4, 0x01000000); st4(buffer + 8, (end + 32 + 4095) & ~4095); @@ -184,11 +201,13 @@ int main(int argc,char **argv) if (write(image, buffer + 2, 14) != 14) die(argv[1]); + + /* seek page aligned boundary in the image file and add boot image */ if (lseek(image, k - start + ((end + 32 + 4095) & ~4095), 0) < 0) die("lseek"); if ((tail = open(argv[3],O_RDONLY)) < 0) die(argv[3]); - while ((i = read (tail, buffer, 1024)) > 0) + while ((i = read(tail, buffer, 1024)) > 0) if (write(image, buffer, i) != i) die(argv[1]); if (close(image) < 0)