linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Loic Prylli <Loic.Prylli@ens-lyon.fr>
To: linuxppc-dev@lists.linuxppc.org
Subject: Re: Booting 2.2.0-pre6 on a PowerStack-II (Net 4000/200)
Date: Wed, 20 Jan 1999 14:56:59 +0100 (MET)	[thread overview]
Message-ID: <13989.56114.388702.567051@porto> (raw)
In-Reply-To: <36A4D4CE.9D957BA0@jlc.net>

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


Michael Meissner writes:
 > 
 > I see you added changes to set the initial cmd config.  Is there any way we can
 > add a configure line when building the kernel, so I can build a kernel with
 > different data (ie, my disk is /dev/sda2 and not /dev/sdb2, etc.).  That way it
 > has a better chance of working if rebooted in the middle of the night due to
 > power failure.
 > 

Some time ago, I made a small addition to Gabriel preploader, including
 a simple "prepctl" program, that permit to modify the
command-line stored in the zImage.

In my case, it is much more useful than getting the command-line
through residual data or NVRAM, because I can modify the command-line
parameters for the next reboot without needing access to the console
(you win a lot of time if you have 16 machines, moreover they are in a
closed room for which it is tedious to get the key:-). Of course this
is not an advantage anymore if there is some tools to modify NVRAM or
residual data after Linux is booted.

Anyway below is the patch, to modify the command-line of a zImage,
simply run "prepctl <zImage> <command line parameters>..." or "prepctl
/dev/sda1 ..." if it is installed on a disk partition.


[-- Attachment #2: preploader.diff --]
[-- Type: application/octet-stream, Size: 5925 bytes --]

Index: preploader/Makefile
diff -c preploader/Makefile:1.1.1.3 preploader/Makefile:1.2
*** preploader/Makefile:1.1.1.3	Wed Jan 20 09:45:40 1999
--- preploader/Makefile	Wed Jan 20 14:26:39 1999
***************
*** 59,68 ****
  
  #OBJECTS += vreset.o kbd.o
  
! zImage: $(OBJECTS) $(IMAGES) $(SIZES) ppcboot.lds
  	ld -o zImage $(OBJECTS) -b binary $(IMAGES) -T ppcboot.lds \
  	--defsym _vmlinux_size=`cut -f 1 <.vmlinux.size` -Map zImage.map
  
  # The 2 objcopy are quite ugly, but for now it was the simplest solution
  # since the flags to expand the bss do not work on a binary output format.
  # It would be better to know where the bss is and clear it in the bootloader,
--- 59,72 ----
  
  #OBJECTS += vreset.o kbd.o
  
! zImage: $(OBJECTS) $(IMAGES) $(SIZES) ppcboot.lds prepctl
  	ld -o zImage $(OBJECTS) -b binary $(IMAGES) -T ppcboot.lds \
  	--defsym _vmlinux_size=`cut -f 1 <.vmlinux.size` -Map zImage.map
  
+ prepctl: prepctl.c
+ 	$(CC) -O -o $@ $<
+ 
+ 
  # The 2 objcopy are quite ugly, but for now it was the simplest solution
  # since the flags to expand the bss do not work on a binary output format.
  # It would be better to know where the bss is and clear it in the bootloader,
Index: preploader/bootdata.h
diff -c /dev/null preploader/bootdata.h:1.1
*** /dev/null	Wed Jan 20 14:54:39 1999
--- preploader/bootdata.h	Wed Jan 20 14:27:27 1999
***************
*** 0 ****
--- 1,3 ----
+ #define MAGIC1_CMDLINE 0xe08ed9f7
+ #define MAGIC2_CMDLINE 0x3c0b8c88
+ 
Index: preploader/bootldr.h
diff -c preploader/bootldr.h:1.1.1.3 preploader/bootldr.h:1.2
*** preploader/bootldr.h:1.1.1.3	Wed Jan 20 09:45:19 1999
--- preploader/bootldr.h	Wed Jan 20 14:26:41 1999
***************
*** 73,78 ****
--- 73,81 ----
   * functions who have to access the .got2 sections (this increases the 
   * size of the prologue in every function).
   */
+ 
+ #include "bootdata.h"
+ 
  typedef struct _boot_data {
  	RESIDUAL *residual;
  	void *load_address;
***************
*** 95,101 ****
  	const struct console_io *console_functions;
  	opaque * console_private;
  	u_long ticks_per_ms;
! 	char cmd_line[256];
  } boot_data;
  
  register boot_data *bd __asm__("r13");
--- 98,106 ----
  	const struct console_io *console_functions;
  	opaque * console_private;
  	u_long ticks_per_ms;
!   unsigned long magic1;
!   char cmd_line[256];
!   unsigned long magic2;
  } boot_data;
  
  register boot_data *bd __asm__("r13");
Index: preploader/misc.c
diff -c preploader/misc.c:1.1.1.3 preploader/misc.c:1.2
*** preploader/misc.c:1.1.1.3	Wed Jan 20 09:45:33 1999
--- preploader/misc.c	Wed Jan 20 14:26:43 1999
***************
*** 48,54 ****
  		  &vacuum_console_functions,
  		  &console_private,
  		  1000000,	/* Decrementer ticks per ms (true for 601) */
! 		  "console=ttyS0"	
  		 };
  
  void exit()
--- 48,54 ----
  		  &vacuum_console_functions,
  		  &console_private,
  		  1000000,	/* Decrementer ticks per ms (true for 601) */
!                   MAGIC1_CMDLINE, "console=ttyS0" ,MAGIC2_CMDLINE
  		 };
  
  void exit()
***************
*** 70,75 ****
--- 70,88 ----
  	return dst;
  }
  
+ int strcmp(const char *p1,const char *p2) {
+   int vs1,vs2;
+   const unsigned char *s1 = p1;
+   const unsigned char *s2 = p2;
+   do {
+     vs1 = *s1++;
+     vs2 = *s2++;
+     if (vs1 != vs2)
+       return vs1 - vs2;
+   } while (vs1 && vs2);
+   return 0;
+ }
+ 
  void hang(const char *s, u_long x, ctxt *p) {
  	u_long *r1;
  #ifdef DEBUG
***************
*** 291,297 ****
  		} else {
  			select_console(&vga_console_setup);
  			/* Remove the kernel serial console parameter */
! 			bd->cmd_line[0]='\0';
  		}
  	} else if (!err) {
  		select_console(&serial_console_setup);
--- 304,311 ----
  		} else {
  			select_console(&vga_console_setup);
  			/* Remove the kernel serial console parameter */
!                         if (strcmp(bd->cmd_line,"console=ttyS0") == 0)
!                           bd->cmd_line[0]='\0';
  		}
  	} else if (!err) {
  		select_console(&serial_console_setup);
Index: preploader/prepctl.c
diff -c /dev/null preploader/prepctl.c:1.1
*** /dev/null	Wed Jan 20 14:54:40 1999
--- preploader/prepctl.c	Wed Jan 20 14:27:30 1999
***************
*** 0 ****
--- 1,64 ----
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ #include "bootdata.h"
+ 
+ #define NBINT 4096
+ #define CMDLENGTH (256/sizeof(int))
+ 
+ int main(int argc,char*argv[])
+ {
+   char buf[256];
+   static unsigned int data[NBINT*2];
+   FILE *f;
+   long pos;
+ 
+   if (argc < 2) {
+     fprintf(stderr,"usage:prepctl <zImage-file> [new command line]\n");
+     exit(1);
+   }
+   f = fopen(argv[1],argc > 2 ? "r+": "r");
+   if (!f) {
+     fprintf(stderr,"cannot open file %s\n",argv[1]);
+     perror("erreur:");
+     exit(1);
+   }
+   
+   while (1) { 
+     int i;
+     pos = ftell(f);
+     if (fread(data,sizeof(data[0]),NBINT,f) <= 0)
+       break;
+     for (i=0;i<NBINT;i++) {
+       if (data[i] == MAGIC1_CMDLINE) {
+         if (i+1+CMDLENGTH < NBINT || fread(data+NBINT,sizeof(data[0]),NBINT,f) >= i+1+CMDLENGTH-NBINT) {
+           char *p = (char*)(data+i+1);
+           int j;
+           if (data[i+1+CMDLENGTH] != MAGIC2_CMDLINE) {
+             fprintf(stderr,"ERROR:found magic1 but no magic2\n");
+             exit(1);
+           }
+           printf("current cmdline=%s\n",p);
+           if (argc <= 2)
+             return 0;
+           p[0] = 0;
+           for (j=2;j<argc;j++) {
+             strcat(p,argv[j]);
+             strcat(p," ");
+           }
+           printf("writing new cmdline=%s\n",p);
+           fflush(f);
+           fseek(f,pos,SEEK_SET);
+           if (fwrite(data,sizeof(data[0]),i+1+CMDLENGTH,f) != i+1+CMDLENGTH) {
+             perror("writing new cmd line\n");
+             exit(1);
+           }
+           return 0;
+         }
+       }
+     }
+   }
+   fprintf(stderr,"magic1 number not found in image\n");
+   return 0;
+ }

  reply	other threads:[~1999-01-20 13:56 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-12 22:43 Booting 2.2.0-pre6 on a PowerStack-II (Net 4000/200) Michael Meissner
1999-01-13 20:10 ` Cort Dougan
1999-01-15 15:28   ` Alois Fertl
1999-01-15 20:10     ` Cort Dougan
1999-01-15 21:58     ` Michael Meissner
1999-01-15 22:04       ` Cort Dougan
1999-01-15 23:33         ` Michael Meissner
1999-01-18  8:51           ` Alois Fertl
1999-01-16  1:49       ` Johnnie Peters
1999-01-16 18:54         ` Dan Malek
1999-01-17 18:58           ` Cort Dougan
1999-01-18  9:21             ` Gabriel Paubert
1999-01-18 13:01           ` Gary Thomas
1999-01-18 16:54             ` Cort Dougan
1999-01-18 17:58               ` Michael Meissner
1999-01-19 22:43                 ` Michael Meissner
1999-01-20  0:18                   ` Johnnie Peters
1999-01-20  3:53                     ` 3-button mouse Brent H Mundy
1999-01-20 22:20                       ` Benjamin Herrenschmidt
1999-01-21  9:34                         ` pre8(vger) kills button 3 on 1-button mouse Martin Costabel
1999-01-21 10:05                         ` 3-button mouse fritzwe.linux
1999-01-20 15:21                     ` Booting 2.2.0-pre6 on a PowerStack-II (Net 4000/200) Gary Thomas
1999-01-20 15:31                       ` Johnnie Peters
1999-01-21 23:46                       ` Johnnie Peters
1999-01-22  1:52                         ` Michael Meissner
1999-01-22  2:04                           ` Cort Dougan
1999-01-22  7:54                             ` Gary Thomas
1999-01-22  8:19                               ` Cort Dougan
1999-01-22 11:07                                 ` Gary Thomas
1999-01-22 15:17                               ` Johnnie Peters
1999-02-01 15:58                       ` Michael Meissner
1999-02-01 16:18                         ` Gary Thomas
1999-02-04 19:09                           ` Michael Meissner
1999-02-04 19:21                             ` Gary Thomas
1999-02-04 20:23                               ` Michael Meissner
     [not found]               ` <XFMail.990119102730.gdt@linuxppc.org>
1999-01-19 13:13                 ` Michael Meissner
1999-01-19 13:28                   ` Gary Thomas
1999-01-19 18:54                     ` Dan Malek
1999-01-20 13:56                       ` Loic Prylli [this message]
1999-01-18 18:11             ` Dan Malek
  -- strict thread matches above, loose matches on Subject: below --
1999-01-16  2:23 Johnnie Peters

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=13989.56114.388702.567051@porto \
    --to=loic.prylli@ens-lyon.fr \
    --cc=linuxppc-dev@lists.linuxppc.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).