Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1904)

Unified Diff: vboot_firmware/stub/load_firmware_stub.c

Issue 2848006: Refactor LoadFrmware() to avoid global variables, which don't work when running out of ROM (Closed) Base URL: ssh://gitrw.chromium.org/vboot_reference.git
Patch Set: Undo change to vboot_struct Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « vboot_firmware/linktest/main.c ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vboot_firmware/stub/load_firmware_stub.c
diff --git a/vboot_firmware/stub/load_firmware_stub.c b/vboot_firmware/stub/load_firmware_stub.c
index dea7f304f852ce9ec9fbb528c8865e1b2740eba6..5bca57dac2fe661fd1738a6b5b131b66e49165af 100644
--- a/vboot_firmware/stub/load_firmware_stub.c
+++ b/vboot_firmware/stub/load_firmware_stub.c
@@ -12,42 +12,43 @@
#include "firmware_image_fw.h"
#include "utility.h"
+typedef struct CallerInternal {
+ uint8_t *firmwareA;
+ uint64_t firmwareA_size;
+ uint8_t *firmwareB;
+ uint64_t firmwareB_size;
+} CallerInternal;
-static uint8_t *g_firmwareA;
-static uint64_t g_firmwareA_size;
-static uint8_t *g_firmwareB;
-static uint64_t g_firmwareB_size;
-
-
-void *GetFirmwareBody(uint64_t firmware_index, uint64_t* size) {
+int GetFirmwareBody(LoadFirmwareParams* params, uint64_t index) {
+ CallerInternal* ci = (CallerInternal*)params->caller_internal;
uint8_t *fw;
+ uint64_t size;
/* In a real implementation, GetFirmwareBody() should be what reads
* and decompresses the firmware volume. In this temporary hack, we
* just pass the pointer which we got from
* VerifyFirmwareDriver_Stub(). */
- switch(firmware_index) {
+ switch(index) {
case 0:
- *size = g_firmwareA_size;
- fw = g_firmwareA;
+ size = ci->firmwareA_size;
+ fw = ci->firmwareA;
case 1:
- *size = g_firmwareB_size;
- fw = g_firmwareB;
+ size = ci->firmwareB_size;
+ fw = ci->firmwareB;
default:
/* Anything else is invalid */
- *size = 0;
- return NULL;
+ return 1;
}
/* Need to call UpdateFirmwareBodyHash() with the firmware volume
* data. In this temporary hack, the FV is already decompressed, so
* we pass in the entire volume at once. In a real implementation,
* you should call this as the FV is being decompressed. */
- UpdateFirmwareBodyHash(fw, *size);
+ UpdateFirmwareBodyHash(params, fw, size);
- /* Return the firmware body pointer */
- return fw;
+ /* Success */
+ return 0;
}
@@ -64,20 +65,27 @@ int VerifyFirmwareDriver_stub(uint8_t* root_key_blob,
int rv;
+ CallerInternal ci;
+
/* Copy the firmware volume pointers to our global variables. */
- g_firmwareA = firmwareA;
- g_firmwareB = firmwareB;
+ ci.firmwareA = firmwareA;
+ ci.firmwareB = firmwareB;
/* TODO: YOU NEED TO PASS IN THE FIRMWARE VOLUME SIZES SOMEHOW */
- g_firmwareA_size = 0;
- g_firmwareB_size = 0;
+ ci.firmwareA_size = 0;
+ ci.firmwareB_size = 0;
/* Set up the params for LoadFirmware() */
LoadFirmwareParams p;
+ p.caller_internal = &ci;
p.firmware_root_key_blob = root_key_blob;
p.verification_block_0 = verification_headerA;
p.verification_block_1 = verification_headerB;
+ /* Allocate a key blob buffer */
+ p.kernel_sign_key_blob = Malloc(LOAD_FIRMWARE_KEY_BLOB_MAX);
+ p.kernel_sign_key_size = LOAD_FIRMWARE_KEY_BLOB_MAX;
+
/* Call LoadFirmware() */
rv = LoadFirmware(&p);
if (LOAD_FIRMWARE_SUCCESS == rv) {
« no previous file with comments | « vboot_firmware/linktest/main.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698