vboot2: use offset to vboot2 work buffer instead of absolute address

this change makes vb2_working_data struct point to the vboot work buffer by
the offset instead of by the absolute address, which can be different
depending on the context (e.g. subprocessor v.s. main cpu).

BUG=none
BRANCH=tot
TEST=booted veyron pinky

Change-Id: I2191ca756c4f49441b3a357338f9c84564b58918
Signed-off-by: Stefan Reinauer <reinauer@chromium.org>
Original-Commit-Id: 93f8b1da2b2c81aa3a33892987a71e9e1e7a8eff
Original-Change-Id: I4e4c12613304586b7395c5173cf08b8093f59521
Original-Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/236583
Original-Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: http://review.coreboot.org/9588
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
diff --git a/src/vendorcode/google/chromeos/vboot2/common.c b/src/vendorcode/google/chromeos/vboot2/common.c
index 178e8b5..caed89f 100644
--- a/src/vendorcode/google/chromeos/vboot2/common.c
+++ b/src/vendorcode/google/chromeos/vboot2/common.c
@@ -63,6 +63,11 @@
 	return (struct vb2_working_data *)_vboot2_work;
 }
 
+void *vboot_get_work_buffer(struct vb2_working_data *wd)
+{
+	return (void *)((uintptr_t)wd + wd->buffer_offset);
+}
+
 void vboot_reboot(void)
 {
 	hard_reset();
diff --git a/src/vendorcode/google/chromeos/vboot2/misc.h b/src/vendorcode/google/chromeos/vboot2/misc.h
index cae302b..b97be49 100644
--- a/src/vendorcode/google/chromeos/vboot2/misc.h
+++ b/src/vendorcode/google/chromeos/vboot2/misc.h
@@ -39,11 +39,13 @@
 struct vb2_working_data {
 	uint32_t selected_region_offset;
 	uint32_t selected_region_size;
-	uint64_t buffer_size;
-	uint64_t buffer;
+	/* offset of the buffer from the start of this struct */
+	uint32_t buffer_offset;
+	uint32_t buffer_size;
 };
 
 struct vb2_working_data * const vboot_get_working_data(void);
+void *vboot_get_work_buffer(struct vb2_working_data *wd);
 
 static inline void vb2_get_selected_region(struct vb2_working_data *wd,
 					   struct vboot_region *region)
diff --git a/src/vendorcode/google/chromeos/vboot2/vboot_handoff.c b/src/vendorcode/google/chromeos/vboot2/vboot_handoff.c
index 33ff79a..5df0d4a 100644
--- a/src/vendorcode/google/chromeos/vboot2/vboot_handoff.c
+++ b/src/vendorcode/google/chromeos/vboot2/vboot_handoff.c
@@ -152,7 +152,7 @@
 	struct vboot_region fw_main;
 	struct vb2_working_data *wd = vboot_get_working_data();
 
-	sd = (struct vb2_shared_data *)(uintptr_t)wd->buffer;
+	sd = vboot_get_work_buffer(wd);
 	sd->workbuf_hash_offset = 0;
 	sd->workbuf_hash_size = 0;
 
diff --git a/src/vendorcode/google/chromeos/vboot2/verstage.c b/src/vendorcode/google/chromeos/vboot2/verstage.c
index 42b0256..88c18f6 100644
--- a/src/vendorcode/google/chromeos/vboot2/verstage.c
+++ b/src/vendorcode/google/chromeos/vboot2/verstage.c
@@ -179,7 +179,7 @@
 
 	/* Set up context and work buffer */
 	memset(&ctx, 0, sizeof(ctx));
-	ctx.workbuf = (uint8_t *)(uintptr_t)wd->buffer;
+	ctx.workbuf = vboot_get_work_buffer(wd);
 	ctx.workbuf_size = wd->buffer_size;
 
 	/* Read nvdata from a non-volatile storage */
diff --git a/src/vendorcode/google/chromeos/vboot2/verstub.c b/src/vendorcode/google/chromeos/vboot2/verstub.c
index e8faa07..8f2e9b2 100644
--- a/src/vendorcode/google/chromeos/vboot2/verstub.c
+++ b/src/vendorcode/google/chromeos/vboot2/verstub.c
@@ -32,9 +32,8 @@
 	wd = vboot_get_working_data();
 	memset(wd, 0, _vboot2_work_size);
 	/* 8-byte alignment for ARMv7 */
-	wd->buffer = ALIGN_UP((uintptr_t)&wd[1], 8);
-	wd->buffer_size = _vboot2_work_size + (uintptr_t)wd
-			- (uintptr_t)wd->buffer;
+	wd->buffer_offset = ALIGN_UP(sizeof(*wd), 8);
+	wd->buffer_size = _vboot2_work_size - wd->buffer_offset;
 
 	return wd;
 }