123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
-
-
-
- #define MAXSIZE (512*1024)
-
- typedef unsigned short ushort_t;
- typedef unsigned long ulong_t;
-
-
-
- struct initial_t
- {
- ulong_t magic;
- ulong_t length;
- ulong_t location;
- ulong_t start;
- };
-
-
-
- struct header_t
- {
- ulong_t flags;
- ulong_t loadaddr;
- ulong_t imgsize;
- ulong_t memsize;
- };
-
-
-
- struct qnx_loader_t
- {
- struct initial_t setup;
- struct header_t qnx;
- };
-
-
-
- union
- {
- struct qnx_loader_t h;
- char filler[512];
- } header;
-
-
- char buffer[MAXSIZE];
-
-
- int usage( char* const* argv )
- {
- fprintf( stderr, "%s - make a tagged boot image for EtherBoot\n", *argv );
- fprintf( stderr, "\nuse:\n" );
- fprintf( stderr, "%s [ -<option> ]*\n", *argv );
- fprintf( stderr, "\noptions:\n" );
- fprintf( stderr, " i <input file> : QNX boot file (default: stdin)\n" );
- fprintf( stderr, " o <output file> : tagged image file (default: stdout)\n" );
- fprintf( stderr, " v : be verbose\n" );
- return EXIT_FAILURE;
- }
-
- #ifdef __USAGE
- %C - make a tagged boot image for EtherBoot
-
- use:
- %C [ -<option> ]*
-
- options:
- i <input file> : QNX boot file (default: stdin)
- o <output file> : tagged image file (default: stdout)
- v : be verbose
- #endif
-
-
- int main( int argc, char* const* argv )
- {
- int ch, l;
- int verbose = 0;
-
- while ( ( ch = getopt( argc, argv, "hi:o:v" ) ) != EOF )
- switch ( ch )
- {
- case 'i':
- if ( !freopen( optarg, "r", stdin ) )
- {
- perror( "can't open input file" );
- return EXIT_FAILURE;
- }
- break;
-
- case 'o':
- if ( !freopen( optarg, "w", stdout ) )
- {
- perror( "can't create output file" );
- return EXIT_FAILURE;
- }
- break;
-
- case 'v':
- verbose++;
- break;
-
- case 'h':
- default:
- return usage( argv );
- }
- if ( optind != argc )
- return usage( argv );
-
- memset( &header, 0, sizeof header );
- header.h.setup.magic = 0x1b031336;
- header.h.setup.length = 4;
- header.h.setup.location = 0x93e00000;
- header.h.setup.start = 0;
- header.h.qnx.flags = 0x04000004;
- header.h.qnx.loadaddr = 0;
- header.h.qnx.imgsize = 0;
- header.h.qnx.memsize = 0;
-
-
- for ( ; ( l = fread( buffer + header.h.qnx.imgsize, 1, 1024, stdin ) ) > 0;
- header.h.qnx.imgsize += l
- )
- ;
- header.h.qnx.memsize = header.h.qnx.imgsize;
-
-
- header.h.setup.start = *(ushort_t*)&buffer[10] << 16;
- header.h.qnx.loadaddr = *(ushort_t*)&buffer[10] << 4;
-
-
- fwrite( &header, 1, 512, stdout );
- fwrite( buffer, 1, header.h.qnx.imgsize, stdout );
-
- if ( verbose )
- {
-
- fprintf( stderr, "QNX image size: %d bytes (%dK), load addr: 0x%05X\n",
- header.h.qnx.imgsize,
- header.h.qnx.imgsize / 1024,
- header.h.qnx.loadaddr
- );
- }
- return EXIT_SUCCESS;
- }
|