dtc.cc (b626f5a73a48f44a31a200291b141e1da408a2ff) | dtc.cc (bbe31b709a653884e18995a1c97cdafd7392999a) |
---|---|
1/*- 2 * Copyright (c) 2013 David Chisnall 3 * All rights reserved. 4 * 5 * This software was developed by SRI International and the University of 6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7 * ("CTSRD"), as part of the DARPA CRASH research programme. 8 * --- 28 unchanged lines hidden (view full) --- 37#include <stdio.h> 38#include <stdlib.h> 39#include <time.h> 40#include <unistd.h> 41 42 43#include "fdt.hh" 44#include "checking.hh" | 1/*- 2 * Copyright (c) 2013 David Chisnall 3 * All rights reserved. 4 * 5 * This software was developed by SRI International and the University of 6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7 * ("CTSRD"), as part of the DARPA CRASH research programme. 8 * --- 28 unchanged lines hidden (view full) --- 37#include <stdio.h> 38#include <stdlib.h> 39#include <time.h> 40#include <unistd.h> 41 42 43#include "fdt.hh" 44#include "checking.hh" |
45#include "util.hh" |
|
45 46using namespace dtc; | 46 47using namespace dtc; |
48using std::string; |
|
47 48/** 49 * The current major version of the tool. 50 */ 51int version_major = 0; 52/** 53 * The current minor version of the tool. 54 */ 55int version_minor = 4; 56/** 57 * The current patch level of the tool. 58 */ 59int version_patch = 0; 60 | 49 50/** 51 * The current major version of the tool. 52 */ 53int version_major = 0; 54/** 55 * The current minor version of the tool. 56 */ 57int version_minor = 4; 58/** 59 * The current patch level of the tool. 60 */ 61int version_patch = 0; 62 |
61static void usage(const char* argv0) | 63static void usage(const string &argv0) |
62{ 63 fprintf(stderr, "Usage:\n" 64 "\t%s\t[-fhsv] [-b boot_cpu_id] [-d dependency_file]" 65 "[-E [no-]checker_name]\n" 66 "\t\t[-H phandle_format] [-I input_format]" 67 "[-O output_format]\n" 68 "\t\t[-o output_file] [-R entries] [-S bytes] [-p bytes]" 69 "[-V blob_version]\n" | 64{ 65 fprintf(stderr, "Usage:\n" 66 "\t%s\t[-fhsv] [-b boot_cpu_id] [-d dependency_file]" 67 "[-E [no-]checker_name]\n" 68 "\t\t[-H phandle_format] [-I input_format]" 69 "[-O output_format]\n" 70 "\t\t[-o output_file] [-R entries] [-S bytes] [-p bytes]" 71 "[-V blob_version]\n" |
70 "\t\t-W [no-]checker_name] input_file\n", basename((char*)argv0)); | 72 "\t\t-W [no-]checker_name] input_file\n", basename(argv0).c_str()); |
71} 72 73/** 74 * Prints the current version of this program.. 75 */ 76static void version(const char* progname) 77{ 78 fprintf(stderr, "Version: %s %d.%d.%d\n", progname, version_major, --- 6 unchanged lines hidden (view full) --- 85main(int argc, char **argv) 86{ 87 int ch; 88 int outfile = fileno(stdout); 89 const char *outfile_name = "-"; 90 const char *in_file = "-"; 91 FILE *depfile = 0; 92 bool debug_mode = false; | 73} 74 75/** 76 * Prints the current version of this program.. 77 */ 78static void version(const char* progname) 79{ 80 fprintf(stderr, "Version: %s %d.%d.%d\n", progname, version_major, --- 6 unchanged lines hidden (view full) --- 87main(int argc, char **argv) 88{ 89 int ch; 90 int outfile = fileno(stdout); 91 const char *outfile_name = "-"; 92 const char *in_file = "-"; 93 FILE *depfile = 0; 94 bool debug_mode = false; |
93 void (device_tree::*write_fn)(int) = &device_tree::write_binary; 94 void (device_tree::*read_fn)(const char*, FILE*) = 95 &device_tree::parse_dts; | 95 auto write_fn = &device_tree::write_binary; 96 auto read_fn = &device_tree::parse_dts; |
96 uint32_t boot_cpu; 97 bool boot_cpu_specified = false; 98 bool keep_going = false; 99 bool sort = false; 100 clock_t c0 = clock(); 101 class device_tree tree; 102 fdt::checking::check_manager checks; 103 const char *options = "hqI:O:o:V:d:R:S:p:b:fi:svH:W:E:DP:"; --- 6 unchanged lines hidden (view full) --- 110 case 'h': 111 usage(argv[0]); 112 return EXIT_SUCCESS; 113 case 'v': 114 version(argv[0]); 115 return EXIT_SUCCESS; 116 case 'I': 117 { | 97 uint32_t boot_cpu; 98 bool boot_cpu_specified = false; 99 bool keep_going = false; 100 bool sort = false; 101 clock_t c0 = clock(); 102 class device_tree tree; 103 fdt::checking::check_manager checks; 104 const char *options = "hqI:O:o:V:d:R:S:p:b:fi:svH:W:E:DP:"; --- 6 unchanged lines hidden (view full) --- 111 case 'h': 112 usage(argv[0]); 113 return EXIT_SUCCESS; 114 case 'v': 115 version(argv[0]); 116 return EXIT_SUCCESS; 117 case 'I': 118 { |
118 string arg = string(optarg); 119 if (arg == string("dtb")) | 119 string arg(optarg); 120 if (arg == "dtb") |
120 { 121 read_fn = &device_tree::parse_dtb; 122 } | 121 { 122 read_fn = &device_tree::parse_dtb; 123 } |
123 else if (arg == string("dts")) | 124 else if (arg == "dts") |
124 { 125 read_fn = &device_tree::parse_dts; 126 } 127 else 128 { 129 fprintf(stderr, "Unknown input format: %s\n", optarg); 130 return EXIT_FAILURE; 131 } 132 break; 133 } 134 case 'O': 135 { | 125 { 126 read_fn = &device_tree::parse_dts; 127 } 128 else 129 { 130 fprintf(stderr, "Unknown input format: %s\n", optarg); 131 return EXIT_FAILURE; 132 } 133 break; 134 } 135 case 'O': 136 { |
136 string arg = string(optarg); 137 if (arg == string("dtb")) | 137 string arg(optarg); 138 if (arg == "dtb") |
138 { 139 write_fn = &device_tree::write_binary; 140 } | 139 { 140 write_fn = &device_tree::write_binary; 141 } |
141 else if (arg == string("asm")) | 142 else if (arg == "asm") |
142 { 143 write_fn = &device_tree::write_asm; 144 } | 143 { 144 write_fn = &device_tree::write_asm; 145 } |
145 else if (arg == string("dts")) | 146 else if (arg == "dts") |
146 { 147 write_fn = &device_tree::write_dts; 148 } 149 else 150 { 151 fprintf(stderr, "Unknown output format: %s\n", optarg); 152 return EXIT_FAILURE; 153 } --- 9 unchanged lines hidden (view full) --- 163 return EXIT_FAILURE; 164 } 165 break; 166 } 167 case 'D': 168 debug_mode = true; 169 break; 170 case 'V': | 147 { 148 write_fn = &device_tree::write_dts; 149 } 150 else 151 { 152 fprintf(stderr, "Unknown output format: %s\n", optarg); 153 return EXIT_FAILURE; 154 } --- 9 unchanged lines hidden (view full) --- 164 return EXIT_FAILURE; 165 } 166 break; 167 } 168 case 'D': 169 debug_mode = true; 170 break; 171 case 'V': |
171 if (string(optarg) != string("17")) | 172 if (string(optarg) != "17") |
172 { 173 fprintf(stderr, "Unknown output format version: %s\n", optarg); 174 return EXIT_FAILURE; 175 } 176 break; 177 case 'd': 178 { 179 if (depfile != 0) 180 { 181 fclose(depfile); 182 } | 173 { 174 fprintf(stderr, "Unknown output format version: %s\n", optarg); 175 return EXIT_FAILURE; 176 } 177 break; 178 case 'd': 179 { 180 if (depfile != 0) 181 { 182 fclose(depfile); 183 } |
183 if (string(optarg) == string("-")) | 184 if (string(optarg) == "-") |
184 { 185 depfile = stdout; 186 } 187 else 188 { 189 depfile = fdopen(open(optarg, O_CREAT | O_TRUNC | O_WRONLY, 0666), "w"); 190 if (depfile == 0) 191 { 192 perror("Unable to open dependency file"); 193 return EXIT_FAILURE; 194 } 195 } 196 break; 197 } 198 case 'H': 199 { | 185 { 186 depfile = stdout; 187 } 188 else 189 { 190 depfile = fdopen(open(optarg, O_CREAT | O_TRUNC | O_WRONLY, 0666), "w"); 191 if (depfile == 0) 192 { 193 perror("Unable to open dependency file"); 194 return EXIT_FAILURE; 195 } 196 } 197 break; 198 } 199 case 'H': 200 { |
200 string arg = string(optarg); 201 if (arg == string("both")) | 201 string arg(optarg); 202 if (arg == "both") |
202 { 203 tree.set_phandle_format(device_tree::BOTH); 204 } | 203 { 204 tree.set_phandle_format(device_tree::BOTH); 205 } |
205 else if (arg == string("epapr")) | 206 else if (arg == "epapr") |
206 { 207 tree.set_phandle_format(device_tree::EPAPR); 208 } | 207 { 208 tree.set_phandle_format(device_tree::EPAPR); 209 } |
209 else if (arg == string("linux")) | 210 else if (arg == "linux") |
210 { 211 tree.set_phandle_format(device_tree::LINUX); 212 } 213 else 214 { 215 fprintf(stderr, "Unknown phandle format: %s\n", optarg); 216 return EXIT_FAILURE; 217 } --- 6 unchanged lines hidden (view full) --- 224 boot_cpu_specified = true; 225 break; 226 case 'f': 227 keep_going = true; 228 break; 229 case 'W': 230 case 'E': 231 { | 211 { 212 tree.set_phandle_format(device_tree::LINUX); 213 } 214 else 215 { 216 fprintf(stderr, "Unknown phandle format: %s\n", optarg); 217 return EXIT_FAILURE; 218 } --- 6 unchanged lines hidden (view full) --- 225 boot_cpu_specified = true; 226 break; 227 case 'f': 228 keep_going = true; 229 break; 230 case 'W': 231 case 'E': 232 { |
232 string arg = string(optarg); | 233 string arg(optarg); |
233 if ((arg.size() > 3) && (strncmp(optarg, "no-", 3) == 0)) 234 { 235 arg = string(optarg+3); 236 if (!checks.disable_checker(arg)) 237 { 238 fprintf(stderr, "Checker %s either does not exist or is already disabled\n", optarg+3); 239 } 240 break; --- 61 unchanged lines hidden (view full) --- 302 } 303 if (depfile != 0) 304 { 305 putc('\n', depfile); 306 fclose(depfile); 307 } 308 if (!(tree.is_valid() || keep_going)) 309 { | 234 if ((arg.size() > 3) && (strncmp(optarg, "no-", 3) == 0)) 235 { 236 arg = string(optarg+3); 237 if (!checks.disable_checker(arg)) 238 { 239 fprintf(stderr, "Checker %s either does not exist or is already disabled\n", optarg+3); 240 } 241 break; --- 61 unchanged lines hidden (view full) --- 303 } 304 if (depfile != 0) 305 { 306 putc('\n', depfile); 307 fclose(depfile); 308 } 309 if (!(tree.is_valid() || keep_going)) 310 { |
310 fprintf(stderr, "Failed to parse tree. Unhappy face!\n"); | 311 fprintf(stderr, "Failed to parse tree.\n"); |
311 return EXIT_FAILURE; 312 } 313 clock_t c2 = clock(); 314 if (!(checks.run_checks(&tree, true) || keep_going)) 315 { 316 return EXIT_FAILURE; 317 } 318 clock_t c3 = clock(); --- 26 unchanged lines hidden --- | 312 return EXIT_FAILURE; 313 } 314 clock_t c2 = clock(); 315 if (!(checks.run_checks(&tree, true) || keep_going)) 316 { 317 return EXIT_FAILURE; 318 } 319 clock_t c3 = clock(); --- 26 unchanged lines hidden --- |