Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: src/platform/vboot_reference/vfirmware/firmware_image.c

Issue 1525032: Add a --vblock option to firmware_utility to only output the verification block. (Closed)
Patch Set: fix typo Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
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* input_file,
261 const FirmwareImage* image) { 261 const FirmwareImage* image,
262 int is_only_vblock) {
262 int fd; 263 int fd;
264 int success = 1;
263 uint8_t* firmware_blob; 265 uint8_t* firmware_blob;
264 uint64_t blob_len; 266 uint64_t blob_len;
265 267
266 if (!image) 268 if (!image)
267 return 0; 269 return 0;
268 if (-1 == (fd = creat(input_file, S_IRWXU))) { 270 if (-1 == (fd = creat(input_file, S_IRWXU))) {
269 debug("Couldn't open file for writing.\n"); 271 debug("Couldn't open file for writing.\n");
270 return 0; 272 return 0;
271 } 273 }
272 274
273 firmware_blob = GetFirmwareBlob(image, &blob_len); 275 firmware_blob = GetFirmwareBlob(image, &blob_len);
274 if (!firmware_blob) { 276 if (!firmware_blob) {
275 debug("Couldn't create firmware blob from FirmwareImage.\n"); 277 debug("Couldn't create firmware blob from FirmwareImage.\n");
276 return 0; 278 return 0;
277 } 279 }
278 if (blob_len != write(fd, firmware_blob, blob_len)) { 280 if (!is_only_vblock) {
279 debug("Couldn't write Firmware Image to file: %s\n", input_file); 281 if (blob_len != write(fd, firmware_blob, blob_len)) {
280 Free(firmware_blob); 282 debug("Couldn't write Firmware Image to file: %s\n", input_file);
281 close(fd); 283 success = 0;
282 return 0; 284 }
285 } else {
286 /* Exclude the firmware_data. */
287 int vblock_len = blob_len - image->firmware_len;
288 if (vblock_len != write(fd, firmware_blob, vblock_len)) {
289 debug("Couldn't write Firmware Image verifcation block to file: %s\n",
290 input_file);
291 success = 0;
292 }
283 } 293 }
284 Free(firmware_blob); 294 Free(firmware_blob);
285 close(fd); 295 close(fd);
286 return 1; 296 return success;
287 } 297 }
288 298
289 void PrintFirmwareImage(const FirmwareImage* image) { 299 void PrintFirmwareImage(const FirmwareImage* image) {
290 if (!image) 300 if (!image)
291 return; 301 return;
292 302
293 /* Print header. */ 303 /* Print header. */
294 debug("Header Length = %d\n" 304 debug("Header Length = %d\n"
295 "Firmware Signature Algorithm = %s\n" 305 "Firmware Signature Algorithm = %s\n"
296 "Firmware Key Version = %d\n\n", 306 "Firmware Key Version = %d\n\n",
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 Free(firmware_buf); 472 Free(firmware_buf);
463 return 0; 473 return 0;
464 } 474 }
465 image->firmware_signature = (uint8_t*) Malloc(signature_len); 475 image->firmware_signature = (uint8_t*) Malloc(signature_len);
466 Memcpy(image->firmware_signature, firmware_signature, signature_len); 476 Memcpy(image->firmware_signature, firmware_signature, signature_len);
467 Free(firmware_signature); 477 Free(firmware_signature);
468 Free(firmware_buf); 478 Free(firmware_buf);
469 Free(preamble_blob); 479 Free(preamble_blob);
470 return 1; 480 return 1;
471 } 481 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698