| OLD | NEW |
| 1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2011 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 * Routines for verifying a firmware image's signature. | 5 * Routines for verifying a firmware image's signature. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 | 9 |
| 10 #include "fmap.h" | 10 #include "fmap.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 * | 50 * |
| 51 * [base_of_rom] pointer to firmware image | 51 * [base_of_rom] pointer to firmware image |
| 52 * [fmap] pointer to Flash Map of firmware image | 52 * [fmap] pointer to Flash Map of firmware image |
| 53 * [gbb_size] GBB size will be stored here if GBB is found | 53 * [gbb_size] GBB size will be stored here if GBB is found |
| 54 */ | 54 */ |
| 55 void* GetFirmwareGBB(const void* base_of_rom, const void* fmap, | 55 void* GetFirmwareGBB(const void* base_of_rom, const void* fmap, |
| 56 uint64_t* gbb_size) { | 56 uint64_t* gbb_size) { |
| 57 const FmapHeader* fh = (const FmapHeader*) fmap; | 57 const FmapHeader* fh = (const FmapHeader*) fmap; |
| 58 const FmapAreaHeader* ah = (const FmapAreaHeader*) | 58 const FmapAreaHeader* ah = (const FmapAreaHeader*) |
| 59 (fmap + sizeof(FmapHeader)); | 59 (fmap + sizeof(FmapHeader)); |
| 60 int i = FmapAreaIndexOrError(fh, ah, "GBB Area"); | 60 int i = FmapAreaIndexOrError(fh, ah, "GBB"); |
| 61 | 61 |
| 62 if (i < 0) | 62 if (i < 0) |
| 63 return NULL; | 63 return NULL; |
| 64 | 64 |
| 65 *gbb_size = ah[i].area_size; | 65 *gbb_size = ah[i].area_size; |
| 66 return (void*)(base_of_rom + ah[i].area_offset); | 66 return (void*)(base_of_rom + ah[i].area_offset); |
| 67 } | 67 } |
| 68 | 68 |
| 69 /* Get verification block | 69 /* Get verification block |
| 70 * | 70 * |
| 71 * Return zero if succeed, or non-zero if failed | 71 * Return zero if succeed, or non-zero if failed |
| 72 * | 72 * |
| 73 * [base_of_rom] pointer to firmware image | 73 * [base_of_rom] pointer to firmware image |
| 74 * [fmap] pointer to Flash Map of firmware image | 74 * [fmap] pointer to Flash Map of firmware image |
| 75 * [index] index of verification block | 75 * [index] index of verification block |
| 76 * [verification_block_ptr] pointer to storing the found verification block | 76 * [verification_block_ptr] pointer to storing the found verification block |
| 77 * [verification_size_ptr] pointer to store the found verification block size | 77 * [verification_size_ptr] pointer to store the found verification block size |
| 78 */ | 78 */ |
| 79 int GetVerificationBlock(const void* base_of_rom, const void* fmap, int index, | 79 int GetVerificationBlock(const void* base_of_rom, const void* fmap, int index, |
| 80 void** verification_block_ptr, uint64_t* verification_size_ptr) { | 80 void** verification_block_ptr, uint64_t* verification_size_ptr) { |
| 81 const char* key_area_name[2] = { | 81 const char* key_area_name[2] = { |
| 82 "Firmware A Key", | 82 "VBLOCK_A", |
| 83 "Firmware B Key" | 83 "VBLOCK_B" |
| 84 }; | 84 }; |
| 85 const FmapHeader* fh = (const FmapHeader*) fmap; | 85 const FmapHeader* fh = (const FmapHeader*) fmap; |
| 86 const FmapAreaHeader* ah = (const FmapAreaHeader*) | 86 const FmapAreaHeader* ah = (const FmapAreaHeader*) |
| 87 (fmap + sizeof(FmapHeader)); | 87 (fmap + sizeof(FmapHeader)); |
| 88 int i = FmapAreaIndexOrError(fh, ah, key_area_name[index]); | 88 int i = FmapAreaIndexOrError(fh, ah, key_area_name[index]); |
| 89 const void* kb; | 89 const void* kb; |
| 90 const VbKeyBlockHeader* kbh; | 90 const VbKeyBlockHeader* kbh; |
| 91 const VbFirmwarePreambleHeader* fph; | 91 const VbFirmwarePreambleHeader* fph; |
| 92 | 92 |
| 93 if (i < 0) | 93 if (i < 0) |
| 94 return 1; | 94 return 1; |
| 95 | 95 |
| 96 kb = base_of_rom + ah[i].area_offset; | 96 kb = base_of_rom + ah[i].area_offset; |
| 97 *verification_block_ptr = (void*) kb; | 97 *verification_block_ptr = (void*) kb; |
| 98 | 98 |
| 99 kbh = (const VbKeyBlockHeader*) kb; | 99 kbh = (const VbKeyBlockHeader*) kb; |
| 100 fph = (const VbFirmwarePreambleHeader*) (kb + kbh->key_block_size); | 100 fph = (const VbFirmwarePreambleHeader*) (kb + kbh->key_block_size); |
| 101 | 101 |
| 102 *verification_size_ptr = kbh->key_block_size + fph->preamble_size; | 102 *verification_size_ptr = kbh->key_block_size + fph->preamble_size; |
| 103 | 103 |
| 104 return 0; | 104 return 0; |
| 105 } | 105 } |
| 106 | 106 |
| 107 /* Return non-zero if not found */ | 107 /* Return non-zero if not found */ |
| 108 int GetFirmwareData(const void* base_of_rom, const void* fmap, int index, | 108 int GetFirmwareData(const void* base_of_rom, const void* fmap, int index, |
| 109 void *verification_block, uint8_t** body_ptr, uint64_t *size_ptr) { | 109 void *verification_block, uint8_t** body_ptr, uint64_t *size_ptr) { |
| 110 const char* data_area_name[2] = { | 110 const char* data_area_name[2] = { |
| 111 "Firmware A Data", | 111 "FW_MAIN_A", |
| 112 "Firmware B Data" | 112 "FW_MAIN_B" |
| 113 }; | 113 }; |
| 114 const FmapHeader* fh = (const FmapHeader*) fmap; | 114 const FmapHeader* fh = (const FmapHeader*) fmap; |
| 115 const FmapAreaHeader* ah = (const FmapAreaHeader*) | 115 const FmapAreaHeader* ah = (const FmapAreaHeader*) |
| 116 (fmap + sizeof(FmapHeader)); | 116 (fmap + sizeof(FmapHeader)); |
| 117 const VbKeyBlockHeader* kbh = (const VbKeyBlockHeader*) verification_block; | 117 const VbKeyBlockHeader* kbh = (const VbKeyBlockHeader*) verification_block; |
| 118 const VbFirmwarePreambleHeader* fph = (const VbFirmwarePreambleHeader*) | 118 const VbFirmwarePreambleHeader* fph = (const VbFirmwarePreambleHeader*) |
| 119 (verification_block + kbh->key_block_size); | 119 (verification_block + kbh->key_block_size); |
| 120 int i = FmapAreaIndexOrError(fh, ah, data_area_name[index]); | 120 int i = FmapAreaIndexOrError(fh, ah, data_area_name[index]); |
| 121 | 121 |
| 122 if (i < 0) | 122 if (i < 0) |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 printf("opened %s\n", image_path); | 252 printf("opened %s\n", image_path); |
| 253 | 253 |
| 254 fmap = FmapFind((char*) base_of_rom, rom_size); | 254 fmap = FmapFind((char*) base_of_rom, rom_size); |
| 255 | 255 |
| 256 retval = DriveLoadFirmware(base_of_rom, fmap); | 256 retval = DriveLoadFirmware(base_of_rom, fmap); |
| 257 | 257 |
| 258 Free((void*) base_of_rom); | 258 Free((void*) base_of_rom); |
| 259 | 259 |
| 260 return retval; | 260 return retval; |
| 261 } | 261 } |
| OLD | NEW |