4 * Copyright (C) 2005 Mike Baker
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <netinet/in.h>
38 unsigned long poly
= ntohl(0x2083b8ed);
40 if ((crc32
= (unsigned long *) malloc(256 * sizeof(unsigned long))) == (void *)-1) {
44 for (n
= 0; n
< 256; n
++) {
45 crc
= (unsigned long) n
;
46 for (bit
= 0; bit
< 8; bit
++)
47 crc
= (crc
& 1) ? (poly
^ (crc
>> 1)) : (crc
>> 1);
52 unsigned int crc32buf(char *buf
, size_t len
)
54 unsigned int crc
= 0xFFFFFFFF;
55 for (; len
; len
--, buf
++)
56 crc
= crc32
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
61 unsigned int crc
; // crc32 of the remainder
62 unsigned int flags
; // unknown, 10577050
63 char *trx
; // standard trx
66 int main(int argc
, char **argv
)
71 struct motorola
*firmware
;
74 printf("%s <trx> <motorola.bin>\n",argv
[0]);
79 if (((fd
= open(argv
[1], O_RDONLY
)) < 0)
80 || ((len
= lseek(fd
, 0, SEEK_END
)) < 0)
81 || ((trx
= mmap(0, len
, PROT_READ
, MAP_SHARED
, fd
, 0)) == (void *) (-1))
83 perror("open/malloc");
87 // create a firmware image in memory
88 // and copy the trx to it
89 firmware
= malloc(len
+8);
90 memcpy(&firmware
->trx
,trx
,len
);
93 // setup the motorola headers
95 firmware
->flags
= ntohl(0x10577050);
96 firmware
->crc
= htonl(crc32buf((char *)&firmware
->flags
,len
+4));
99 if (((fd
= open(argv
[2], O_CREAT
|O_WRONLY
,0644)) < 0)
100 || (write(fd
,firmware
,len
+8) != len
+8)
101 || (close(fd
) < 0)) {
This page took 0.060055 seconds and 5 git commands to generate.