1 /* firmware/extract.c - tool for extracting firmwares out of linux
4 * --------------------------------------------------------------------
6 * Copyright (C) 2003 ACX100 Open Source Project
8 * The contents of this file are subject to the Mozilla Public
9 * License Version 1.1 (the "License"); you may not use this file
10 * except in compliance with the License. You may obtain a copy of
11 * the License at http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS
14 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
15 * implied. See the License for the specific language governing
16 * rights and limitations under the License.
18 * Alternatively, the contents of this file may be used under the
19 * terms of the GNU Public License version 2 (the "GPL"), in which
20 * case the provisions of the GPL are applicable instead of the
21 * above. If you wish to allow the use of your version of this file
22 * only under the terms of the GPL and not to allow others to use
23 * your version of this file under the MPL, indicate your decision
24 * by deleting the provisions above and replace them with the notice
25 * and other provisions required by the GPL. If you do not delete
26 * the provisions above, a recipient may use your version of this
27 * file under either the MPL or the GPL.
29 * --------------------------------------------------------------------
31 * Inquiries regarding the ACX100 Open Source Project can be
34 * acx100-users@lists.sf.net
35 * http://acx100.sf.net
37 * --------------------------------------------------------------------
41 * - get the firmware size from the debug symbols in the binary
42 * - check for version string, not only 4 first bytes
49 #include <sys/types.h>
53 #define FRMWR_SIZE 29612
56 int main(int argc
, char *argv
[])
60 int size
, pos
, file_size
;
61 unsigned char *mem
, *begin
;
63 /* this is the signature for firmware version 1.5.0 which is present in all the linux binary drivers. */
64 unsigned char signature
[] = {0x58, 0xb2, 0x24, 0x00};
66 /* check the arguments */
69 fprintf(stderr
, "Wrong call arguments.\n");
70 fprintf(stderr
, "USAGE: extract binary_driver.o\n");
71 fprintf(stderr
, " The firmware will be extracted, and will be written to stdout.\n");
75 /* try to open the file */
76 driver
= fopen(argv
[1], "r");
79 fprintf(stderr
, "ERROR: couldn't open or find given binary file %s to extract firmware image from it, aborting!\n", argv
[1]);
84 fseek(driver
, 0, SEEK_END
);
85 file_size
= ftell(driver
);
86 fseek(driver
, 0, SEEK_SET
);
88 /* alloc buffer to hold complete file */
89 mem
= malloc(file_size
);
92 fprintf(stderr
, "Could not allocate enough memory\n");
96 /* read the complete file */
97 size
= fread(mem
, 1, file_size
, driver
);
98 if ( size
!= file_size
)
100 fprintf(stderr
, "Was unable to read complete file (%i, %i)\n", size
, file_size
);
105 /* find the firmware */
106 begin
= memmem(mem
, file_size
, signature
, 4);
109 fprintf(stderr
, "Firmware was not found\n");
113 /* start processing the firmware */
119 } while(pos
!= FRMWR_SIZE
);