From 408b4fda1f2a7fb61af648daf5577b89127612a5 Mon Sep 17 00:00:00 2001 From: David McCullough Date: Thu, 29 May 2003 03:17:56 +0000 Subject: [PATCH] Add ktrace option so that individual flat files will produce the useful kernel trace for debugging. Update to latest flat.h. --- elf2flt.c | 10 ++++++++-- flat.h | 22 ++++++++++++++++++---- flthdr.c | 18 +++++++++++++++--- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/elf2flt.c b/elf2flt.c index dce6506..beabe57 100644 --- a/elf2flt.c +++ b/elf2flt.c @@ -6,7 +6,7 @@ * ELF format file handling. Extended relocation support for all of * text and data. * - * (c) 2003, H8 support + * (c) 2003, H8 support, ktrace * (c) 2001-2003, arm/arm-pic/arm-big-endian support * (c) 2001, v850 changes, Mile Bader * (c) 2003, SuperH support, Paul Mundt @@ -95,6 +95,7 @@ int verbose = 0; /* extra output when running */ int pic_with_got = 0; /* do elf/got processing with PIC code */ int load_to_ram = 0; /* instruct loader to allocate everything into RAM */ +int ktrace = 0; /* instruct loader output kernel trace on load */ int compress = 0; /* 1 = compress everything, 2 = compress data only */ int use_resolved = 0; /* If true, get the value of symbol references from */ /* the program contents, not from the relocation table. */ @@ -1050,6 +1051,7 @@ static void usage(void) "[-o ] \n\n" " -v : verbose operation\n" " -r : force load to RAM\n" + " -k : enable kernel trace on load (for debug)\n" " -z : compress code/data/relocs\n" " -d : compress data/relocs\n" " -a : use existing symbol references\n" @@ -1124,7 +1126,7 @@ int main(int argc, char *argv[]) stack = 4096; - while ((opt = getopt(argc, argv, "avzdrp:s:o:R:")) != -1) { + while ((opt = getopt(argc, argv, "avzdrkp:s:o:R:")) != -1) { switch (opt) { case 'v': verbose++; @@ -1132,6 +1134,9 @@ int main(int argc, char *argv[]) case 'r': load_to_ram++; break; + case 'k': + ktrace++; + break; case 'z': compress = 1; break; @@ -1333,6 +1338,7 @@ int main(int argc, char *argv[]) hdr.reloc_count = htonl(reloc_len); hdr.flags = htonl(0 | (load_to_ram ? FLAT_FLAG_RAM : 0) + | (ktrace ? FLAT_FLAG_KTRACE : 0) | (pic_with_got ? FLAT_FLAG_GOTPIC : 0) | (compress ? (compress == 2 ? FLAT_FLAG_GZDATA : FLAT_FLAG_GZIP) : 0) ); diff --git a/flat.h b/flat.h index 28fa5bd..ec56852 100644 --- a/flat.h +++ b/flat.h @@ -1,14 +1,27 @@ - -/* Copyright (C) 1998 Kenneth Albanowski - * The Silver Hammer Group, Ltd. +/* + * Copyright (C) 2002-2003 David McCullough + * Copyright (C) 1998 Kenneth Albanowski + * The Silver Hammer Group, Ltd. * + * This file provides the definitions and structures needed to + * support uClinux flat-format executables. */ #ifndef _LINUX_FLAT_H #define _LINUX_FLAT_H +#ifdef __KERNEL__ +#include +#endif + #define FLAT_VERSION 0x00000004L +#ifdef CONFIG_BINFMT_SHARED_FLAT +#define MAX_SHARED_LIBS (4) +#else +#define MAX_SHARED_LIBS (1) +#endif + /* * To make everything easier to port and manage cross platform * development, all fields are in network byte order. @@ -41,6 +54,7 @@ struct flat_hdr { #define FLAT_FLAG_GOTPIC 0x0002 /* program is PIC with GOT */ #define FLAT_FLAG_GZIP 0x0004 /* all but the header is compressed */ #define FLAT_FLAG_GZDATA 0x0008 /* only data/relocs are compressed (for XIP) */ +#define FLAT_FLAG_KTRACE 0x0010 /* output useful kernel trace for debugging */ #ifdef __KERNEL__ /* so systems without linux headers can compile the apps */ @@ -81,6 +95,6 @@ typedef union { } reloc; } flat_v2_reloc_t; -#endif +#endif /* __KERNEL__ */ #endif /* _LINUX_FLAT_H */ diff --git a/flthdr.c b/flthdr.c index 12db066..12f7dcd 100644 --- a/flthdr.c +++ b/flthdr.c @@ -2,7 +2,7 @@ /* * A simple program to manipulate flat files * - * Copyright (C) 2001,2002 SnapGear Inc, davidm@snapgear.com + * Copyright (C) 2001-2003 SnapGear Inc, davidm@snapgear.com * Copyright (C) 2001 Lineo, davidm@lineo.com */ /****************************************************************************/ @@ -22,7 +22,7 @@ char *program_name; static char cmd[1024]; -static int print = 0, compress = 0, ramload = 0, stacksize = 0; +static int print = 0, compress = 0, ramload = 0, stacksize = 0, ktrace = 0; static int short_format = 0; /****************************************************************************/ @@ -99,6 +99,11 @@ process_file(char *ifile, char *ofile) else if (ramload < 0) new_flags &= ~FLAT_FLAG_RAM; + if (ktrace > 0) + new_flags |= FLAT_FLAG_KTRACE; + else if (ktrace < 0) + new_flags &= ~FLAT_FLAG_KTRACE; + if (stacksize) new_stack = stacksize; @@ -127,6 +132,8 @@ process_file(char *ifile, char *ofile) printf("Gzip-Compressed "); if (old_flags & FLAT_FLAG_GZDATA) printf("Gzip-Data-Compressed "); + if (old_flags & FLAT_FLAG_KTRACE) + printf("Kernel-Traced-Load "); printf(")\n"); } } else if (print > 1) { @@ -139,6 +146,7 @@ process_file(char *ifile, char *ofile) first = 0; } *tfile = '\0'; + strcat(tfile, (old_flags & FLAT_FLAG_KTRACE) ? "k" : ""); strcat(tfile, (old_flags & FLAT_FLAG_RAM) ? "r" : ""); strcat(tfile, (old_flags & FLAT_FLAG_GOTPIC) ? "p" : ""); strcat(tfile, (old_flags & FLAT_FLAG_GZIP) ? "z" : @@ -287,6 +295,8 @@ usage(char *s) fprintf(stderr, " -Z : un-compressed flat file\n"); fprintf(stderr, " -r : ram load\n"); fprintf(stderr, " -R : do not RAM load\n"); + fprintf(stderr, " -k : kernel traced load (for debug)\n"); + fprintf(stderr, " -K : normal non-kernel traced load\n"); fprintf(stderr, " -s size : stack size\n"); fprintf(stderr, " -o file : output-file\n" " (default is to modify input file)\n"); @@ -303,7 +313,7 @@ main(int argc, char *argv[]) program_name = argv[0]; - while ((c = getopt(argc, argv, "pdzZrRs:o:")) != EOF) { + while ((c = getopt(argc, argv, "pdzZrRkKs:o:")) != EOF) { switch (c) { case 'p': print = 1; break; case 'z': compress = 1; break; @@ -311,6 +321,8 @@ main(int argc, char *argv[]) case 'Z': compress = -1; break; case 'r': ramload = 1; break; case 'R': ramload = -1; break; + case 'k': ktrace = 1; break; + case 'K': ktrace = -1; break; case 's': stacksize = atoi(optarg); break; case 'o': ofile = optarg; break; default: -- 2.39.5