2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005, 2008.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 %option noyywrap nounput noinput never-interactive
26 PROPNODECHAR [a-zA-Z0-9,._+*#?@-]
27 PATHCHAR ({PROPNODECHAR}|[/])
28 LABEL [a-zA-Z_][a-zA-Z0-9_]*
29 STRING \"([^\\"]|\\.)*\"
31 COMMENT "/*"([^*]|\*+[^*/])*\*+"/"
33 GAP ({WS}|{COMMENT}|{LINECOMMENT})*
47 static int v1_tagged; /* = 0 */
48 static int cbase = 16;
49 static int saw_hyphen; /* = 0 */
50 static unsigned long long last_val;
51 static char *last_name; /* = NULL */
57 { "*-frequency", 10, 0 },
59 { "#*-cells", 10, 0 },
60 { "*cache-line-size", 10, 0 },
61 { "*cache-block-size", 10, 0 },
62 { "*cache-size", 10, 0 },
63 { "*cache-sets", 10, 0 },
64 { "cell-index", 10, 0 },
65 { "bank-width", 10, 0 },
66 { "*-fifo-size", 10, 0 },
67 { "*-frame-size", 10, 0 },
68 { "*-channel", 10, 0 },
69 { "current-speed", 10, 0 },
78 <*>"/include/"{GAP}{STRING} ECHO;
80 <*>\"([^\\"]|\\.)*\" ECHO;
83 die("Input dts file is already version 1\n");
88 fprintf(yyout, "/dts-v1/;\n\n");
101 else if (*yytext == 'o')
103 else if (*yytext == 'd')
109 <INITIAL>[0-9a-fA-F]+ {
110 unsigned long long val;
111 int obase = 16, width = 0;
114 val = strtoull(yytext, NULL, cbase);
117 val = val - last_val + 1;
120 for (i = 0; i < ARRAY_SIZE(guess_table); i++)
121 if (fnmatch(guess_table[i].pattern,
122 last_name, 0) == 0) {
123 obase = guess_table[i].obase;
124 width = guess_table[i].width;
137 fprintf(yyout, "0x%0*llx", width, val);
140 fprintf(yyout, "0%0*llo", width, val);
143 fprintf(yyout, "%*llu", width, val);
154 "&{/"{PATHCHAR}+\} ECHO;
156 <INITIAL>"&/"{PATHCHAR}+ fprintf(yyout, "&{/%s}", yytext + 2);
158 <BYTESTRING>[0-9a-fA-F]{2} ECHO;
165 <PROPNODENAME>{PROPNODECHAR}+ {
167 last_name = xstrdup(yytext);
173 <*>- { /* Hack to convert old style memreserves */
180 fprintf(yyout, "/dts-v1/;\n\n");
185 if (yytext[0] == '[') {
188 if ((yytext[0] == '{')
189 || (yytext[0] == ';')) {
195 /* Usage related data. */
196 static const char usage_synopsis[] = "convert-dtsv0 [options] <v0 dts file>...";
197 static const char usage_short_opts[] = "" USAGE_COMMON_SHORT_OPTS;
198 static struct option const usage_long_opts[] = {
199 USAGE_COMMON_LONG_OPTS
201 static const char * const usage_opts_help[] = {
202 USAGE_COMMON_OPTS_HELP
205 static void convert_file(const char *fname)
207 const char suffix[] = "v1";
208 int len = strlen(fname);
211 newname = xmalloc(len + sizeof(suffix));
212 memcpy(newname, fname, len);
213 memcpy(newname + len, suffix, sizeof(suffix));
215 yyin = fopen(fname, "r");
217 die("Couldn't open input file %s: %s\n",
218 fname, strerror(errno));
220 yyout = fopen(newname, "w");
222 die("Couldn't open output file %s: %s\n",
223 newname, strerror(errno));
229 int main(int argc, char *argv[])
234 while ((opt = util_getopt_long()) != EOF) {
236 case_USAGE_COMMON_FLAGS
240 usage("missing filename");
242 for (i = 1; i < argc; i++) {
243 fprintf(stderr, "Converting %s from dts v0 to dts v1\n", argv[i]);
244 convert_file(argv[i]);