root/arch/ppc/boot/cortstrip.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 #include <stdio.h>
   2 #include <sys/types.h>
   3 #include <unistd.h>
   4 #include <fcntl.h>
   5 
   6 /* amount to skip */
   7 #define PLACE 65536
   8 
   9 /* size of read buffer */
  10 #define SIZE 0x200000
  11 
  12 /* crude program to strip the elf header to make a bootable
  13    image via tftp
  14  */
  15 
  16 
  17 int main(int argc, char **argv )
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19   int fd, fdo;
  20   unsigned char data[SIZE];
  21   int i, n, skip;
  22 
  23   if ( argc != 3 )
  24   {
  25     fprintf(stderr,"%s infile outfile\n", argv[0]);
  26     exit(-1);
  27   }
  28 
  29 
  30   fd = open(argv[1], O_RDONLY);
  31   if ( fd == -1 )
  32   {
  33     fprintf(stderr,"Couldn't open %s\n", argv[1]);
  34     perror("open()");
  35     exit(-1);
  36   }
  37   
  38   fdo = open(argv[2], O_WRONLY|O_CREAT);
  39   if ( fdo == -1 )
  40   {
  41     fprintf(stderr,"Couldn't open %s\n", argv[2]);
  42     perror("open()");
  43     exit(-1);
  44   }
  45 
  46 #if 0
  47   skip = atoi(argv[3]);
  48 #else
  49   skip = PLACE;
  50 #endif
  51   i = lseek(fd, skip, SEEK_SET);
  52   printf("lseek'd %d bytes\n", i);
  53   if ( i == -1 )
  54   {
  55       perror("lseek()");
  56   }
  57 
  58   while ( (n = read(fd, data, SIZE)) > 0 )
  59   {
  60     printf("Read %d bytes\n", n);
  61     i = write(fdo, data, n);
  62     printf("Wrote %d bytes\n", i);    
  63   }
  64 
  65 
  66   close(fdo);
  67   close(fd);
  68   return(0);
  69 }
  70 
  71 

/* [previous][next][first][last][top][bottom][index][help] */