OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [arch/] [ppc/] [boot/] [cortstrip.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#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 )
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|O_TRUNC,0755);
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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.