| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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* output_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 is_subkey_out) { |
| 263 int fd; | 264 int fd; |
| 264 int success = 1; | 265 int success = 1; |
| 265 uint8_t* firmware_blob; | 266 uint8_t* firmware_blob; |
| 267 uint8_t* subkey_out_buf = NULL; |
| 268 uint8_t* subkey_header = NULL; |
| 266 uint64_t blob_len; | 269 uint64_t blob_len; |
| 267 | 270 |
| 268 if (!image) | 271 if (!image) |
| 269 return 0; | 272 return 0; |
| 270 if (-1 == (fd = creat(output_file, 0666))) { | 273 if (-1 == (fd = creat(output_file, 0666))) { |
| 271 debug("Couldn't open file for writing.\n"); | 274 debug("Couldn't open file for writing.\n"); |
| 272 return 0; | 275 return 0; |
| 273 } | 276 } |
| 277 if (is_subkey_out) { |
| 278 blob_len = GetFirmwareHeaderLen(image) + |
| 279 siglen_map[ROOT_SIGNATURE_ALGORITHM]; |
| 280 subkey_out_buf = (uint8_t*) Malloc(blob_len); |
| 281 subkey_header = GetFirmwareHeaderBlob(image); |
| 282 Memcpy(subkey_out_buf, subkey_header, GetFirmwareHeaderLen(image)); |
| 283 Memcpy(subkey_out_buf + GetFirmwareHeaderLen(image), |
| 284 image->firmware_key_signature, |
| 285 siglen_map[ROOT_SIGNATURE_ALGORITHM]); |
| 286 if (blob_len != write(fd, subkey_out_buf, blob_len)) { |
| 287 debug("Couldn't write kernel subkey header to file: %s\n", |
| 288 output_file); |
| 289 success = 0; |
| 290 } |
| 291 Free(subkey_header); |
| 292 Free(subkey_out_buf); |
| 293 close(fd); |
| 294 return success; |
| 295 } |
| 274 | 296 |
| 275 firmware_blob = GetFirmwareBlob(image, &blob_len); | 297 firmware_blob = GetFirmwareBlob(image, &blob_len); |
| 276 if (!firmware_blob) { | 298 if (!firmware_blob) { |
| 277 debug("Couldn't create firmware blob from FirmwareImage.\n"); | 299 debug("Couldn't create firmware blob from FirmwareImage.\n"); |
| 278 return 0; | 300 return 0; |
| 279 } | 301 } |
| 280 if (!is_only_vblock) { | 302 if (!is_only_vblock) { |
| 281 if (blob_len != write(fd, firmware_blob, blob_len)) { | 303 if (blob_len != write(fd, firmware_blob, blob_len)) { |
| 282 debug("Couldn't write Firmware Image to file: %s\n", output_file); | 304 debug("Couldn't write Firmware Image to file: %s\n", output_file); |
| 283 success = 0; | 305 success = 0; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 Free(firmware_buf); | 494 Free(firmware_buf); |
| 473 return 0; | 495 return 0; |
| 474 } | 496 } |
| 475 image->firmware_signature = (uint8_t*) Malloc(signature_len); | 497 image->firmware_signature = (uint8_t*) Malloc(signature_len); |
| 476 Memcpy(image->firmware_signature, firmware_signature, signature_len); | 498 Memcpy(image->firmware_signature, firmware_signature, signature_len); |
| 477 Free(firmware_signature); | 499 Free(firmware_signature); |
| 478 Free(firmware_buf); | 500 Free(firmware_buf); |
| 479 Free(preamble_blob); | 501 Free(preamble_blob); |
| 480 return 1; | 502 return 1; |
| 481 } | 503 } |
| OLD | NEW |