vboot: Add vb2api_secdata_fwmp_create()

This commit adds a method to create an empty Firmware Management
Parameters (FWMP) object in secure storage context.  This can be used
to initialize the FWMP space just after it's been created by
firmware.

BUG=b:184677625
BRANCH=None
TEST=With other changes in coreboot to create and write the FWMP
space, `emerge-keeby coreboot`.

Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Change-Id: I614975609a44ec18ff018970056e6e45e68265ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2875533
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Auto-Submit: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
diff --git a/firmware/2lib/2secdata_fwmp.c b/firmware/2lib/2secdata_fwmp.c
index a28b5bb..cec2481 100644
--- a/firmware/2lib/2secdata_fwmp.c
+++ b/firmware/2lib/2secdata_fwmp.c
@@ -60,6 +60,25 @@
 	return VB2_SUCCESS;
 }
 
+uint32_t vb2api_secdata_fwmp_create(struct vb2_context *ctx)
+{
+	struct vb2_secdata_fwmp *sec = (void *)&ctx->secdata_fwmp;
+
+	/* Clear the entire struct */
+	memset(sec, 0, sizeof(*sec));
+
+	/* Set to current version */
+	sec->struct_version = VB2_SECDATA_FWMP_VERSION;
+
+	/* Set the structure size */
+	sec->struct_size = sizeof(*sec);
+
+	/* Calculate initial CRC */
+	sec->crc8 = vb2_secdata_fwmp_crc(sec);
+
+	return sizeof(*sec);
+}
+
 vb2_error_t vb2_secdata_fwmp_init(struct vb2_context *ctx)
 {
 	struct vb2_shared_data *sd = vb2_get_sd(ctx);
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index bd3b05f..fb8bc51 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -578,6 +578,15 @@
 uint32_t vb2api_secdata_kernel_create_v0(struct vb2_context *ctx);
 
 /**
+ * Create an empty Firmware Management Parameters (FWMP) in secure storage
+ * context.
+ *
+ * @param ctx		Context pointer
+ * @return size of created FWMP secure storage data in bytes
+ */
+uint32_t vb2api_secdata_fwmp_create(struct vb2_context *ctx);
+
+/**
  * Check the validity of firmware management parameters (FWMP) space.
  *
  * Checks size, version, and CRC.  If the struct size is larger than the size