| 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 * TEMPORARY stub for calling LoadFirmware() which looks like the old | 5 * TEMPORARY stub for calling LoadFirmware() which looks like the old |
| 6 * VerifyFirmwareDriver_f() call. | 6 * VerifyFirmwareDriver_f() call. |
| 7 * (Firmware portion) | 7 * (Firmware portion) |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 #include "load_firmware_fw.h" | 10 #include "load_firmware_fw.h" |
| 11 | 11 |
| 12 #include "firmware_image_fw.h" | 12 #include "firmware_image_fw.h" |
| 13 #include "utility.h" | 13 #include "utility.h" |
| 14 | 14 |
| 15 typedef struct CallerInternal { |
| 16 uint8_t *firmwareA; |
| 17 uint64_t firmwareA_size; |
| 18 uint8_t *firmwareB; |
| 19 uint64_t firmwareB_size; |
| 20 } CallerInternal; |
| 15 | 21 |
| 16 static uint8_t *g_firmwareA; | 22 int GetFirmwareBody(LoadFirmwareParams* params, uint64_t index) { |
| 17 static uint64_t g_firmwareA_size; | |
| 18 static uint8_t *g_firmwareB; | |
| 19 static uint64_t g_firmwareB_size; | |
| 20 | 23 |
| 21 | 24 CallerInternal* ci = (CallerInternal*)params->caller_internal; |
| 22 void *GetFirmwareBody(uint64_t firmware_index, uint64_t* size) { | |
| 23 | |
| 24 uint8_t *fw; | 25 uint8_t *fw; |
| 26 uint64_t size; |
| 25 | 27 |
| 26 /* In a real implementation, GetFirmwareBody() should be what reads | 28 /* In a real implementation, GetFirmwareBody() should be what reads |
| 27 * and decompresses the firmware volume. In this temporary hack, we | 29 * and decompresses the firmware volume. In this temporary hack, we |
| 28 * just pass the pointer which we got from | 30 * just pass the pointer which we got from |
| 29 * VerifyFirmwareDriver_Stub(). */ | 31 * VerifyFirmwareDriver_Stub(). */ |
| 30 switch(firmware_index) { | 32 switch(index) { |
| 31 case 0: | 33 case 0: |
| 32 *size = g_firmwareA_size; | 34 size = ci->firmwareA_size; |
| 33 fw = g_firmwareA; | 35 fw = ci->firmwareA; |
| 34 case 1: | 36 case 1: |
| 35 *size = g_firmwareB_size; | 37 size = ci->firmwareB_size; |
| 36 fw = g_firmwareB; | 38 fw = ci->firmwareB; |
| 37 default: | 39 default: |
| 38 /* Anything else is invalid */ | 40 /* Anything else is invalid */ |
| 39 *size = 0; | 41 return 1; |
| 40 return NULL; | |
| 41 } | 42 } |
| 42 | 43 |
| 43 /* Need to call UpdateFirmwareBodyHash() with the firmware volume | 44 /* Need to call UpdateFirmwareBodyHash() with the firmware volume |
| 44 * data. In this temporary hack, the FV is already decompressed, so | 45 * data. In this temporary hack, the FV is already decompressed, so |
| 45 * we pass in the entire volume at once. In a real implementation, | 46 * we pass in the entire volume at once. In a real implementation, |
| 46 * you should call this as the FV is being decompressed. */ | 47 * you should call this as the FV is being decompressed. */ |
| 47 UpdateFirmwareBodyHash(fw, *size); | 48 UpdateFirmwareBodyHash(params, fw, size); |
| 48 | 49 |
| 49 /* Return the firmware body pointer */ | 50 /* Success */ |
| 50 return fw; | 51 return 0; |
| 51 } | 52 } |
| 52 | 53 |
| 53 | 54 |
| 54 /* Where you're currently calling VerifyFirmwareDriver_f(), call this | 55 /* Where you're currently calling VerifyFirmwareDriver_f(), call this |
| 55 * function instead. Because you still need to read in both firmware | 56 * function instead. Because you still need to read in both firmware |
| 56 * volumes, this call will still be slow. Once we reach feature | 57 * volumes, this call will still be slow. Once we reach feature |
| 57 * complete, you should modify your code to call LoadImage() | 58 * complete, you should modify your code to call LoadImage() |
| 58 * directly. */ | 59 * directly. */ |
| 59 int VerifyFirmwareDriver_stub(uint8_t* root_key_blob, | 60 int VerifyFirmwareDriver_stub(uint8_t* root_key_blob, |
| 60 uint8_t* verification_headerA, | 61 uint8_t* verification_headerA, |
| 61 uint8_t* firmwareA, | 62 uint8_t* firmwareA, |
| 62 uint8_t* verification_headerB, | 63 uint8_t* verification_headerB, |
| 63 uint8_t* firmwareB) { | 64 uint8_t* firmwareB) { |
| 64 | 65 |
| 65 int rv; | 66 int rv; |
| 66 | 67 |
| 68 CallerInternal ci; |
| 69 |
| 67 /* Copy the firmware volume pointers to our global variables. */ | 70 /* Copy the firmware volume pointers to our global variables. */ |
| 68 g_firmwareA = firmwareA; | 71 ci.firmwareA = firmwareA; |
| 69 g_firmwareB = firmwareB; | 72 ci.firmwareB = firmwareB; |
| 70 | 73 |
| 71 /* TODO: YOU NEED TO PASS IN THE FIRMWARE VOLUME SIZES SOMEHOW */ | 74 /* TODO: YOU NEED TO PASS IN THE FIRMWARE VOLUME SIZES SOMEHOW */ |
| 72 g_firmwareA_size = 0; | 75 ci.firmwareA_size = 0; |
| 73 g_firmwareB_size = 0; | 76 ci.firmwareB_size = 0; |
| 74 | 77 |
| 75 /* Set up the params for LoadFirmware() */ | 78 /* Set up the params for LoadFirmware() */ |
| 76 LoadFirmwareParams p; | 79 LoadFirmwareParams p; |
| 80 p.caller_internal = &ci; |
| 77 p.firmware_root_key_blob = root_key_blob; | 81 p.firmware_root_key_blob = root_key_blob; |
| 78 p.verification_block_0 = verification_headerA; | 82 p.verification_block_0 = verification_headerA; |
| 79 p.verification_block_1 = verification_headerB; | 83 p.verification_block_1 = verification_headerB; |
| 80 | 84 |
| 85 /* Allocate a key blob buffer */ |
| 86 p.kernel_sign_key_blob = Malloc(LOAD_FIRMWARE_KEY_BLOB_MAX); |
| 87 p.kernel_sign_key_size = LOAD_FIRMWARE_KEY_BLOB_MAX; |
| 88 |
| 81 /* Call LoadFirmware() */ | 89 /* Call LoadFirmware() */ |
| 82 rv = LoadFirmware(&p); | 90 rv = LoadFirmware(&p); |
| 83 if (LOAD_FIRMWARE_SUCCESS == rv) { | 91 if (LOAD_FIRMWARE_SUCCESS == rv) { |
| 84 /* TODO: YOU NEED TO KEEP TRACK OF p.kernel_sign_key_blob AND | 92 /* TODO: YOU NEED TO KEEP TRACK OF p.kernel_sign_key_blob AND |
| 85 * p.kernel_sign_key_size SO YOU CAN PASS THEM TO LoadKernel(). */ | 93 * p.kernel_sign_key_size SO YOU CAN PASS THEM TO LoadKernel(). */ |
| 86 | 94 |
| 87 return (0 == p.firmware_index ? BOOT_FIRMWARE_A_CONTINUE : | 95 return (0 == p.firmware_index ? BOOT_FIRMWARE_A_CONTINUE : |
| 88 BOOT_FIRMWARE_B_CONTINUE); | 96 BOOT_FIRMWARE_B_CONTINUE); |
| 89 | 97 |
| 90 } else { | 98 } else { |
| 91 /* Error */ | 99 /* Error */ |
| 92 return BOOT_FIRMWARE_RECOVERY_CONTINUE; | 100 return BOOT_FIRMWARE_RECOVERY_CONTINUE; |
| 93 } | 101 } |
| 94 } | 102 } |
| OLD | NEW |