jonzhang@fb.com has uploaded this change for review.

View Change

drivers/vpd: Set bool type variable matching with key/value pair

Summary:
Give a key/value pair in VPD binary blob, and name of a bool
type variable, set the variable value if there is a match.

Several checks are in place:
* The key/value length needs to be correct.
* The key name needs to match.
* THe value is either '1' or '0'.

Test Plan:
* Build an OCP MonoLake coreboot image, flash and run.

Reviewers: dhendrix, hpe, anpetrov

Subscribers:

Tasks:

Tags:
Signed-off-by: Jonathan Zhang <jonzhang@fb.com>
Change-Id: Iebdba59419a555147fc40391cf17cc6879d9e1b2
---
M src/drivers/vpd/Makefile.inc
A src/drivers/vpd/vpd_fsp.c
A src/drivers/vpd/vpd_fsp.h
3 files changed, 77 insertions(+), 1 deletion(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/34/34634/1
diff --git a/src/drivers/vpd/Makefile.inc b/src/drivers/vpd/Makefile.inc
index 17019b5..368024b 100644
--- a/src/drivers/vpd/Makefile.inc
+++ b/src/drivers/vpd/Makefile.inc
@@ -1,2 +1,2 @@
-romstage-$(CONFIG_VPD) += vpd_decode.c
+romstage-$(CONFIG_VPD) += vpd_decode.c vpd_fsp.c
ramstage-$(CONFIG_VPD) += vpd.c vpd_decode.c
diff --git a/src/drivers/vpd/vpd_fsp.c b/src/drivers/vpd/vpd_fsp.c
new file mode 100644
index 0000000..adff8e9
--- /dev/null
+++ b/src/drivers/vpd/vpd_fsp.c
@@ -0,0 +1,44 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (c) 2019 The coreboot Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ */
+#include <string.h>
+#include "vpd_fsp.h"
+
+/*
+ * Process UPD variable of boolean type.
+ * Match the variable name with key name in the key/value pair,
+ * use the value to set *val.
+ * During the process, necessary checking is done, such as making
+ * sure the value length is 1, and value is either '1' or '0'.
+ */
+bool set_upd_bool(const char *upd_var,
+ const uint8_t *key, const int32_t key_len,
+ const uint8_t *value, const int32_t value_len,
+ uint8_t *val)
+{
+ int i;
+ /* Check key length and value length */
+ if (key_len != strlen(upd_var) || value_len != 1)
+ return false;
+
+ /* Matching key with variable name */
+ for (i = 0; i < key_len; i++) {
+ if (key[i] != upd_var[i])
+ return false;
+ }
+
+ /* Make sure the value is either '1' or '0' */
+ if (*value == '1') {
+ *val = 1;
+ return true;
+ } else if (*value == '0') {
+ *val = 0;
+ return true;
+ } else
+ return false;
+}
diff --git a/src/drivers/vpd/vpd_fsp.h b/src/drivers/vpd/vpd_fsp.h
new file mode 100644
index 0000000..c59f249
--- /dev/null
+++ b/src/drivers/vpd/vpd_fsp.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (c) 2019 The coreboot Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ */
+
+#ifndef __VPD_FSP__
+#define __VPD_FSP__
+
+#include <inttypes.h>
+
+#define GOOGLE_VPD_2_0_OFFSET 0x600
+
+/*
+ * Process UPD variable of boolean type.
+ *
+ * Match the variable name with key name in the key/value pair,
+ * use the value to set *val.
+ * During the process, necessary checking is done, such as making
+ * sure the value length is 1, and value is either '1' or '0'.
+ *
+ * If there is a match and checking is successful, set *val
+ * accordingly, and return true; otherwise return false.
+ */
+bool set_upd_bool(const char *upd_var,
+ const uint8_t *key, const int32_t key_len,
+ const uint8_t *value, const int32_t value_len,
+ uint8_t *val);
+#endif /* __VPD_FSP__ */

To view, visit change 34634. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Iebdba59419a555147fc40391cf17cc6879d9e1b2
Gerrit-Change-Number: 34634
Gerrit-PatchSet: 1
Gerrit-Owner: jonzhang@fb.com
Gerrit-MessageType: newchange