OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 * | 4 * |
5 * Functions for generating and manipulating a verified boot firmware image. | 5 * Functions for generating and manipulating a verified boot firmware image. |
6 */ | 6 */ |
7 | 7 |
8 #include "firmware_image.h" | 8 #include "firmware_image.h" |
9 | 9 |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 Free(preamble_blob); | 250 Free(preamble_blob); |
251 Free(header_blob); | 251 Free(header_blob); |
252 | 252 |
253 if (st.overrun || st.remaining_len != 0) { /* Underrun or Overrun. */ | 253 if (st.overrun || st.remaining_len != 0) { /* Underrun or Overrun. */ |
254 Free(firmware_blob); | 254 Free(firmware_blob); |
255 return NULL; | 255 return NULL; |
256 } | 256 } |
257 return firmware_blob; | 257 return firmware_blob; |
258 } | 258 } |
259 | 259 |
260 int WriteFirmwareImage(const char* input_file, | 260 int WriteFirmwareImage(const char* output_file, |
261 const FirmwareImage* image, | 261 const FirmwareImage* image, |
262 int is_only_vblock) { | 262 int is_only_vblock) { |
263 int fd; | 263 int fd; |
264 int success = 1; | 264 int success = 1; |
265 uint8_t* firmware_blob; | 265 uint8_t* firmware_blob; |
266 uint64_t blob_len; | 266 uint64_t blob_len; |
267 | 267 |
268 if (!image) | 268 if (!image) |
269 return 0; | 269 return 0; |
270 if (-1 == (fd = creat(input_file, S_IRWXU))) { | 270 if (-1 == (fd = creat(output_file, 0666))) { |
271 debug("Couldn't open file for writing.\n"); | 271 debug("Couldn't open file for writing.\n"); |
272 return 0; | 272 return 0; |
273 } | 273 } |
274 | 274 |
275 firmware_blob = GetFirmwareBlob(image, &blob_len); | 275 firmware_blob = GetFirmwareBlob(image, &blob_len); |
276 if (!firmware_blob) { | 276 if (!firmware_blob) { |
277 debug("Couldn't create firmware blob from FirmwareImage.\n"); | 277 debug("Couldn't create firmware blob from FirmwareImage.\n"); |
278 return 0; | 278 return 0; |
279 } | 279 } |
280 if (!is_only_vblock) { | 280 if (!is_only_vblock) { |
281 if (blob_len != write(fd, firmware_blob, blob_len)) { | 281 if (blob_len != write(fd, firmware_blob, blob_len)) { |
282 debug("Couldn't write Firmware Image to file: %s\n", input_file); | 282 debug("Couldn't write Firmware Image to file: %s\n", output_file); |
283 success = 0; | 283 success = 0; |
284 } | 284 } |
285 } else { | 285 } else { |
286 /* Exclude the firmware_data. */ | 286 /* Exclude the firmware_data. */ |
287 int vblock_len = blob_len - image->firmware_len; | 287 int vblock_len = blob_len - image->firmware_len; |
288 if (vblock_len != write(fd, firmware_blob, vblock_len)) { | 288 if (vblock_len != write(fd, firmware_blob, vblock_len)) { |
289 debug("Couldn't write Firmware Image verifcation block to file: %s\n", | 289 debug("Couldn't write Firmware Image verifcation block to file: %s\n", |
290 input_file); | 290 output_file); |
291 success = 0; | 291 success = 0; |
292 } | 292 } |
293 } | 293 } |
294 Free(firmware_blob); | 294 Free(firmware_blob); |
295 close(fd); | 295 close(fd); |
296 return success; | 296 return success; |
297 } | 297 } |
298 | 298 |
299 void PrintFirmwareImage(const FirmwareImage* image) { | 299 void PrintFirmwareImage(const FirmwareImage* image) { |
300 if (!image) | 300 if (!image) |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 Free(firmware_buf); | 472 Free(firmware_buf); |
473 return 0; | 473 return 0; |
474 } | 474 } |
475 image->firmware_signature = (uint8_t*) Malloc(signature_len); | 475 image->firmware_signature = (uint8_t*) Malloc(signature_len); |
476 Memcpy(image->firmware_signature, firmware_signature, signature_len); | 476 Memcpy(image->firmware_signature, firmware_signature, signature_len); |
477 Free(firmware_signature); | 477 Free(firmware_signature); |
478 Free(firmware_buf); | 478 Free(firmware_buf); |
479 Free(preamble_blob); | 479 Free(preamble_blob); |
480 return 1; | 480 return 1; |
481 } | 481 } |
OLD | NEW |