@@ -99,13 +99,10 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz,
99
99
return s.str ();
100
100
}
101
101
102
- std::string dtc_compile (const std::string& dtc_input, const std::string& input_type, const std::string& output_type )
102
+ static std::string dtc_compile (const std::string& dtc_input, bool compile )
103
103
{
104
- if (input_type == output_type)
105
- std::cerr << " Must have differing {in,out}put types for running " DTC << std::endl;
106
-
107
- if (!((input_type == " dts" && output_type == " dtb" ) || (input_type == " dtb" && output_type == " dts" )))
108
- std::cerr << " Invalid {in,out}put types for running " DTC " : Must convert from 'dts' to 'dtb' (or vice versa)" << std::endl;
104
+ const char * input_type = compile ? " dts" : " dtb" ;
105
+ const char * output_type = compile ? " dtb" : " dts" ;
109
106
110
107
int dtc_input_pipe[2 ];
111
108
pid_t dtc_input_pid;
@@ -147,7 +144,7 @@ std::string dtc_compile(const std::string& dtc_input, const std::string& input_t
147
144
close (dtc_input_pipe[1 ]);
148
145
close (dtc_output_pipe[0 ]);
149
146
close (dtc_output_pipe[1 ]);
150
- execlp (DTC, DTC, " -O" , output_type. c_str () , " -I" , input_type. c_str (), ( char *) 0 );
147
+ execlp (DTC, DTC, " -O" , output_type, " -I" , input_type, nullptr );
151
148
std::cerr << " Failed to run " DTC " : " << strerror (errno) << std::endl;
152
149
exit (1 );
153
150
}
@@ -186,6 +183,16 @@ std::string dtc_compile(const std::string& dtc_input, const std::string& input_t
186
183
return dtc_output.str ();
187
184
}
188
185
186
+ std::string dtb_to_dts (const std::string& dtc_input)
187
+ {
188
+ return dtc_compile (dtc_input, false );
189
+ }
190
+
191
+ std::string dts_to_dtb (const std::string& dtc_input)
192
+ {
193
+ return dtc_compile (dtc_input, true );
194
+ }
195
+
189
196
int fdt_get_node_addr_size (const void *fdt, int node, reg_t *addr,
190
197
unsigned long *size, const char *field)
191
198
{
0 commit comments