summaryrefslogtreecommitdiff
path: root/rbutil/mkamsboot/bin2c.c
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2009-05-28 18:27:08 +0000
committerRafaël Carré <rafael.carre@gmail.com>2009-05-28 18:27:08 +0000
commit96165abec2da60c466659fa0e68e06d97587d51a (patch)
tree5445bddea2ac0e706546ce972d61dacc8d0f81e2 /rbutil/mkamsboot/bin2c.c
parentbebc8587cfa7896684278d824ed5b28b2e9f9df1 (diff)
downloadrockbox-96165abec2da60c466659fa0e68e06d97587d51a.tar.gz
rockbox-96165abec2da60c466659fa0e68e06d97587d51a.zip
FS#10253 : mkamsboot v1.0mkamsboot_1.0
- Bump version to 1.0 - Add Clipv2 target - Make mkamsboot work as a library (work by domonoky : FS#10185, with a few modifications by me) . Use a macro with variadic arguments for error cases in functions which might error. . Add detailed descriptions to functions exported by the library (in the header file) - modify bin2c.c to produce only one pair of .c/.h files with several files embedded in it - move files needing to be built by an ARM cross compiler into dualboot/ - commit produced .c/.h files (containing nrv2e_d8.S and dualboot.S built for Clip, Fuze, e200v2, c200v2, m200v4, Clipv2) - Write a real README file - cosmetics: indent dualboot.S properly, remove trailing spaces, limit lines to 80 characters - comments: add/correct comments in dualboot.S and mkamsboot.c - move back extract_fw.c to utils/AMS/hacking git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21118 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/mkamsboot/bin2c.c')
-rw-r--r--rbutil/mkamsboot/bin2c.c134
1 files changed, 0 insertions, 134 deletions
diff --git a/rbutil/mkamsboot/bin2c.c b/rbutil/mkamsboot/bin2c.c
deleted file mode 100644
index dce8013c31..0000000000
--- a/rbutil/mkamsboot/bin2c.c
+++ /dev/null
@@ -1,134 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 Dave Chapman
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdio.h>
23#include <string.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <unistd.h>
27#include <fcntl.h>
28#include <stdlib.h>
29
30#ifndef O_BINARY
31#define O_BINARY 0
32#endif
33
34static off_t filesize(int fd)
35{
36 struct stat buf;
37
38 fstat(fd,&buf);
39 return buf.st_size;
40}
41
42static int write_cfile(const unsigned char* buf, off_t len, const char* cname)
43{
44 char filename[256];
45 FILE* fp;
46 int i;
47
48 snprintf(filename,256,"%s.c",cname);
49
50 fp = fopen(filename,"w+");
51 if (fp == NULL) {
52 fprintf(stderr,"Couldn't open %s\n",filename);
53 return -1;
54 }
55
56 fprintf(fp,"/* Generated by bin2c */\n\n");
57 fprintf(fp,"unsigned char %s[%d] = {",cname,len);
58
59 for (i=0;i<len;i++) {
60 if ((i % 16) == 0) {
61 fprintf(fp,"\n ");
62 }
63 if (i == (len-1)) {
64 fprintf(fp,"0x%02x",buf[i]);
65 } else {
66 fprintf(fp,"0x%02x, ",buf[i]);
67 }
68 }
69 fprintf(fp,"\n};\n");
70
71 fclose(fp);
72 return 0;
73}
74
75static int write_hfile(off_t len, const char* cname)
76{
77 char filename[256];
78 FILE* fp;
79
80 snprintf(filename,256,"%s.h",cname);
81 fp = fopen(filename,"w+");
82 if (fp == NULL) {
83 fprintf(stderr,"Couldn't open %s\n",filename);
84 return -1;
85 }
86
87 fprintf(fp,"/* Generated by bin2c */\n\n");
88 fprintf(fp,"extern unsigned char %s[%d];\n",cname,len);
89 fclose(fp);
90 return 0;
91}
92
93int main (int argc, char* argv[])
94{
95 char* infile;
96 char* cname;
97 int fd;
98 unsigned char* buf;
99 int len;
100 int n;
101
102 if (argc != 3) {
103 fprintf(stderr,"Usage: bin2c file cname\n");
104 return 0;
105 }
106
107 infile=argv[1];
108 cname=argv[2];
109
110 fd = open(infile,O_RDONLY|O_BINARY);
111 if (fd < 0) {
112 fprintf(stderr,"Can not open %s\n",infile);
113 return 0;
114 }
115
116 len = filesize(fd);
117
118 buf = malloc(len);
119 n = read(fd,buf,len);
120 if (n < len) {
121 fprintf(stderr,"Short read, aborting\n");
122 return 0;
123 }
124 close(fd);
125
126 if (write_cfile(buf,len,cname) < 0) {
127 return -1;
128 }
129 if (write_hfile(len,cname) < 0) {
130 return -1;
131 }
132
133 return 0;
134}