| 1 |
/* Xilinx firmware convertor program. |
| 2 |
* |
| 3 |
* Written by Jim Dixon <[email protected]>. |
| •4 |
* Binary output adde by Ben Hutchings <[email protected]>. |
| 5 |
* |
| 6 |
* Copyright (C) 2001 Jim Dixon / Zapata Telephony. |
| 7 |
* Copyright (C) 2001-2008 Digium, Inc. |
| 8 |
* |
| 9 |
* All rights reserved. |
| 10 |
* |
| 11 |
*/ |
| 12 |
|
| 13 |
/* |
| 14 |
* See http://www.asterisk.org for more information about |
| 15 |
* the Asterisk project. Please do not directly contact |
| 16 |
* any of the maintainers of this project for assistance; |
| 17 |
* the project provides a web site, mailing lists and IRC |
| 18 |
* channels for your use. |
| 19 |
* |
| 20 |
* This program is free software, distributed under the terms of |
| 21 |
* the GNU General Public License Version 2 as published by the |
| 22 |
* Free Software Foundation. See the LICENSE file included with |
| 23 |
* this program for more details. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#define SWATH 12 |
| 31 |
|
| 32 |
int main(int argc, char *argv[]) |
| 33 |
{ |
| 34 |
FILE *fp; |
| 35 |
int i,j,nbytes; |
| 36 |
unsigned char c; |
| 37 |
char buf[300]; |
| •38 |
int bin; |
| 39 |
|
| 40 |
if (argc < 3) |
| 41 |
{ |
| 42 |
puts("Usage... makefw filename.rbt array_name"); |
| •43 |
puts(" makefw filename.rbt -b"); |
| 44 |
exit(1); |
| 45 |
} |
| 46 |
|
| 47 |
fp = fopen(argv[1],"r"); |
| 48 |
if (!fp) |
| 49 |
{ |
| 50 |
perror("bit file open"); |
| 51 |
exit(1); |
| 52 |
} |
| •53 |
bin = !strcmp(argv[2], "-b"); |
| 54 |
nbytes = 0; |
| •55 |
if (!bin) |
| 56 |
printf("static unsigned char %s[] = {\n",argv[2]); |
| 57 |
i = 0; |
| 58 |
while(fgets(buf,sizeof(buf) - 1,fp)) |
| 59 |
{ |
| 60 |
if (!buf[0]) continue; |
| 61 |
if (buf[strlen(buf) - 1] < ' ') buf[strlen(buf) - 1] = 0; |
| 62 |
if (!buf[0]) continue; |
| 63 |
if (buf[strlen(buf) - 1] < ' ') buf[strlen(buf) - 1] = 0; |
| 64 |
if (!buf[0]) continue; |
| 65 |
if (strlen(buf) < 32) continue; |
| 66 |
if ((buf[0] != '0') && (buf[0] != '1')) continue; |
| 67 |
c = 0; |
| 68 |
for(j = 0; buf[j]; j++) |
| 69 |
{ |
| 70 |
if (buf[j] > '0') c |= 1 << (j & 7); |
| 71 |
if ((j & 7) == 7) |
| 72 |
{ |
| 73 |
nbytes++; |
| •74 |
if (bin) { |
| 75 |
putchar(c); |
| 76 |
} else { |
| 77 |
if (i) printf(","); |
| 78 |
printf("0x%02x",c); |
| 79 |
if (i++ == SWATH) { |
| 80 |
printf(",\n"); |
| 81 |
i = 0; |
| 82 |
} |
| 83 |
} |
| 84 |
c = 0; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| •88 |
if (!bin) |
| 89 |
printf("\n};\n\n"); |
| 90 |
fprintf(stderr,"Loaded %d bytes from file\n",nbytes); |
| 91 |
fclose(fp); |
| 92 |
exit(0); |
| 93 |
} |
| 94 |
|