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
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 */
53 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
59 { "*-frequency", 10, 0 },
61 { "#*-cells", 10, 0 },
62 { "*cache-line-size", 10, 0 },
63 { "*cache-block-size", 10, 0 },
64 { "*cache-size", 10, 0 },
65 { "*cache-sets", 10, 0 },
66 { "cell-index", 10, 0 },
67 { "bank-width", 10, 0 },
68 { "*-fifo-size", 10, 0 },
69 { "*-frame-size", 10, 0 },
70 { "*-channel", 10, 0 },
71 { "current-speed", 10, 0 },
80 <*>"/include/"{GAP}{STRING} ECHO;
82 <*>\"([^\\"]|\\.)*\" ECHO;
85 die("Input dts file is already version 1\n");
90 fprintf(yyout, "/dts-v1/;\n\n");
103 else if (*yytext == 'o')
105 else if (*yytext == 'd')
111 <INITIAL>[0-9a-fA-F]+ {
112 unsigned long long val;
113 int obase = 16, width = 0;
116 val = strtoull(yytext, NULL, cbase);
119 val = val - last_val + 1;
122 for (i = 0; i < ARRAY_SIZE(guess_table); i++)
123 if (fnmatch(guess_table[i].pattern,
124 last_name, 0) == 0) {
125 obase = guess_table[i].obase;
126 width = guess_table[i].width;
139 fprintf(yyout, "0x%0*llx", width, val);
142 fprintf(yyout, "0%0*llo", width, val);
145 fprintf(yyout, "%*llu", width, val);
156 "&{/"{PATHCHAR}+\} ECHO;
158 <INITIAL>"&/"{PATHCHAR}+ fprintf(yyout, "&{/%s}", yytext + 2);
160 <BYTESTRING>[0-9a-fA-F]{2} ECHO;
167 <PROPNODENAME>{PROPNODECHAR}+ {
169 last_name = xstrdup(yytext);
175 <*>- { /* Hack to convert old style memreserves */
182 fprintf(yyout, "/dts-v1/;\n\n");
187 if (yytext[0] == '[') {
190 if ((yytext[0] == '{')
191 || (yytext[0] == ';')) {
197 static void usage(void)
199 fprintf(stderr, "convert-dtsv0 <v0 dts file>...\n");
203 static void convert_file(const char *fname)
205 const char suffix[] = "v1";
206 int len = strlen(fname);
209 newname = xmalloc(len + sizeof(suffix));
210 memcpy(newname, fname, len);
211 memcpy(newname + len, suffix, sizeof(suffix));
213 srcpos_file = dtc_open_file(fname, NULL);
214 yyin = srcpos_file->file;
216 yyout = fopen(newname, "w");
218 die("Couldn't open output file %s: %s\n",
219 newname, strerror(errno));
225 int main(int argc, char *argv[])
232 for (i = 1; i < argc; i++) {
233 fprintf(stderr, "Converting %s from dts v0 to dts v1\n", argv[i]);
234 convert_file(argv[i]);