summaryrefslogtreecommitdiffstats
path: root/tools/build
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-06-27 18:51:49 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-06-27 18:51:49 +0000
commit5d18fb057a9158336a79953b88d481c74c6eb0ae (patch)
tree5762f11ed095f1236aa83bf386637423afb7638c /tools/build
parent98100d275f62a034917d0b1f3157053e6c130005 (diff)
downloadrtems-5d18fb057a9158336a79953b88d481c74c6eb0ae.tar.bz2
PC386 BSP enhancements from Aleksey Romanov (Quality Quorum
<qqi@world.std.com>). 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
Diffstat (limited to 'tools/build')
-rw-r--r--tools/build/binpatch.c168
1 files changed, 168 insertions, 0 deletions
diff --git a/tools/build/binpatch.c b/tools/build/binpatch.c
new file mode 100644
index 0000000000..ab0900702a
--- /dev/null
+++ b/tools/build/binpatch.c
@@ -0,0 +1,168 @@
+/*
+ * $Id$
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+ * This function will patch binary file
+ */
+
+
+static char buf[512];
+
+static void
+usage(void)
+{
+ printf("usage: binpatch [-h] <ofile> <ifile> <reloc> <off> <byte0> "
+ "[<byte1> [<byte2> [<byte3>]]]\n");
+ printf("this function patches binary file at specified offset with\n");
+ printf("up to 4 bytes provided on command line \n");
+ printf("-h - prints this message\n\n");
+ printf("<ofile> - output file\n");
+ printf("<ifile> - input ifile\n");
+ printf("<reloc> - relocation address of image\n");
+ printf("<off> - offset of patch, offset in file is at off - reloc\n");
+ printf("<byte0> - byte 0 of patch\n");
+ printf("<byte1> - byte 1 of patch\n");
+ printf("<byte2> - byte 1 of patch\n");
+ printf("<byte3> - byte 1 of patch\n");
+
+ return;
+}
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ FILE *ofp, *ifp;
+ char patch[4], *end;
+ int patchLen, tmp, i, off, cnt, patched, len, reloc;
+
+
+ /* parse command line options */
+ while ((c = getopt(argc, argv, "h")) >= 0)
+ {
+ switch (c)
+ {
+ case 'h':
+ usage();
+ return 0;
+ default:
+ usage();
+ return 1;
+ }
+ }
+
+ if(argc < 6)
+ {
+ usage();
+ return 1;
+ }
+
+ /* Let us get offset in file */
+ reloc = strtol(argv[3], &end, 0);
+ if(end == argv[3] || off < 0)
+ {
+ fprintf(stderr, "bad reloc value %s\n", argv[3]);
+ return 1;
+ }
+
+ off = strtol(argv[4], &end, 0);
+ if(end == argv[4] || off < 0 || off < reloc)
+ {
+ fprintf(stderr, "bad offset value %s\n", argv[4]);
+ return 1;
+ }
+
+ off -= reloc;
+
+ /* Let us get patch */
+ patchLen = argc - 5;
+
+ for(i=0; i<patchLen; i++)
+ {
+ tmp = strtol(argv[5+i], &end, 0);
+
+ if(end == argv[4+i] || tmp < 0 || tmp > 0xff)
+ {
+ fprintf(stderr, "bad byte value %s\n", argv[5+i]);
+ return 1;
+ }
+ patch[i] = tmp;
+ }
+
+ ifp = fopen(argv[2], "r");
+ if(ifp == NULL)
+ {
+ fprintf(stderr, "unable to open file %s\n", argv[2]);
+ return 1;
+ }
+
+ ofp = fopen(argv[1], "w");
+ if(ofp == NULL)
+ {
+ fprintf(stderr, "unable to open file %s\n", argv[1]);
+ return 1;
+ }
+
+ cnt = 0;
+ patched = 0;
+ for(;;)
+ {
+ len = fread(buf, 1, sizeof(buf), ifp);
+
+ if(len == 0)
+ {
+ break;
+ }
+
+ if(cnt <= off && (cnt + len) > off)
+ {
+ /* Perform patch */
+ for(i=0; i<patchLen && (off+i)<(cnt+len); i++)
+ {
+ buf[off-cnt+i] = patch[i];
+ }
+ patched = 1;
+ }
+ else if(cnt > off && cnt < (off + patchLen))
+ {
+ /* Perform patch */
+ for(i=cnt-off; i<patchLen; i++)
+ {
+ buf[off-cnt+i] = patch[i];
+ }
+ patched = 1;
+ }
+
+ fwrite(buf, 1, len, ofp);
+
+ cnt += len;
+ }
+
+ fclose(ifp);
+ fclose(ofp);
+
+ if(!patched)
+ {
+ fprintf(stderr, "warning: offset is beyond input file length\n");
+ fprintf(stderr, " no patch is performed\n");
+ }
+
+ return 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+