| 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 26 matching lines...) Expand all Loading... |
| 37 if (firmware_index != 0 && firmware_index != 1) | 37 if (firmware_index != 0 && firmware_index != 1) |
| 38 return 1; | 38 return 1; |
| 39 | 39 |
| 40 UpdateFirmwareBodyHash(params, | 40 UpdateFirmwareBodyHash(params, |
| 41 ci->firmware[firmware_index].fw, | 41 ci->firmware[firmware_index].fw, |
| 42 ci->firmware[firmware_index].size); | 42 ci->firmware[firmware_index].size); |
| 43 | 43 |
| 44 return 0; | 44 return 0; |
| 45 } | 45 } |
| 46 | 46 |
| 47 /* Get firmware root key | 47 /* Get GBB |
| 48 * | 48 * |
| 49 * Return pointer to firmware root key of firmware image, or NULL if not found | 49 * Return pointer to GBB from firmware image, or NULL if not found. |
| 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 */ | 54 */ |
| 54 void* GetFirmwareRootKey(const void* base_of_rom, const void* fmap) { | 55 void* GetFirmwareGBB(const void* base_of_rom, const void* fmap, |
| 56 uint64_t* gbb_size) { |
| 55 const FmapHeader* fh = (const FmapHeader*) fmap; | 57 const FmapHeader* fh = (const FmapHeader*) fmap; |
| 56 const FmapAreaHeader* ah = (const FmapAreaHeader*) | 58 const FmapAreaHeader* ah = (const FmapAreaHeader*) |
| 57 (fmap + sizeof(FmapHeader)); | 59 (fmap + sizeof(FmapHeader)); |
| 58 int i = FmapAreaIndexOrError(fh, ah, "GBB Area"); | 60 int i = FmapAreaIndexOrError(fh, ah, "GBB Area"); |
| 59 const void* gbb; | |
| 60 const GoogleBinaryBlockHeader* gbbh; | |
| 61 | 61 |
| 62 if (i < 0) | 62 if (i < 0) |
| 63 return NULL; | 63 return NULL; |
| 64 | 64 |
| 65 gbb = base_of_rom + ah[i].area_offset; | 65 *gbb_size = ah[i].area_size; |
| 66 gbbh = (const GoogleBinaryBlockHeader*) gbb; | 66 return (void*)(base_of_rom + ah[i].area_offset); |
| 67 return (void*) gbb + gbbh->rootkey_offset; | |
| 68 } | 67 } |
| 69 | 68 |
| 70 /* Get verification block | 69 /* Get verification block |
| 71 * | 70 * |
| 72 * Return zero if succeed, or non-zero if failed | 71 * Return zero if succeed, or non-zero if failed |
| 73 * | 72 * |
| 74 * [base_of_rom] pointer to firmware image | 73 * [base_of_rom] pointer to firmware image |
| 75 * [fmap] pointer to Flash Map of firmware image | 74 * [fmap] pointer to Flash Map of firmware image |
| 76 * [index] index of verification block | 75 * [index] index of verification block |
| 77 * [verification_block_ptr] pointer to storing the found verification block | 76 * [verification_block_ptr] pointer to storing the found verification block |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 void** vblock_ptr[2] = { | 143 void** vblock_ptr[2] = { |
| 145 &lfp.verification_block_0, &lfp.verification_block_1 | 144 &lfp.verification_block_0, &lfp.verification_block_1 |
| 146 }; | 145 }; |
| 147 uint64_t* vsize_ptr[2] = { | 146 uint64_t* vsize_ptr[2] = { |
| 148 &lfp.verification_size_0, &lfp.verification_size_1 | 147 &lfp.verification_size_0, &lfp.verification_size_1 |
| 149 }; | 148 }; |
| 150 | 149 |
| 151 /* Initialize LoadFirmwareParams lfp */ | 150 /* Initialize LoadFirmwareParams lfp */ |
| 152 | 151 |
| 153 lfp.caller_internal = &ci; | 152 lfp.caller_internal = &ci; |
| 154 | 153 lfp.gbb_data = GetFirmwareGBB(base_of_rom, fmap, &lfp.gbb_size); |
| 155 lfp.firmware_root_key_blob = GetFirmwareRootKey(base_of_rom, fmap); | 154 if (!lfp.gbb_data) { |
| 156 if (!lfp.firmware_root_key_blob) { | 155 printf("ERROR: cannot get firmware GBB\n"); |
| 157 printf("ERROR: cannot get firmware root key blob\n"); | |
| 158 return 1; | 156 return 1; |
| 159 } | 157 } |
| 160 | 158 |
| 161 printf("firmware root key blob at 0x%08" PRIx64 "\n", | 159 printf("firmware GBB at 0x%08" PRIx64 "\n", |
| 162 (uint64_t) (lfp.firmware_root_key_blob - base_of_rom)); | 160 (uint64_t) (lfp.gbb_data - base_of_rom)); |
| 163 | 161 |
| 164 /* Loop to initialize firmware key and data A / B */ | 162 /* Loop to initialize firmware key and data A / B */ |
| 165 for (index = 0; index < 2; ++index) { | 163 for (index = 0; index < 2; ++index) { |
| 166 if (GetVerificationBlock(base_of_rom, fmap, index, | 164 if (GetVerificationBlock(base_of_rom, fmap, index, |
| 167 vblock_ptr[index], vsize_ptr[index])) { | 165 vblock_ptr[index], vsize_ptr[index])) { |
| 168 printf("ERROR: cannot get key block %d\n", index); | 166 printf("ERROR: cannot get key block %d\n", index); |
| 169 return 1; | 167 return 1; |
| 170 } | 168 } |
| 171 | 169 |
| 172 printf("verification block %d at 0x%08" PRIx64 "\n", index, | 170 printf("verification block %d at 0x%08" PRIx64 "\n", index, |
| 173 (uint64_t) (*vblock_ptr[index] - base_of_rom)); | 171 (uint64_t) (*vblock_ptr[index] - base_of_rom)); |
| 174 printf("verification block %d size is 0x%08" PRIx64 "\n", index, | 172 printf("verification block %d size is 0x%08" PRIx64 "\n", index, |
| 175 *vsize_ptr[index]); | 173 *vsize_ptr[index]); |
| 176 | 174 |
| 177 if (GetFirmwareData(base_of_rom, fmap, index, *vblock_ptr[index], | 175 if (GetFirmwareData(base_of_rom, fmap, index, *vblock_ptr[index], |
| 178 &(ci.firmware[index].fw), &(ci.firmware[index].size))) { | 176 &(ci.firmware[index].fw), &(ci.firmware[index].size))) { |
| 179 printf("ERROR: cannot get firmware body %d\n", index); | 177 printf("ERROR: cannot get firmware body %d\n", index); |
| 180 return 1; | 178 return 1; |
| 181 } | 179 } |
| 182 | 180 |
| 183 printf("firmware %c at 0x%08" PRIx64 "\n", "AB"[index], | 181 printf("firmware %c at 0x%08" PRIx64 "\n", "AB"[index], |
| 184 (uint64_t) ((void*) ci.firmware[index].fw - base_of_rom)); | 182 (uint64_t) ((void*) ci.firmware[index].fw - base_of_rom)); |
| 185 printf("firmware %c size is 0x%08" PRIx64 "\n", "AB"[index], | 183 printf("firmware %c size is 0x%08" PRIx64 "\n", "AB"[index], |
| 186 ci.firmware[index].size); | 184 ci.firmware[index].size); |
| 187 } | 185 } |
| 188 | 186 |
| 189 lfp.kernel_sign_key_blob = Malloc(LOAD_FIRMWARE_KEY_BLOB_REC_SIZE); | 187 lfp.shared_data_blob = Malloc(VB_SHARED_DATA_MIN_SIZE); |
| 190 lfp.kernel_sign_key_size = LOAD_FIRMWARE_KEY_BLOB_REC_SIZE; | 188 lfp.shared_data_size = VB_SHARED_DATA_MIN_SIZE; |
| 191 printf("kernel sign key size is 0x%08" PRIx64 "\n", lfp.kernel_sign_key_size); | 189 printf("shared data size 0x%08" PRIx64 "\n", lfp.shared_data_size); |
| 192 | 190 |
| 193 lfp.boot_flags = 0; | 191 lfp.boot_flags = 0; |
| 194 printf("boot flags is 0x%08" PRIx64 "\n", lfp.boot_flags); | 192 printf("boot flags is 0x%08" PRIx64 "\n", lfp.boot_flags); |
| 195 | 193 |
| 196 status = LoadFirmware(&lfp); | 194 status = LoadFirmware(&lfp); |
| 197 status_str = status_string(status); | 195 status_str = status_string(status); |
| 198 if (status_str) | 196 if (status_str) |
| 199 printf("LoadFirmware returns %s\n", status_str); | 197 printf("LoadFirmware returns %s\n", status_str); |
| 200 else | 198 else |
| 201 printf("LoadFirmware returns unknown status code: %d\n", status); | 199 printf("LoadFirmware returns unknown status code: %d\n", status); |
| 202 if (status == LOAD_FIRMWARE_SUCCESS) | 200 if (status == LOAD_FIRMWARE_SUCCESS) |
| 203 printf("firmwiare index is %" PRIu64 "\n", lfp.firmware_index); | 201 printf("firmwiare index is %" PRIu64 "\n", lfp.firmware_index); |
| 204 | 202 |
| 205 Free(lfp.kernel_sign_key_blob); | 203 Free(lfp.shared_data_blob); |
| 206 | 204 |
| 207 return 0; | 205 return 0; |
| 208 } | 206 } |
| 209 | 207 |
| 210 /* wrap FmapAreaIndex; print error when not found */ | 208 /* wrap FmapAreaIndex; print error when not found */ |
| 211 int FmapAreaIndexOrError(const FmapHeader* fh, const FmapAreaHeader* ah, | 209 int FmapAreaIndexOrError(const FmapHeader* fh, const FmapAreaHeader* ah, |
| 212 const char* name) { | 210 const char* name) { |
| 213 int i = FmapAreaIndex(fh, ah, name); | 211 int i = FmapAreaIndex(fh, ah, name); |
| 214 if (i < 0) | 212 if (i < 0) |
| 215 fprintf(stderr, "%s: can't find %s in firmware image\n", progname, name); | 213 fprintf(stderr, "%s: can't find %s in firmware image\n", progname, name); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 printf("opened %s\n", image_path); | 252 printf("opened %s\n", image_path); |
| 255 | 253 |
| 256 fmap = FmapFind((char*) base_of_rom, rom_size); | 254 fmap = FmapFind((char*) base_of_rom, rom_size); |
| 257 | 255 |
| 258 retval = DriveLoadFirmware(base_of_rom, fmap); | 256 retval = DriveLoadFirmware(base_of_rom, fmap); |
| 259 | 257 |
| 260 Free((void*) base_of_rom); | 258 Free((void*) base_of_rom); |
| 261 | 259 |
| 262 return retval; | 260 return retval; |
| 263 } | 261 } |
| OLD | NEW |