summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/cbi.c8
-rw-r--r--include/cros_board_info.h16
-rw-r--r--util/cbi-util.c10
3 files changed, 26 insertions, 8 deletions
diff --git a/common/cbi.c b/common/cbi.c
index 8517506eec..cf4605288a 100644
--- a/common/cbi.c
+++ b/common/cbi.c
@@ -49,6 +49,14 @@ uint8_t *cbi_set_data(uint8_t *p, enum cbi_data_tag tag,
return p;
}
+uint8_t *cbi_set_string(uint8_t *p, enum cbi_data_tag tag, const char *str)
+{
+ if (str == NULL)
+ return p;
+
+ return cbi_set_data(p, tag, str, strlen(str) + 1);
+}
+
struct cbi_data *cbi_find_tag(const void *cbi, enum cbi_data_tag tag)
{
struct cbi_data *d;
diff --git a/include/cros_board_info.h b/include/cros_board_info.h
index 8ed8737731..e7a1f1bb48 100644
--- a/include/cros_board_info.h
+++ b/include/cros_board_info.h
@@ -90,6 +90,22 @@ uint8_t *cbi_set_data(uint8_t *p, enum cbi_data_tag tag,
const void *buf, int size);
/**
+ * Store string data in memory in CBI data format.
+ *
+ * @param p Pointer to the buffer where a new data item will be stored. It
+ * should be pointing to the data section of CBI.
+ * @param tag Tag of the data item
+ * @param str Pointer to the string data being copied. If pointer is NULL,
+ * this function will ignore adding the tag as well. Else, the
+ * string data will be added to CBI using size of strlen + 1. This
+ * string is assumed to be NUL-terminated and NUL gets stored in
+ * CBI along with the string data.
+ * @return Address of the byte following the stored data in the destination
+ * buffer.
+ */
+uint8_t *cbi_set_string(uint8_t *p, enum cbi_data_tag tag, const char *str);
+
+/**
* Find a data field in CBI
*
* @param cbi Buffer containing CBI struct
diff --git a/util/cbi-util.c b/util/cbi-util.c
index 2ea86b14cf..f8abb4e64a 100644
--- a/util/cbi-util.c
+++ b/util/cbi-util.c
@@ -340,14 +340,8 @@ static int cmd_create(int argc, char **argv)
p = cbi_set_data(p, CBI_TAG_OEM_ID, &bi.oem.val, bi.oem.size);
p = cbi_set_data(p, CBI_TAG_SKU_ID, &bi.sku.val, bi.sku.size);
p = cbi_set_data(p, CBI_TAG_MODEL_ID, &bi.model.val, bi.model.size);
- if (bi.dram_part_num != NULL) {
- p = cbi_set_data(p, CBI_TAG_DRAM_PART_NUM, bi.dram_part_num,
- strlen(bi.dram_part_num) + 1);
- }
- if (bi.oem_name != NULL) {
- p = cbi_set_data(p, CBI_TAG_OEM_NAME, bi.oem_name,
- strlen(bi.oem_name) + 1);
- }
+ p = cbi_set_string(p, CBI_TAG_DRAM_PART_NUM, bi.dram_part_num);
+ p = cbi_set_string(p, CBI_TAG_OEM_NAME, bi.oem_name);
h->total_size = p - cbi;
h->crc = cbi_crc8(h);