| 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 * Verified boot kernel utility | 5 * Verified boot kernel utility |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <getopt.h> | 9 #include <getopt.h> |
| 10 #include <inttypes.h> /* For PRIu64 */ | 10 #include <inttypes.h> /* For PRIu64 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 static const int DEFAULT_PADDING = 65536; | 29 static const int DEFAULT_PADDING = 65536; |
| 30 | 30 |
| 31 /* Command line options */ | 31 /* Command line options */ |
| 32 enum { | 32 enum { |
| 33 OPT_MODE_PACK = 1000, | 33 OPT_MODE_PACK = 1000, |
| 34 OPT_MODE_REPACK, | 34 OPT_MODE_REPACK, |
| 35 OPT_MODE_VERIFY, | 35 OPT_MODE_VERIFY, |
| 36 OPT_ARCH, | 36 OPT_ARCH, |
| 37 OPT_OLDBLOB, | 37 OPT_OLDBLOB, |
| 38 OPT_KLOADADDR, | |
| 39 OPT_KEYBLOCK, | 38 OPT_KEYBLOCK, |
| 40 OPT_SIGNPUBKEY, | 39 OPT_SIGNPUBKEY, |
| 41 OPT_SIGNPRIVATE, | 40 OPT_SIGNPRIVATE, |
| 42 OPT_VERSION, | 41 OPT_VERSION, |
| 43 OPT_VMLINUZ, | 42 OPT_VMLINUZ, |
| 44 OPT_BOOTLOADER, | 43 OPT_BOOTLOADER, |
| 45 OPT_CONFIG, | 44 OPT_CONFIG, |
| 46 OPT_VBLOCKONLY, | 45 OPT_VBLOCKONLY, |
| 47 OPT_PAD, | 46 OPT_PAD, |
| 48 OPT_VERBOSE, | 47 OPT_VERBOSE, |
| 49 }; | 48 }; |
| 50 | 49 |
| 51 enum { | 50 enum { |
| 52 ARCH_ARM, | 51 ARCH_ARM, |
| 53 ARCH_X86 /* default */ | 52 ARCH_X86 /* default */ |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 static struct option long_opts[] = { | 55 static struct option long_opts[] = { |
| 57 {"pack", 1, 0, OPT_MODE_PACK }, | 56 {"pack", 1, 0, OPT_MODE_PACK }, |
| 58 {"repack", 1, 0, OPT_MODE_REPACK }, | 57 {"repack", 1, 0, OPT_MODE_REPACK }, |
| 59 {"verify", 1, 0, OPT_MODE_VERIFY }, | 58 {"verify", 1, 0, OPT_MODE_VERIFY }, |
| 60 {"arch", 1, 0, OPT_ARCH }, | 59 {"arch", 1, 0, OPT_ARCH }, |
| 61 {"oldblob", 1, 0, OPT_OLDBLOB }, | 60 {"oldblob", 1, 0, OPT_OLDBLOB }, |
| 62 {"kloadaddr", 1, 0, OPT_KLOADADDR }, | |
| 63 {"keyblock", 1, 0, OPT_KEYBLOCK }, | 61 {"keyblock", 1, 0, OPT_KEYBLOCK }, |
| 64 {"signpubkey", 1, 0, OPT_SIGNPUBKEY }, | 62 {"signpubkey", 1, 0, OPT_SIGNPUBKEY }, |
| 65 {"signprivate", 1, 0, OPT_SIGNPRIVATE }, | 63 {"signprivate", 1, 0, OPT_SIGNPRIVATE }, |
| 66 {"version", 1, 0, OPT_VERSION }, | 64 {"version", 1, 0, OPT_VERSION }, |
| 67 {"vmlinuz", 1, 0, OPT_VMLINUZ }, | 65 {"vmlinuz", 1, 0, OPT_VMLINUZ }, |
| 68 {"bootloader", 1, 0, OPT_BOOTLOADER }, | 66 {"bootloader", 1, 0, OPT_BOOTLOADER }, |
| 69 {"config", 1, 0, OPT_CONFIG }, | 67 {"config", 1, 0, OPT_CONFIG }, |
| 70 {"vblockonly", 0, 0, OPT_VBLOCKONLY }, | 68 {"vblockonly", 0, 0, OPT_VBLOCKONLY }, |
| 71 {"pad", 1, 0, OPT_PAD }, | 69 {"pad", 1, 0, OPT_PAD }, |
| 72 {"verbose", 0, 0, OPT_VERBOSE }, | 70 {"verbose", 0, 0, OPT_VERBOSE }, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 87 " --keyblock <file> Key block in .keyblock format\n" | 85 " --keyblock <file> Key block in .keyblock format\n" |
| 88 " --signprivate <file>" | 86 " --signprivate <file>" |
| 89 " Private key to sign kernel data, in .vbprivk format\n" | 87 " Private key to sign kernel data, in .vbprivk format\n" |
| 90 " --version <number> Kernel version\n" | 88 " --version <number> Kernel version\n" |
| 91 " --vmlinuz <file> Linux kernel bzImage file\n" | 89 " --vmlinuz <file> Linux kernel bzImage file\n" |
| 92 " --bootloader <file> Bootloader stub\n" | 90 " --bootloader <file> Bootloader stub\n" |
| 93 " --config <file> Command line file\n" | 91 " --config <file> Command line file\n" |
| 94 " --arch <arch> Cpu architecture (default x86)\n" | 92 " --arch <arch> Cpu architecture (default x86)\n" |
| 95 "\n" | 93 "\n" |
| 96 " Optional:\n" | 94 " Optional:\n" |
| 97 " --kloadaddr <address> Assign kernel body load address\n" | |
| 98 " --pad <number> Verification padding size in bytes\n" | 95 " --pad <number> Verification padding size in bytes\n" |
| 99 " --vblockonly Emit just the verification blob\n", | 96 " --vblockonly Emit just the verification blob\n", |
| 100 progname); | 97 progname); |
| 101 fprintf(stderr, | 98 fprintf(stderr, |
| 102 "\nOR\n\n" | 99 "\nOR\n\n" |
| 103 "Usage: %s --repack <file> [PARAMETERS]\n" | 100 "Usage: %s --repack <file> [PARAMETERS]\n" |
| 104 "\n" | 101 "\n" |
| 105 " Required parameters (of --keyblock, --config, and --version \n" | 102 " Required parameters (of --keyblock, --config, and --version \n" |
| 106 " at least one is required):\n" | 103 " at least one is required):\n" |
| 107 " --keyblock <file> Key block in .keyblock format\n" | 104 " --keyblock <file> Key block in .keyblock format\n" |
| 108 " --signprivate <file>" | 105 " --signprivate <file>" |
| 109 " Private key to sign kernel data, in .vbprivk format\n" | 106 " Private key to sign kernel data, in .vbprivk format\n" |
| 110 " --oldblob <file> Previously packed kernel blob\n" | 107 " --oldblob <file> Previously packed kernel blob\n" |
| 111 " --config <file> New command line file\n" | 108 " --config <file> New command line file\n" |
| 112 " --version <number> Kernel version\n" | 109 " --version <number> Kernel version\n" |
| 113 "\n" | 110 "\n" |
| 114 " Optional:\n" | 111 " Optional:\n" |
| 115 " --kloadaddr <address> Assign kernel body load address\n" | |
| 116 " --pad <number> Verification padding size in bytes\n" | 112 " --pad <number> Verification padding size in bytes\n" |
| 117 " --vblockonly Emit just the verification blob\n", | 113 " --vblockonly Emit just the verification blob\n", |
| 118 progname); | 114 progname); |
| 119 fprintf(stderr, | 115 fprintf(stderr, |
| 120 "\nOR\n\n" | 116 "\nOR\n\n" |
| 121 "Usage: %s --verify <file> [PARAMETERS]\n" | 117 "Usage: %s --verify <file> [PARAMETERS]\n" |
| 122 "\n" | 118 "\n" |
| 123 " Optional:\n" | 119 " Optional:\n" |
| 124 " --signpubkey <file>" | 120 " --signpubkey <file>" |
| 125 " Public key to verify kernel keyblock, in .vbpubk format\n" | 121 " Public key to verify kernel keyblock, in .vbpubk format\n" |
| 126 " --verbose Print a more detailed report\n" | 122 " --verbose Print a more detailed report\n" |
| 127 " --keyblock <file>" | 123 " --keyblock <file>" |
| 128 " Outputs the verified key block, in .keyblock format\n" | 124 " Outputs the verified key block, in .keyblock format\n" |
| 129 " --kloadaddr <address> Assign kernel body load address\n" | |
| 130 "\n", | 125 "\n", |
| 131 progname); | 126 progname); |
| 132 return 1; | 127 return 1; |
| 133 } | 128 } |
| 134 | 129 |
| 135 static void Debug(const char *format, ...) { | 130 static void Debug(const char *format, ...) { |
| 136 if (!opt_debug) | 131 if (!opt_debug) |
| 137 return; | 132 return; |
| 138 | 133 |
| 139 va_list ap; | 134 va_list ap; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 uint8_t *blob; | 192 uint8_t *blob; |
| 198 | 193 |
| 199 /* these fields are not always initialized */ | 194 /* these fields are not always initialized */ |
| 200 VbKernelPreambleHeader* preamble; | 195 VbKernelPreambleHeader* preamble; |
| 201 VbKeyBlockHeader* key_block; | 196 VbKeyBlockHeader* key_block; |
| 202 uint8_t *buf; | 197 uint8_t *buf; |
| 203 | 198 |
| 204 } blob_t; | 199 } blob_t; |
| 205 | 200 |
| 206 /* Given a blob return the location of the kernel command line buffer. */ | 201 /* Given a blob return the location of the kernel command line buffer. */ |
| 207 static char* BpCmdLineLocation(blob_t *bp, uint64_t kernel_body_load_address) | 202 static char* BpCmdLineLocation(blob_t *bp) |
| 208 { | 203 { |
| 209 return (char*)(bp->blob + bp->bootloader_address - kernel_body_load_address - | 204 return (char*)(bp->blob + bp->bootloader_address - CROS_32BIT_ENTRY_ADDR - |
| 210 CROS_CONFIG_SIZE - CROS_PARAMS_SIZE); | 205 CROS_CONFIG_SIZE - CROS_PARAMS_SIZE); |
| 211 } | 206 } |
| 212 | 207 |
| 213 static void FreeBlob(blob_t *bp) { | 208 static void FreeBlob(blob_t *bp) { |
| 214 if (bp) { | 209 if (bp) { |
| 215 if (bp->blob) | 210 if (bp->blob) |
| 216 Free(bp->blob); | 211 Free(bp->blob); |
| 217 if (bp->buf) | 212 if (bp->buf) |
| 218 Free(bp->buf); | 213 Free(bp->buf); |
| 219 Free(bp); | 214 Free(bp); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 247 } | 242 } |
| 248 } | 243 } |
| 249 return config_buf; | 244 return config_buf; |
| 250 } | 245 } |
| 251 | 246 |
| 252 /* Create a blob from its components */ | 247 /* Create a blob from its components */ |
| 253 static blob_t *NewBlob(uint64_t version, | 248 static blob_t *NewBlob(uint64_t version, |
| 254 const char* vmlinuz, | 249 const char* vmlinuz, |
| 255 const char* bootloader_file, | 250 const char* bootloader_file, |
| 256 const char* config_file, | 251 const char* config_file, |
| 257 int arch, | 252 int arch) { |
| 258 uint64_t kernel_body_load_address) { | |
| 259 blob_t* bp; | 253 blob_t* bp; |
| 260 struct linux_kernel_header* lh = 0; | 254 struct linux_kernel_header* lh = 0; |
| 261 struct linux_kernel_params* params = 0; | 255 struct linux_kernel_params* params = 0; |
| 262 uint8_t* config_buf; | 256 uint8_t* config_buf; |
| 263 uint64_t config_size; | 257 uint64_t config_size; |
| 264 uint8_t* bootloader_buf; | 258 uint8_t* bootloader_buf; |
| 265 uint64_t bootloader_size; | 259 uint64_t bootloader_size; |
| 266 uint8_t* kernel_buf; | 260 uint8_t* kernel_buf; |
| 267 uint64_t kernel_size; | 261 uint64_t kernel_size; |
| 268 uint64_t kernel32_start = 0; | 262 uint64_t kernel32_start = 0; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 bp->blob = blob; | 333 bp->blob = blob; |
| 340 | 334 |
| 341 /* Copy the 32-bit kernel. */ | 335 /* Copy the 32-bit kernel. */ |
| 342 Debug("kernel goes at blob+=0x%" PRIx64 "\n", now); | 336 Debug("kernel goes at blob+=0x%" PRIx64 "\n", now); |
| 343 if (kernel32_size) | 337 if (kernel32_size) |
| 344 Memcpy(blob + now, kernel_buf + kernel32_start, kernel32_size); | 338 Memcpy(blob + now, kernel_buf + kernel32_start, kernel32_size); |
| 345 now += roundup(now + kernel32_size, CROS_ALIGN); | 339 now += roundup(now + kernel32_size, CROS_ALIGN); |
| 346 | 340 |
| 347 Debug("config goes at blob+0x%" PRIx64 "\n", now); | 341 Debug("config goes at blob+0x%" PRIx64 "\n", now); |
| 348 /* Find the load address of the commandline. We'll need it later. */ | 342 /* Find the load address of the commandline. We'll need it later. */ |
| 349 cmdline_addr = kernel_body_load_address + now + | 343 cmdline_addr = CROS_32BIT_ENTRY_ADDR + now + |
| 350 find_cmdline_start((char *)config_buf, config_size); | 344 find_cmdline_start((char *)config_buf, config_size); |
| 351 Debug(" cmdline_addr=0x%" PRIx64 "\n", cmdline_addr); | 345 Debug(" cmdline_addr=0x%" PRIx64 "\n", cmdline_addr); |
| 352 | 346 |
| 353 /* Copy the config. */ | 347 /* Copy the config. */ |
| 354 if (config_size) | 348 if (config_size) |
| 355 Memcpy(blob + now, config_buf, config_size); | 349 Memcpy(blob + now, config_buf, config_size); |
| 356 now += CROS_CONFIG_SIZE; | 350 now += CROS_CONFIG_SIZE; |
| 357 | 351 |
| 358 /* The zeropage data is next. Overlay the linux_kernel_header onto it, and | 352 /* The zeropage data is next. Overlay the linux_kernel_header onto it, and |
| 359 * tweak a few fields. */ | 353 * tweak a few fields. */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 376 params->e820_entries[0].segment_size = 0x00001000; | 370 params->e820_entries[0].segment_size = 0x00001000; |
| 377 params->e820_entries[0].segment_type = E820_TYPE_RAM; | 371 params->e820_entries[0].segment_type = E820_TYPE_RAM; |
| 378 params->e820_entries[1].start_addr = 0xfffff000; | 372 params->e820_entries[1].start_addr = 0xfffff000; |
| 379 params->e820_entries[1].segment_size = 0x00001000; | 373 params->e820_entries[1].segment_size = 0x00001000; |
| 380 params->e820_entries[1].segment_type = E820_TYPE_RESERVED; | 374 params->e820_entries[1].segment_type = E820_TYPE_RESERVED; |
| 381 now += CROS_PARAMS_SIZE; | 375 now += CROS_PARAMS_SIZE; |
| 382 | 376 |
| 383 /* Finally, append the bootloader. Remember where it will load in | 377 /* Finally, append the bootloader. Remember where it will load in |
| 384 * memory, too. */ | 378 * memory, too. */ |
| 385 Debug("bootloader goes at blob+=0x%" PRIx64 "\n", now); | 379 Debug("bootloader goes at blob+=0x%" PRIx64 "\n", now); |
| 386 bp->bootloader_address = kernel_body_load_address + now; | 380 bp->bootloader_address = CROS_32BIT_ENTRY_ADDR + now; |
| 387 bp->bootloader_size = roundup(bootloader_size, CROS_ALIGN); | 381 bp->bootloader_size = roundup(bootloader_size, CROS_ALIGN); |
| 388 Debug(" bootloader_address=0x%" PRIx64 "\n", bp->bootloader_address); | 382 Debug(" bootloader_address=0x%" PRIx64 "\n", bp->bootloader_address); |
| 389 Debug(" bootloader_size=0x%" PRIx64 "\n", bp->bootloader_size); | 383 Debug(" bootloader_size=0x%" PRIx64 "\n", bp->bootloader_size); |
| 390 if (bootloader_size) | 384 if (bootloader_size) |
| 391 Memcpy(blob + now, bootloader_buf, bootloader_size); | 385 Memcpy(blob + now, bootloader_buf, bootloader_size); |
| 392 now += bp->bootloader_size; | 386 now += bp->bootloader_size; |
| 393 Debug("end of blob is 0x%" PRIx64 "\n", now); | 387 Debug("end of blob is 0x%" PRIx64 "\n", now); |
| 394 | 388 |
| 395 /* Free input buffers */ | 389 /* Free input buffers */ |
| 396 Free(kernel_buf); | 390 Free(kernel_buf); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 Free(buf); | 518 Free(buf); |
| 525 } | 519 } |
| 526 } | 520 } |
| 527 return bp; | 521 return bp; |
| 528 } | 522 } |
| 529 | 523 |
| 530 | 524 |
| 531 /* Pack a .kernel */ | 525 /* Pack a .kernel */ |
| 532 static int Pack(const char* outfile, const char* keyblock_file, | 526 static int Pack(const char* outfile, const char* keyblock_file, |
| 533 const char* signprivate, blob_t *bp, uint64_t pad, | 527 const char* signprivate, blob_t *bp, uint64_t pad, |
| 534 int vblockonly, | 528 int vblockonly) { |
| 535 uint64_t kernel_body_load_address) { | |
| 536 VbPrivateKey* signing_key; | 529 VbPrivateKey* signing_key; |
| 537 VbSignature* body_sig; | 530 VbSignature* body_sig; |
| 538 VbKernelPreambleHeader* preamble; | 531 VbKernelPreambleHeader* preamble; |
| 539 VbKeyBlockHeader* key_block; | 532 VbKeyBlockHeader* key_block; |
| 540 uint64_t key_block_size; | 533 uint64_t key_block_size; |
| 541 FILE* f; | 534 FILE* f; |
| 542 uint64_t i; | 535 uint64_t i; |
| 543 | 536 |
| 544 if (!outfile) { | 537 if (!outfile) { |
| 545 error("Must specify output filename\n"); | 538 error("Must specify output filename\n"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 | 572 |
| 580 /* Sign the kernel data */ | 573 /* Sign the kernel data */ |
| 581 body_sig = CalculateSignature(bp->blob, bp->blob_size, signing_key); | 574 body_sig = CalculateSignature(bp->blob, bp->blob_size, signing_key); |
| 582 if (!body_sig) { | 575 if (!body_sig) { |
| 583 error("Error calculating body signature\n"); | 576 error("Error calculating body signature\n"); |
| 584 return 1; | 577 return 1; |
| 585 } | 578 } |
| 586 | 579 |
| 587 /* Create preamble */ | 580 /* Create preamble */ |
| 588 preamble = CreateKernelPreamble(bp->kernel_version, | 581 preamble = CreateKernelPreamble(bp->kernel_version, |
| 589 kernel_body_load_address, | 582 CROS_32BIT_ENTRY_ADDR, |
| 590 bp->bootloader_address, | 583 bp->bootloader_address, |
| 591 bp->bootloader_size, | 584 bp->bootloader_size, |
| 592 body_sig, | 585 body_sig, |
| 593 pad - key_block_size, | 586 pad - key_block_size, |
| 594 signing_key); | 587 signing_key); |
| 595 if (!preamble) { | 588 if (!preamble) { |
| 596 error("Error creating preamble.\n"); | 589 error("Error creating preamble.\n"); |
| 597 return 1; | 590 return 1; |
| 598 } | 591 } |
| 599 | 592 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 628 | 621 |
| 629 fclose(f); | 622 fclose(f); |
| 630 | 623 |
| 631 /* Success */ | 624 /* Success */ |
| 632 return 0; | 625 return 0; |
| 633 } | 626 } |
| 634 | 627 |
| 635 /* | 628 /* |
| 636 * Replace kernel command line in a blob representing a kernel. | 629 * Replace kernel command line in a blob representing a kernel. |
| 637 */ | 630 */ |
| 638 static int ReplaceConfig(blob_t* bp, const char* config_file, | 631 static int ReplaceConfig(blob_t* bp, const char* config_file) |
| 639 uint64_t kernel_body_load_address) | |
| 640 { | 632 { |
| 641 uint8_t* new_conf; | 633 uint8_t* new_conf; |
| 642 uint64_t config_size; | 634 uint64_t config_size; |
| 643 | 635 |
| 644 if (!config_file) { | 636 if (!config_file) { |
| 645 return 0; | 637 return 0; |
| 646 } | 638 } |
| 647 | 639 |
| 648 new_conf = ReadConfigFile(config_file, &config_size); | 640 new_conf = ReadConfigFile(config_file, &config_size); |
| 649 if (!new_conf) { | 641 if (!new_conf) { |
| 650 return 1; | 642 return 1; |
| 651 } | 643 } |
| 652 | 644 |
| 653 /* fill the config buffer with zeros */ | 645 /* fill the config buffer with zeros */ |
| 654 Memset(BpCmdLineLocation(bp, kernel_body_load_address), 0, CROS_CONFIG_SIZE); | 646 Memset(BpCmdLineLocation(bp), 0, CROS_CONFIG_SIZE); |
| 655 Memcpy(BpCmdLineLocation(bp, kernel_body_load_address), | 647 Memcpy(BpCmdLineLocation(bp), new_conf, config_size); |
| 656 new_conf, config_size); | |
| 657 Free(new_conf); | 648 Free(new_conf); |
| 658 return 0; | 649 return 0; |
| 659 } | 650 } |
| 660 | 651 |
| 661 static int Verify(const char* infile, const char* signpubkey, int verbose, | 652 static int Verify(const char* infile, const char* signpubkey, int verbose, |
| 662 const char* key_block_file, | 653 const char* key_block_file) { |
| 663 uint64_t kernel_body_load_address) { | |
| 664 | 654 |
| 665 VbKeyBlockHeader* key_block; | 655 VbKeyBlockHeader* key_block; |
| 666 VbKernelPreambleHeader* preamble; | 656 VbKernelPreambleHeader* preamble; |
| 667 VbPublicKey* data_key; | 657 VbPublicKey* data_key; |
| 668 VbPublicKey* sign_key = NULL; | 658 VbPublicKey* sign_key = NULL; |
| 669 RSAPublicKey* rsa; | 659 RSAPublicKey* rsa; |
| 670 blob_t* bp; | 660 blob_t* bp; |
| 671 uint64_t now; | 661 uint64_t now; |
| 672 int rv = 1; | 662 int rv = 1; |
| 673 | 663 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 goto verify_exit; | 762 goto verify_exit; |
| 773 } | 763 } |
| 774 printf("Body verification succeeded.\n"); | 764 printf("Body verification succeeded.\n"); |
| 775 | 765 |
| 776 rv = 0; | 766 rv = 0; |
| 777 | 767 |
| 778 if (!verbose) { | 768 if (!verbose) { |
| 779 goto verify_exit; | 769 goto verify_exit; |
| 780 } | 770 } |
| 781 | 771 |
| 782 printf("Config:\n%s\n", BpCmdLineLocation(bp, kernel_body_load_address)); | 772 printf("Config:\n%s\n", BpCmdLineLocation(bp)); |
| 783 | 773 |
| 784 verify_exit: | 774 verify_exit: |
| 785 FreeBlob(bp); | 775 FreeBlob(bp); |
| 786 return rv; | 776 return rv; |
| 787 } | 777 } |
| 788 | 778 |
| 789 | 779 |
| 790 int main(int argc, char* argv[]) { | 780 int main(int argc, char* argv[]) { |
| 791 char* filename = NULL; | 781 char* filename = NULL; |
| 792 char* oldfile = NULL; | 782 char* oldfile = NULL; |
| 793 char* key_block_file = NULL; | 783 char* key_block_file = NULL; |
| 794 char* signpubkey = NULL; | 784 char* signpubkey = NULL; |
| 795 char* signprivate = NULL; | 785 char* signprivate = NULL; |
| 796 int version = -1; | 786 int version = -1; |
| 797 char* vmlinuz = NULL; | 787 char* vmlinuz = NULL; |
| 798 char* bootloader = NULL; | 788 char* bootloader = NULL; |
| 799 char* config_file = NULL; | 789 char* config_file = NULL; |
| 800 int arch = ARCH_X86; | 790 int arch = ARCH_X86; |
| 801 int vblockonly = 0; | 791 int vblockonly = 0; |
| 802 int verbose = 0; | 792 int verbose = 0; |
| 803 uint64_t kernel_body_load_address = CROS_32BIT_ENTRY_ADDR; | |
| 804 uint64_t pad = DEFAULT_PADDING; | 793 uint64_t pad = DEFAULT_PADDING; |
| 805 int mode = 0; | 794 int mode = 0; |
| 806 int parse_error = 0; | 795 int parse_error = 0; |
| 807 char* e; | 796 char* e; |
| 808 int i,r; | 797 int i,r; |
| 809 blob_t *bp; | 798 blob_t *bp; |
| 810 | 799 |
| 811 | 800 |
| 812 char *progname = strrchr(argv[0], '/'); | 801 char *progname = strrchr(argv[0], '/'); |
| 813 if (progname) | 802 if (progname) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 else { | 837 else { |
| 849 fprintf(stderr, "Unknown architecture string: %s\n", optarg); | 838 fprintf(stderr, "Unknown architecture string: %s\n", optarg); |
| 850 parse_error = 1; | 839 parse_error = 1; |
| 851 } | 840 } |
| 852 break; | 841 break; |
| 853 | 842 |
| 854 case OPT_OLDBLOB: | 843 case OPT_OLDBLOB: |
| 855 oldfile = optarg; | 844 oldfile = optarg; |
| 856 break; | 845 break; |
| 857 | 846 |
| 858 case OPT_KLOADADDR: | |
| 859 kernel_body_load_address = strtoul(optarg, &e, 0); | |
| 860 if (!*optarg || (e && *e)) { | |
| 861 fprintf(stderr, "Invalid --kloadaddr\n"); | |
| 862 parse_error = 1; | |
| 863 } | |
| 864 break; | |
| 865 | |
| 866 case OPT_KEYBLOCK: | 847 case OPT_KEYBLOCK: |
| 867 key_block_file = optarg; | 848 key_block_file = optarg; |
| 868 break; | 849 break; |
| 869 | 850 |
| 870 case OPT_SIGNPUBKEY: | 851 case OPT_SIGNPUBKEY: |
| 871 signpubkey = optarg; | 852 signpubkey = optarg; |
| 872 break; | 853 break; |
| 873 | 854 |
| 874 case OPT_SIGNPRIVATE: | 855 case OPT_SIGNPRIVATE: |
| 875 signprivate = optarg; | 856 signprivate = optarg; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 verbose = 1; | 892 verbose = 1; |
| 912 break; | 893 break; |
| 913 } | 894 } |
| 914 } | 895 } |
| 915 | 896 |
| 916 if (parse_error) | 897 if (parse_error) |
| 917 return PrintHelp(progname); | 898 return PrintHelp(progname); |
| 918 | 899 |
| 919 switch(mode) { | 900 switch(mode) { |
| 920 case OPT_MODE_PACK: | 901 case OPT_MODE_PACK: |
| 921 bp = NewBlob(version, vmlinuz, bootloader, config_file, arch, | 902 bp = NewBlob(version, vmlinuz, bootloader, config_file, arch); |
| 922 kernel_body_load_address); | |
| 923 if (!bp) | 903 if (!bp) |
| 924 return 1; | 904 return 1; |
| 925 r = Pack(filename, key_block_file, signprivate, bp, pad, vblockonly, | 905 r = Pack(filename, key_block_file, signprivate, bp, pad, vblockonly); |
| 926 kernel_body_load_address); | |
| 927 FreeBlob(bp); | 906 FreeBlob(bp); |
| 928 return r; | 907 return r; |
| 929 | 908 |
| 930 case OPT_MODE_REPACK: | 909 case OPT_MODE_REPACK: |
| 931 if (!config_file && !key_block_file && (version<0)) { | 910 if (!config_file && !key_block_file && (version<0)) { |
| 932 fprintf(stderr, | 911 fprintf(stderr, |
| 933 "You must supply at least one of " | 912 "You must supply at least one of " |
| 934 "--config, --keyblock or --version\n"); | 913 "--config, --keyblock or --version\n"); |
| 935 return 1; | 914 return 1; |
| 936 } | 915 } |
| 937 | 916 |
| 938 bp = OldBlob(oldfile); | 917 bp = OldBlob(oldfile); |
| 939 if (!bp) | 918 if (!bp) |
| 940 return 1; | 919 return 1; |
| 941 r = ReplaceConfig(bp, config_file, kernel_body_load_address); | 920 r = ReplaceConfig(bp, config_file); |
| 942 if (!r) { | 921 if (!r) { |
| 943 if (version >= 0) { | 922 if (version >= 0) { |
| 944 bp->kernel_version = (uint64_t) version; | 923 bp->kernel_version = (uint64_t) version; |
| 945 } | 924 } |
| 946 r = Pack(filename, key_block_file, signprivate, bp, pad, vblockonly, | 925 r = Pack(filename, key_block_file, signprivate, bp, pad, vblockonly); |
| 947 kernel_body_load_address); | |
| 948 } | 926 } |
| 949 FreeBlob(bp); | 927 FreeBlob(bp); |
| 950 return r; | 928 return r; |
| 951 | 929 |
| 952 case OPT_MODE_VERIFY: | 930 case OPT_MODE_VERIFY: |
| 953 return Verify(filename, signpubkey, verbose, key_block_file, | 931 return Verify(filename, signpubkey, verbose, key_block_file); |
| 954 kernel_body_load_address); | |
| 955 | 932 |
| 956 default: | 933 default: |
| 957 fprintf(stderr, | 934 fprintf(stderr, |
| 958 "You must specify a mode: --pack, --repack or --verify\n"); | 935 "You must specify a mode: --pack, --repack or --verify\n"); |
| 959 return PrintHelp(progname); | 936 return PrintHelp(progname); |
| 960 } | 937 } |
| 961 } | 938 } |
| OLD | NEW |