source: rtems/c/src/lib/libbsp/i386/pc386/tools/binpatch.c @ 5d18fb0

4.104.114.84.95
Last change on this file since 5d18fb0 was 5d18fb0, checked in by Joel Sherrill <joel.sherrill@…>, on 06/27/98 at 18:51:49

PC386 BSP enhancements from Aleksey Romanov (Quality Quorum
<qqi@…>). Unfortunately after merging these,
the pc386 will not boot using grub for for. It still does not
work using netboot for me. Here is his summary of changes:

rtems/c/src/lib/libbsp/i386/pc386/Makefile.in

Added support for new sub-directory

rtems/c/src/lib/libbsp/i386/pc386/bsp_specs

Made possible to build COFF image

rtems/c/src/lib/libbsp/i386/pc386/console/console.c

Added support for serial consoles, selectable by patching
binary image, added assert(), use _IBMPC_inch_sleep()
instaed of _IMBPC_inch()

rtems/c/src/lib/libbsp/i386/pc386/console/inch.c

Added _IMBPC_inch_sleep()

rtems/c/src/lib/libbsp/i386/pc386/console/outch.c

Oops - just formatting

rtems/c/src/lib/libbsp/i386/pc386/include/Makefile.in

Added support for new files

rtems/c/src/lib/libbsp/i386/pc386/include/bsp.h

Added support for new features

rtems/c/src/lib/libbsp/i386/pc386/include/pc386uart.h

New file: definitions for serial ports

rtems/c/src/lib/libbsp/i386/pc386/include/pcibios.h

New file: definitions for PCI BIOS

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/Makefile.in

New file: makefile in new directory

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/i386-stub-glue.c

New file: i386-stub interface

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/i386-stub.c

New file: i386-stub itself

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/pc386uart.c

New file: serial ports

rtems/c/src/lib/libbsp/i386/pc386/pc386dev/pcibios.c

New file: PCI BIOS support

rtems/c/src/lib/libbsp/i386/pc386/start/start.s

Commented out DEBUG_EARLY stuff, everything is working fine

rtems/c/src/lib/libbsp/i386/pc386/start/start16.s

Cleaned up

rtems/c/src/lib/libbsp/i386/pc386/startup/bspstart.c

Added call to console_resereve_resources

rtems/c/src/lib/libbsp/i386/pc386/startup/exit.c

Added support for serial console

rtems/c/src/lib/libbsp/i386/pc386/startup/ldsegs.s

Fixed typo in comments

rtems/c/src/lib/libbsp/i386/pc386/tools/Makefile.in

Changed to reflect cnages in code

rtems/c/src/lib/libbsp/i386/pc386/tools/bin2boot.c

Trivialized, problem - I do not know how to make patch
remove obsolete files - there are a lot of them there

rtems/c/src/lib/libbsp/i386/pc386/tools/binpatch.c

New file: utility to do binary patches

rtems/c/src/lib/libbsp/i386/pc386/wrapup/Makefile.in

Added support for new directory

rtems/make/custom/pc386.cfg

Add COFF image building

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  $Id$
3 */
4
5
6#include <stdio.h>
7#include <stdlib.h>
8
9/*
10 * This function will patch binary file
11 */
12
13
14static char buf[512];
15
16static void
17usage(void)
18{
19  printf("usage: binpatch [-h] <ofile> <ifile> <reloc> <off> <byte0> "
20         "[<byte1> [<byte2> [<byte3>]]]\n");
21  printf("this function patches binary file at specified offset with\n");
22  printf("up to 4 bytes provided on command line \n");
23  printf("-h       - prints this message\n\n");
24  printf("<ofile>  - output file\n");
25  printf("<ifile>  - input ifile\n");
26  printf("<reloc>  - relocation address of image\n");
27  printf("<off>    - offset of patch, offset in file is at off - reloc\n");
28  printf("<byte0>  - byte 0 of patch\n");
29  printf("<byte1>  - byte 1 of patch\n");
30  printf("<byte2>  - byte 1 of patch\n");
31  printf("<byte3>  - byte 1 of patch\n");
32
33  return;
34}
35
36int
37main(int argc, char **argv)
38{
39  int   c;
40  FILE  *ofp, *ifp;
41  char  patch[4], *end;
42  int   patchLen, tmp, i, off, cnt, patched, len, reloc;
43 
44 
45  /* parse command line options */
46  while ((c = getopt(argc, argv, "h")) >= 0)
47    {
48      switch (c)
49        {
50        case 'h':
51          usage();
52          return 0;
53        default:
54          usage();
55          return 1;
56        }
57    }
58
59  if(argc < 6)
60    {
61      usage();
62      return 1;
63    }
64
65  /* Let us get offset in file */
66  reloc = strtol(argv[3], &end, 0);
67  if(end == argv[3] || off < 0)
68    {
69      fprintf(stderr, "bad reloc value %s\n", argv[3]);
70      return 1;
71    }
72
73  off = strtol(argv[4], &end, 0);
74  if(end == argv[4] || off < 0 || off < reloc)
75    {
76      fprintf(stderr, "bad offset value %s\n", argv[4]);
77      return 1;
78    }
79
80  off -= reloc;
81
82  /* Let us get patch  */
83  patchLen = argc - 5;
84
85  for(i=0; i<patchLen; i++)
86    {
87      tmp = strtol(argv[5+i], &end, 0);
88
89      if(end == argv[4+i] || tmp < 0 || tmp > 0xff)
90        {
91          fprintf(stderr, "bad byte value %s\n", argv[5+i]);
92          return 1;
93        }
94      patch[i] = tmp;
95    }
96     
97  ifp = fopen(argv[2], "r");
98  if(ifp == NULL)
99    {
100      fprintf(stderr, "unable to open file %s\n", argv[2]);
101      return 1;
102    }
103
104  ofp = fopen(argv[1], "w");
105  if(ofp == NULL)
106    {
107      fprintf(stderr, "unable to open file %s\n", argv[1]);
108      return 1;
109    }
110
111  cnt     = 0;
112  patched = 0;
113  for(;;)
114    {
115      len = fread(buf, 1, sizeof(buf), ifp);
116
117      if(len == 0)
118        {
119          break;
120        }
121
122      if(cnt <= off && (cnt + len) > off)
123        {
124          /* Perform patch */
125          for(i=0; i<patchLen && (off+i)<(cnt+len); i++)
126            {
127              buf[off-cnt+i] = patch[i];
128            }
129          patched = 1;
130        }
131      else if(cnt > off && cnt < (off + patchLen))
132        {
133          /* Perform patch */
134          for(i=cnt-off; i<patchLen; i++)
135            {
136              buf[off-cnt+i] = patch[i];
137            }
138          patched = 1;
139        }
140         
141      fwrite(buf, 1, len, ofp);
142
143      cnt += len;
144    }
145
146  fclose(ifp);
147  fclose(ofp);
148 
149  if(!patched)
150    {
151      fprintf(stderr, "warning: offset is beyond input file length\n");
152      fprintf(stderr, "         no patch is performed\n");
153    }
154
155  return 0;
156}
157
158     
159
160 
161
162
163
164
165 
166
167
168
Note: See TracBrowser for help on using the repository browser.