| 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 | 5 |
| 6 /* Routines for verifying a file's signature. Useful in testing the core | 6 /* Routines for verifying a file's signature. Useful in testing the core |
| 7 * RSA verification implementation. | 7 * RSA verification implementation. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 #include <inttypes.h> /* For PRIu64 macro */ | 10 #include <inttypes.h> /* For PRIu64 macro */ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 int main(int argc, char* argv[]) { | 75 int main(int argc, char* argv[]) { |
| 76 | 76 |
| 77 const char* image_name; | 77 const char* image_name; |
| 78 const char* keyfile_name; | 78 const char* keyfile_name; |
| 79 int rv; | 79 int rv; |
| 80 | 80 |
| 81 Memset(&lkp, 0, sizeof(LoadKernelParams)); | 81 Memset(&lkp, 0, sizeof(LoadKernelParams)); |
| 82 lkp.bytes_per_lba = LBA_BYTES; | 82 lkp.bytes_per_lba = LBA_BYTES; |
| 83 | 83 |
| 84 /* Read command line parameters */ | 84 /* Read command line parameters */ |
| 85 if (3 > argc) { | 85 if (4 > argc) { |
| 86 fprintf(stderr, "usage: %s <drive_image> <sign_key>\n", argv[0]); | 86 fprintf(stderr, "usage: %s <drive_image> <sign_key> [boot flag]\n", argv[0])
; |
| 87 return 1; | 87 return 1; |
| 88 } | 88 } |
| 89 image_name = argv[1]; | 89 image_name = argv[1]; |
| 90 keyfile_name = argv[2]; | 90 keyfile_name = argv[2]; |
| 91 | 91 |
| 92 /* Read header signing key blob */ | 92 /* Read header signing key blob */ |
| 93 { | 93 { |
| 94 uint64_t key_size; | 94 uint64_t key_size; |
| 95 lkp.header_sign_key_blob = ReadFile(keyfile_name, &key_size); | 95 lkp.header_sign_key_blob = ReadFile(keyfile_name, &key_size); |
| 96 if (!lkp.header_sign_key_blob) { | 96 if (!lkp.header_sign_key_blob) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 111 rewind(image_file); | 111 rewind(image_file); |
| 112 printf("Ending LBA: %" PRIu64 "\n", lkp.ending_lba); | 112 printf("Ending LBA: %" PRIu64 "\n", lkp.ending_lba); |
| 113 | 113 |
| 114 /* Allocate a buffer for the kernel */ | 114 /* Allocate a buffer for the kernel */ |
| 115 lkp.kernel_buffer = Malloc(KERNEL_BUFFER_SIZE); | 115 lkp.kernel_buffer = Malloc(KERNEL_BUFFER_SIZE); |
| 116 if(!lkp.kernel_buffer) { | 116 if(!lkp.kernel_buffer) { |
| 117 fprintf(stderr, "Unable to allocate kernel buffer.\n"); | 117 fprintf(stderr, "Unable to allocate kernel buffer.\n"); |
| 118 return 1; | 118 return 1; |
| 119 } | 119 } |
| 120 | 120 |
| 121 /* TODO: Option for boot mode - developer, recovery */ | |
| 122 /* Need to skip the address check, since we're putting it somewhere on the | 121 /* Need to skip the address check, since we're putting it somewhere on the |
| 123 * heap instead of its actual target address in the firmware. */ | 122 * heap instead of its actual target address in the firmware. */ |
| 124 lkp.boot_flags = BOOT_FLAG_SKIP_ADDR_CHECK | BOOT_FLAG_RECOVERY; | 123 if (argc == 4) { |
| 125 | 124 lkp.boot_flags = atoi(argv[3]) | BOOT_FLAG_SKIP_ADDR_CHECK; |
| 125 } else { |
| 126 /* Default to recovery. */ |
| 127 lkp.boot_flags = BOOT_FLAG_SKIP_ADDR_CHECK | BOOT_FLAG_RECOVERY; |
| 128 } |
| 126 /* Call LoadKernel() */ | 129 /* Call LoadKernel() */ |
| 127 rv = LoadKernel(&lkp); | 130 rv = LoadKernel(&lkp); |
| 128 printf("LoadKernel() returned %d\n", rv); | 131 printf("LoadKernel() returned %d\n", rv); |
| 129 | 132 |
| 130 if (LOAD_KERNEL_SUCCESS == rv) { | 133 if (LOAD_KERNEL_SUCCESS == rv) { |
| 131 printf("Partition number: %" PRIu64 "\n", lkp.partition_number); | 134 printf("Partition number: %" PRIu64 "\n", lkp.partition_number); |
| 132 printf("Bootloader address: %" PRIu64 "\n", lkp.bootloader_address); | 135 printf("Bootloader address: %" PRIu64 "\n", lkp.bootloader_address); |
| 133 printf("Bootloader size: %" PRIu64 "\n", lkp.bootloader_size); | 136 printf("Bootloader size: %" PRIu64 "\n", lkp.bootloader_size); |
| 134 } | 137 } |
| 135 | 138 |
| 136 fclose(image_file); | 139 fclose(image_file); |
| 137 Free(lkp.kernel_buffer); | 140 Free(lkp.kernel_buffer); |
| 138 return rv != LOAD_KERNEL_SUCCESS; | 141 return rv != LOAD_KERNEL_SUCCESS; |
| 139 } | 142 } |
| OLD | NEW |