Patrick Rudolph has uploaded this change for review.

View Change

option: Add API for mainboard provided options

This API can be implemented by mainboards providing a custom option storage.
For example an external I2C EEPROM, IPMI on BMC, ...

Update documentation accordingly.

Change-Id: Ic5bbb5b3353d862c5533f90ced4824eec27ca3b9
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
M Documentation/index.md
A Documentation/lib/option.md
M src/Kconfig
M src/include/option.h
4 files changed, 48 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/01/52601/1
diff --git a/Documentation/index.md b/Documentation/index.md
index 9870cf3..b4a42cd 100644
--- a/Documentation/index.md
+++ b/Documentation/index.md
@@ -182,6 +182,7 @@
* [System on Chip](soc/index.md)
* [Mainboard](mainboard/index.md)
* [Payloads](lib/payloads/index.md)
+* [Options](lib/option.md)
* [Libraries](lib/index.md)
* [Security](security/index.md)
* [SuperIO](superio/index.md)
diff --git a/Documentation/lib/option.md b/Documentation/lib/option.md
new file mode 100644
index 0000000..c65728f
--- /dev/null
+++ b/Documentation/lib/option.md
@@ -0,0 +1,30 @@
+# Option framework
+
+The option framework around `set_option(const char *name, void *val)` and
+`get_option(void *dest, const char *name)` was deprecated in favour of a
+typesafe API.
+
+Historically the option framework used the persistent NVRAM backed by the
+RTC battery on PC platforms. On todays platforms options are usually
+stored in the firmware flash as well.
+
+The new typesafe option framework can be used by calling
+`enum cb_err set_int_option(const char *name, int value)` and
+`int get_int_option(const char *name, const int fallback)`.
+
+# Mainboard option framework
+
+Mainboards that do not use NVRAM, but a vendor specific method, to store
+firmware settings must select `USE_MAINBOARD_OPTION_TABLE`.
+
+In addition it must implement the following methods:
+
+```
+enum cb_err mainboard_set_option(const char *name, const void *val, const size_t size);
+enum cb_err mainboard_get_option(const char *name, void *dest, size_t *size_in_out);
+```
+
+Possible vendor specific stores are:
+* BMC (configurable over IPMI or WebUI)
+* I2C EEPROM
+* ...
diff --git a/src/Kconfig b/src/Kconfig
index fe325e8..8566a56 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -127,6 +127,12 @@
Enable this option if coreboot shall read options from the "CMOS"
NVRAM instead of using hard-coded values.

+config USE_MAINBOARD_OPTION_TABLE
+ bool
+ help
+ Selected by mainboards that provide a custom interface to read and
+ write options, for example an EEPROM or BMC interface.
+
config STATIC_OPTION_TABLE
bool "Load default configuration values into CMOS on each boot"
depends on USE_OPTION_TABLE
diff --git a/src/include/option.h b/src/include/option.h
index 4de032b..4bfd33a 100644
--- a/src/include/option.h
+++ b/src/include/option.h
@@ -10,10 +10,15 @@
enum cb_err cmos_set_option(const char *name, void *val);
enum cb_err cmos_get_option(void *dest, const char *name);

+enum cb_err mainboard_set_option(const char *name, const void *val, const size_t size);
+enum cb_err mainboard_get_option(const char *name, void *dest, size_t *size_in_out);
+
static inline enum cb_err set_int_option(const char *name, int value)
{
if (CONFIG(USE_OPTION_TABLE))
return cmos_set_option(name, &value);
+ else if (CONFIG(USE_MAINBOARD_OPTION_TABLE))
+ return mainboard_set_option(name, &value, sizeof(value));

return CB_CMOS_OTABLE_DISABLED;
}
@@ -24,7 +29,13 @@
int value = 0;
if (cmos_get_option(&value, name) == CB_SUCCESS)
return value;
+ } else if (CONFIG(USE_MAINBOARD_OPTION_TABLE)) {
+ int value = 0;
+ size_t size = sizeof(value);
+ if (mainboard_get_option(name, &value, &size) == CB_SUCCESS)
+ return value;
}
+
return fallback;
}


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

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ic5bbb5b3353d862c5533f90ced4824eec27ca3b9
Gerrit-Change-Number: 52601
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <patrick.rudolph@9elements.com>
Gerrit-MessageType: newchange