@@ -99,86 +99,91 @@ 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 dts_compile (const std::string& dts )
102
+ std::string dtc_compile (const std::string& dtc_input, const std::string& input_type, const std::string& output_type )
103
103
{
104
- // Convert the DTS to DTB
105
- int dts_pipe[2 ];
106
- pid_t dts_pid;
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;
109
+
110
+ int dtc_input_pipe[2 ];
111
+ pid_t dtc_input_pid;
107
112
108
113
fflush (NULL ); // flush stdout/stderr before forking
109
- if (pipe (dts_pipe ) != 0 || (dts_pid = fork ()) < 0 ) {
110
- std::cerr << " Failed to fork dts child: " << strerror (errno) << std::endl;
114
+ if (pipe (dtc_input_pipe ) != 0 || (dtc_input_pid = fork ()) < 0 ) {
115
+ std::cerr << " Failed to fork dtc_input child: " << strerror (errno) << std::endl;
111
116
exit (1 );
112
117
}
113
118
114
- // Child process to output dts
115
- if (dts_pid == 0 ) {
116
- close (dts_pipe [0 ]);
117
- int step, len = dts .length ();
118
- const char *buf = dts .c_str ();
119
+ // Child process to output dtc_input
120
+ if (dtc_input_pid == 0 ) {
121
+ close (dtc_input_pipe [0 ]);
122
+ int step, len = dtc_input .length ();
123
+ const char *buf = dtc_input .c_str ();
119
124
for (int done = 0 ; done < len; done += step) {
120
- step = write (dts_pipe [1 ], buf+done, len-done);
125
+ step = write (dtc_input_pipe [1 ], buf+done, len-done);
121
126
if (step == -1 ) {
122
- std::cerr << " Failed to write dts : " << strerror (errno) << std::endl;
127
+ std::cerr << " Failed to write dtc_input : " << strerror (errno) << std::endl;
123
128
exit (1 );
124
129
}
125
130
}
126
- close (dts_pipe [1 ]);
131
+ close (dtc_input_pipe [1 ]);
127
132
exit (0 );
128
133
}
129
134
130
- pid_t dtb_pid ;
131
- int dtb_pipe [2 ];
132
- if (pipe (dtb_pipe ) != 0 || (dtb_pid = fork ()) < 0 ) {
133
- std::cerr << " Failed to fork dtb child: " << strerror (errno) << std::endl;
135
+ pid_t dtc_output_pid ;
136
+ int dtc_output_pipe [2 ];
137
+ if (pipe (dtc_output_pipe ) != 0 || (dtc_output_pid = fork ()) < 0 ) {
138
+ std::cerr << " Failed to fork dtc_output child: " << strerror (errno) << std::endl;
134
139
exit (1 );
135
140
}
136
141
137
- // Child process to output dtb
138
- if (dtb_pid == 0 ) {
139
- dup2 (dts_pipe [0 ], 0 );
140
- dup2 (dtb_pipe [1 ], 1 );
141
- close (dts_pipe [0 ]);
142
- close (dts_pipe [1 ]);
143
- close (dtb_pipe [0 ]);
144
- close (dtb_pipe [1 ]);
145
- execlp (DTC, DTC, " -O" , " dtb " , (char *)0 );
142
+ // Child process to output dtc_output
143
+ if (dtc_output_pid == 0 ) {
144
+ dup2 (dtc_input_pipe [0 ], 0 );
145
+ dup2 (dtc_output_pipe [1 ], 1 );
146
+ close (dtc_input_pipe [0 ]);
147
+ close (dtc_input_pipe [1 ]);
148
+ close (dtc_output_pipe [0 ]);
149
+ close (dtc_output_pipe [1 ]);
150
+ execlp (DTC, DTC, " -O" , output_type. c_str (), " -I " , input_type. c_str () , (char *)0 );
146
151
std::cerr << " Failed to run " DTC " : " << strerror (errno) << std::endl;
147
152
exit (1 );
148
153
}
149
154
150
- close (dts_pipe [1 ]);
151
- close (dts_pipe [0 ]);
152
- close (dtb_pipe [1 ]);
155
+ close (dtc_input_pipe [1 ]);
156
+ close (dtc_input_pipe [0 ]);
157
+ close (dtc_output_pipe [1 ]);
153
158
154
- // Read-out dtb
155
- std::stringstream dtb ;
159
+ // Read-out dtc_output
160
+ std::stringstream dtc_output ;
156
161
157
162
int got;
158
163
char buf[4096 ];
159
- while ((got = read (dtb_pipe [0 ], buf, sizeof (buf))) > 0 ) {
160
- dtb .write (buf, got);
164
+ while ((got = read (dtc_output_pipe [0 ], buf, sizeof (buf))) > 0 ) {
165
+ dtc_output .write (buf, got);
161
166
}
162
167
if (got == -1 ) {
163
- std::cerr << " Failed to read dtb : " << strerror (errno) << std::endl;
168
+ std::cerr << " Failed to read dtc_output : " << strerror (errno) << std::endl;
164
169
exit (1 );
165
170
}
166
- close (dtb_pipe [0 ]);
171
+ close (dtc_output_pipe [0 ]);
167
172
168
173
// Reap children
169
174
int status;
170
- waitpid (dts_pid , &status, 0 );
175
+ waitpid (dtc_input_pid , &status, 0 );
171
176
if (!WIFEXITED (status) || WEXITSTATUS (status) != 0 ) {
172
- std::cerr << " Child dts process failed" << std::endl;
177
+ std::cerr << " Child dtc_input process failed" << std::endl;
173
178
exit (1 );
174
179
}
175
- waitpid (dtb_pid , &status, 0 );
180
+ waitpid (dtc_output_pid , &status, 0 );
176
181
if (!WIFEXITED (status) || WEXITSTATUS (status) != 0 ) {
177
- std::cerr << " Child dtb process failed" << std::endl;
182
+ std::cerr << " Child dtc_output process failed" << std::endl;
178
183
exit (1 );
179
184
}
180
185
181
- return dtb .str ();
186
+ return dtc_output .str ();
182
187
}
183
188
184
189
int fdt_get_node_addr_size (const void *fdt, int node, reg_t *addr,
0 commit comments