putelf.c File Reference

#include <stdio.h>
#include "elf.h"

Include dependency graph for putelf.c:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int cmd_putelf (int argc, char **argv)
 mycmd_init (sputelf, cmd_putelf,"sputelf filename","put kernel")
 mycmd_init (fputelf, cmd_putelf,"fputelf filename","put kernel")
 mycmd_init (putelf, cmd_putelf,"putelf filename","put kernel")

Variables

static struct ehdr exec
static struct phdr prgm
static struct shdr sect
static struct sym symb


Function Documentation

int cmd_putelf ( int  argc,
char **  argv 
)

Definition at line 31 of file putelf.c.

References do_cmd(), ehdr.entry, exec, phdr.filesz, in, phdr.offset, ehdr.phcount, ehdr.phoff, ehdr.phsize, prgm, PT_LOAD, tgt_exec, phdr.type, ui_datamem, and phdr.vaddr.

00032 {
00033         FILE    *in, *out;
00034         int     i;
00035         long    len;
00036         char    tmpfile[100];
00037 
00038         if(argv[0][0] == 'p') argv[0][3] = 0;
00039         else argv[0][4] = 0;
00040 
00041         if( (in = fopen(argv[1], "rb")) == NULL ) {
00042                 perror(argv[1]);
00043                 return -1;
00044         }
00045 
00046         strcpy(tmpfile,"/tmp/ejtagbin_XXXXXX");
00047     if(mktemp(tmpfile) == NULL)
00048         {
00049                 perror(tmpfile);
00050                 return -1;
00051         }
00052 
00053 
00054         if( fread(&exec, sizeof(exec), 1, in) == 0 ) {
00055                 fprintf(stderr, "fread fails\n");
00056                 return -3;
00057         }
00058 
00059         /*---------------------------------------------------------------------------
00060          * For the BOOTROM, the code is compiled to 0xbfc00000 while the data is usually
00061          * compiled to address 0xa0000200 which is uncached DRAM or 0x00000200 which is
00062          * the cached DRAM.  This causes a problem as the elf headers appear to be ordering
00063          * in accending order (hence the data will appear before the code).  Thus we process
00064          * the headers in reverse order.
00065          *---------------------------------------------------------------------------*/
00066         for ( i =0 ; i < exec.phcount; i++ ) {
00067                 char *buf;
00068 
00069                 fseek(in,exec.phoff + i* exec.phsize,SEEK_SET);
00070         
00071                 if( fread(&prgm, sizeof(prgm), 1, in) == 0 ) {
00072                         fprintf(stderr, "fread fails\n");
00073                         return -3;
00074                 }
00075 
00076                 if(prgm.type != PT_LOAD)
00077                  continue;
00078 
00079                 if( (out = fopen(&tmpfile, "wb")) == NULL ) {
00080                         perror(&tmpfile);
00081                         fclose(in);
00082                         return -2;
00083                 }
00084 
00085                 len = prgm.filesz;
00086                 fseek(in, prgm.offset , SEEK_SET);
00087                 buf = malloc(len);
00088                 fread(buf,len,1,in);
00089                 fwrite(buf,len,1,out);
00090                 fclose(out);
00091                 sprintf(buf,"%s %s 0x%x",argv[0],tmpfile,prgm.vaddr|0xa0000000);
00092                 printf("%s\n",buf);
00093                 do_cmd(buf);
00094                 unlink(&tmpfile);
00095                 free(buf);
00096         }
00097 
00098         fclose(in);
00099 
00100         ui_datamem[0] = exec.entry;
00101 
00102                 tgt_exec(\
00103                   "1:mtc0    $2, $31;\n" \
00104                   "lui    $2,0xFF20;\n" \
00105                   "lw    $2, ($2);\n" \
00106                   "mtc0    $2, $24;\n" \
00107                   "mfc0    $2, $31;\n" \
00108                   "b 1b;\n" \
00109                   "nop;\n" \
00110                   ,0x8000);
00111 
00112         return 0;
00113 }

Here is the call graph for this function:

mycmd_init ( sputelf  ,
cmd_putelf  ,
"sputelf filename"  ,
"put kernel"   
)

mycmd_init ( fputelf  ,
cmd_putelf  ,
"fputelf filename"  ,
"put kernel"   
)

mycmd_init ( putelf  ,
cmd_putelf  ,
"putelf filename"  ,
"put kernel"   
)


Variable Documentation

struct ehdr exec [static]

Definition at line 4 of file putelf.c.

Referenced by cmd_putelf().

struct phdr prgm [static]

Definition at line 5 of file putelf.c.

Referenced by cmd_putelf().

struct shdr sect [static]

Definition at line 6 of file putelf.c.

struct sym symb [static]

Definition at line 7 of file putelf.c.


Generated on Fri Nov 5 07:24:50 2010 for ejtag debug tools for loongson 232 cpu by  doxygen 1.5.6