File: makefw.c

package info (click to toggle)
dahdi-firmware 2.11.1.0.20170917-3.1
  • links: PTS, VCS
  • area: non-free-firmware
  • in suites: forky, sid
  • size: 9,228 kB
  • sloc: ansic: 120,145; perl: 2,395; sh: 973; makefile: 367; xml: 21
file content (94 lines) | stat: -rw-r--r-- 2,056 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* Xilinx firmware convertor program.
 *
 * Written by Jim Dixon <jim@lambdatel.com>.
 * Binary output adde by Ben Hutchings <ben@decadent.org.uk>.
 *
 * Copyright (C) 2001 Jim Dixon / Zapata Telephony.
 * Copyright (C) 2001-2008 Digium, Inc.
 *
 * All rights reserved.
 *
 */

/*
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2 as published by the
 * Free Software Foundation. See the LICENSE file included with
 * this program for more details.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define	SWATH 12

int main(int argc, char *argv[])
{
FILE *fp;
int i,j,nbytes;
unsigned char c;
char	buf[300];
int bin;

	if (argc < 3)
	   {
		puts("Usage... makefw  filename.rbt  array_name");
		puts("         makefw  filename.rbt  -b");
		exit(1);
	   }	

	fp = fopen(argv[1],"r");
	if (!fp)
	   {
		perror("bit file open");
		exit(1);
	   }
	bin = !strcmp(argv[2], "-b");
	nbytes = 0;
	if (!bin)
		printf("static unsigned char %s[] = {\n",argv[2]);
	i = 0;
	while(fgets(buf,sizeof(buf) - 1,fp))
	   {
		if (!buf[0]) continue;
		if (buf[strlen(buf) - 1] < ' ') buf[strlen(buf) - 1] = 0;
		if (!buf[0]) continue;
		if (buf[strlen(buf) - 1] < ' ') buf[strlen(buf) - 1] = 0;
		if (!buf[0]) continue;
		if (strlen(buf) < 32) continue;
		if ((buf[0] != '0') && (buf[0] != '1')) continue;
		c = 0;
		for(j = 0; buf[j]; j++)
		   {
			if (buf[j] > '0') c |= 1 << (j & 7);
			if ((j & 7) == 7)
			   {
				nbytes++;
				if (bin) {
					putchar(c);
				} else {
					if (i) printf(",");
					printf("0x%02x",c);
					if (i++ == SWATH) {
						printf(",\n");
						i = 0;
					}
				}
				c = 0;
			   }
		   }
	   }
	if (!bin)
		printf("\n};\n\n");
	fprintf(stderr,"Loaded %d bytes from file\n",nbytes);
	fclose(fp);
	exit(0);
}