aboutsummaryrefslogtreecommitdiff
path: root/core/nvram-format.c
diff options
context:
space:
mode:
authorOliver O'Halloran <oohall@gmail.com>2016-08-17 15:32:51 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-08-30 16:59:47 +1000
commit9070ae9817ccca570a1c80132c92374f57aa62ac (patch)
tree35aa576b293e9fe07c8857fdb0028ad8fe0087fb /core/nvram-format.c
parente9833175edd7a5a63841bd6c7e8e63c50604e480 (diff)
downloadskiboot-9070ae9817ccca570a1c80132c92374f57aa62ac.zip
skiboot-9070ae9817ccca570a1c80132c92374f57aa62ac.tar.gz
skiboot-9070ae9817ccca570a1c80132c92374f57aa62ac.tar.bz2
core/nvram: add support for skiboot config strings
This allows the ibm,skiboot partition to be used to store NUL terminated key=value OF configuration strings. These strings can be written using the nvram utility found in the linux powerpc-utils package. Currently the only use case for this is passing command line arguments to the boot kernel so only ASCII strings are supported. The 0xFF binary escaping mechanism for configuration strings is not supported. Signed-off-by: Oliver O'Halloran <oohall@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'core/nvram-format.c')
-rw-r--r--core/nvram-format.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/core/nvram-format.c b/core/nvram-format.c
index 5d15a60..227147e 100644
--- a/core/nvram-format.c
+++ b/core/nvram-format.c
@@ -179,3 +179,71 @@ int nvram_check(void *nvram_image, const uint32_t nvram_size)
failed:
return -1;
}
+
+static const char *find_next_key(const char *start, const char *end)
+{
+ /*
+ * Unused parts of the partition are set to NUL. If we hit two
+ * NULs in a row then we assume that we have hit the end of the
+ * partition.
+ */
+ if (*start == 0)
+ return NULL;
+
+ while (start < end) {
+ if (*start == 0)
+ return start + 1;
+
+ start++;
+ }
+
+ return NULL;
+}
+
+/*
+ * nvram_query() - Searches skiboot NVRAM partition for a key=value pair.
+ *
+ * Returns a pointer to a NUL terminated string that contains the value
+ * associated with the given key.
+ */
+const char *nvram_query(const char *key)
+{
+ const char *part_end = (const char *) skiboot_part_hdr +
+ skiboot_part_hdr->len * 16 - 1;
+ const char *start = (const char *) skiboot_part_hdr +
+ sizeof(*skiboot_part_hdr);
+ int key_len = strlen(key);
+
+ if (!key_len) {
+ prlog(PR_WARNING, "NVRAM: search key is empty!\n");
+ return NULL;
+ }
+
+ if (key_len > 32)
+ prlog(PR_WARNING, "NVRAM: search key '%s' is longer than 32 chars\n", key);
+
+ while (start) {
+ int remaining = part_end - start;
+
+ prlog(PR_TRACE, "NVRAM: '%s' (%lu)\n",
+ start, strlen(start));
+
+ if (key_len + 1 > remaining)
+ return NULL;
+
+ if (!strncmp(key, start, key_len) && start[key_len] == '=') {
+ const char *value = &start[key_len + 1];
+
+ prlog(PR_DEBUG, "NVRAM: Searched for '%s' found '%s'\n",
+ key, value);
+
+ return value;
+ }
+
+ start = find_next_key(start, part_end);
+ }
+
+ prlog(PR_DEBUG, "NVRAM: '%s' not found\n", key);
+
+ return NULL;
+}