[jornada] A faster alternative to file2hex

From: Peter Gerwinski <peter_at_gerwinski.de>
Date: Mon, 24 Jun 2002 20:37:15 +0200

Hi, everyone stuck with CIBD!

(CIBD = Compiled-In Block Device. It is needed to boot Linux on
platforms where the bootloader has limited control over the system
- such as hpcboot started from MS Windows CE on the HP Jornada
710/720.)

I observed that the way a CIBD is compiled into the Linux kernel
is way too slow for doing serious debugging with it. The following
is faster:

 - Instead of running `makeh', save the following two lines as the
   contents of `drivers/block/cibd.h':

     static unsigned char cibd_fs[2 * 1024 * 1024] =
       { 3, 1, 4, 1, 5, 9, 2, 6 };

   Compiling this will result in an `rc.o' that has 2 MB of free
   space in it, starting with some "magic" bytes.
 
 - Now, use my little program `file2o' to copy the disk image
   directly into `rc.o':

     file2o < /tmp/linux-2048.initrd-20020624

   (I am appending the C source of `file2o' below.)
 
 - After that, compile the Linux kernel.

For whatever reason, I did not succeed to squeeze anything bigger
than 2 MB into the CIBD. If someone can solve this problem, it would
make booting Linux on the Jornada _much_ simpler!

Whenever the disk image (/tmp/linux-2048.initrd-20020624 in the
example above) changes, it is necessary to re-compile `rc.o' and
repeat the procedure above. If someone includes it into the
Makefile, it would be better.

Have fun,

    Peter

8< ---- file2o.c ---------------------------------------------------

/* file2o.c - copy standard output into a `.o' file
 * Copyright (C) 2002 by Peter Gerwinski <peter_at_gerwinski.de>
 * This program is free software under the GNU GPL, version 2 or higher.
 */

#include <stdio.h>

#define LMAX 8

int main (void)
{
  FILE *rd = fopen ("rd.o", "r+");
  char t0[LMAX], t1[LMAX] = { 3, 1, 4, 1, 5, 9, 2, 6 }, c;

  do
    {
      int l = 0;
      if (fread (&t0[0], 1, 1, rd) == 0)
        {
          fprintf (stderr, "pattern not found\n");
          return 1;
        }
      while (l < LMAX - 1 && t0[l] == t1[l])
        {
          l++;
          if (fread (&t0[l], 1, 1, rd) == 0)
            {
              fprintf (stderr, "pattern not found\n");
              return 1;
            }
        }
    }
  while (strncmp (t0, t1, LMAX) != 0);
  fseek (rd, -LMAX, SEEK_CUR);
  while (fread (&c, 1, 1, stdin) != 0)
    fwrite (&c, 1, 1, rd);
  fclose (rd);
  return 0;
}
Received on Mon Jun 24 2002 - 18:37:15 EDT

This archive was generated by hypermail 2.2.0 : Mon Jul 25 2005 - 17:26:16 EDT