MCPcopy Create free account
hub / github.com/coreboot/coreboot / do_process

Function do_process

util/cbfstool/amdcompress.c:159–260  ·  view source on GitHub ↗

* zlib compressed case: * Build the required header and follow it with the compressed image. Detect * whether the input is an elf image, and if so, compress only the progbits. * * header * 0 +------+-------+-------+-------+ * | | | | | * +----------------------+-------+ * | | size | | | * +----------------------+-------+ *

Source from the content-addressed store, hash-verified

157 * n +------------------------------+
158 */
159static void do_process(char *outf, char *inf, size_t max_size, bool do_compress)
160{
161 int out_fd, in_fd;
162 struct buffer inbf, outbf;
163 int err;
164
165 in_fd = do_file(inf, &inbf.size, O_RDONLY);
166 if (in_fd < 0) {
167 printf("\tError opening input file %s\n", inf);
168 err = 1;
169 goto out;
170 }
171
172 out_fd = do_file(outf, 0, O_CREAT | O_WRONLY);
173 if (out_fd < 0) {
174 printf("\tError opening output file %s\n", outf);
175 err = 1;
176 goto out_close_in;
177 }
178
179 inbf.data = calloc(inbf.size, 1);
180 if (!inbf.data) {
181 printf("\tError allocating 0x%zx bytes for input buffer\n", inbf.size);
182 err = 1;
183 goto out_close_out;
184 }
185
186 if (read(in_fd, inbf.data, inbf.size) != (ssize_t)inbf.size) {
187 printf("\tError reading input file %s\n", inf);
188 err = 1;
189 goto out_free_in;
190 }
191
192 if (iself(inbf.data)) {
193 if (convert_elf(&inbf)) {
194 err = 1;
195 goto out_free_in;
196 }
197 }
198
199 if (max_size && inbf.size > max_size) {
200 printf("\tError - size (%zx) exceeds specified max_size (%zx)\n",
201 inbf.size, max_size);
202 err = 1;
203 goto out_free_in;
204 }
205
206 if (!do_compress) {
207 /*
208 * When no zlib compression is being used there's also no 256 byte header.
209 * Simply copy the input to the output.
210 */
211 err = 0;
212 if (write(out_fd, inbf.data, inbf.size) != (ssize_t)(inbf.size)) {
213 printf("\tError writing to %s\n", outf);
214 err = 1;
215 }
216 goto out_free_in;

Callers 1

mainFunction · 0.85

Calls 10

do_fileFunction · 0.85
printfFunction · 0.85
readFunction · 0.85
convert_elfFunction · 0.85
writeFunction · 0.85
compressFunction · 0.85
exitFunction · 0.85
iselfFunction · 0.70
callocFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected