summaryrefslogtreecommitdiff
path: root/common/eeprom/eeprom_layout.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2024-06-07 10:48:41 -0600
committerTom Rini <trini@konsulko.com>2024-06-07 10:48:41 -0600
commit77ba281c91c3578c835d11c0f2fe2cac6fa1d658 (patch)
treedbf0ff8a3b764fce3a7da1cbae20750d9d65d6af /common/eeprom/eeprom_layout.c
parent227be29df37545f74243a98c12a4a33c4160e3cd (diff)
parent57a9e8d86fde5732f77577adf52dcb62fcdc068a (diff)
Merge patch series "'eeprom' command improvements"
Marek BehĂșn <kabel@kernel.org> says: This series contains improvements for the 'eeprom' command: - refactors - fixes - improvements - ability to use driver model EEPROMs (uclass UCLASS_I2C_EEPROM) - more flexible EEPROM layout support It should not cause any behavior change for any existing board. This series is a dependency for some DDR issue fixes for Turris Omnia. I will be sending that one separately. github PR link (with CI): https://github.com/u-boot/u-boot/pull/540 - there is a failure for test.py for sandbox sandbox_clang but it seems unrelated to these changes
Diffstat (limited to 'common/eeprom/eeprom_layout.c')
-rw-r--r--common/eeprom/eeprom_layout.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/common/eeprom/eeprom_layout.c b/common/eeprom/eeprom_layout.c
index 1a425c1754d..8c0b7e0b393 100644
--- a/common/eeprom/eeprom_layout.c
+++ b/common/eeprom/eeprom_layout.c
@@ -57,6 +57,28 @@ static void eeprom_layout_print(const struct eeprom_layout *layout)
}
/*
+ * eeprom_layout_find_field() - finds a layout field by name
+ * @layout: A pointer to an existing struct layout.
+ * @field_name: The name of the field to update.
+ * @warn: Whether to print a warning if the field is not found.
+ *
+ * Returns: a pointer to the found field or NULL on failure.
+ */
+struct eeprom_field *eeprom_layout_find_field(struct eeprom_layout *layout,
+ char *field_name, bool warn)
+{
+ for (int i = 0; i < layout->num_of_fields; i++)
+ if (layout->fields[i].name != RESERVED_FIELDS &&
+ !strcmp(layout->fields[i].name, field_name))
+ return &layout->fields[i];
+
+ if (warn)
+ printf("No such field '%s'\n", field_name);
+
+ return NULL;
+}
+
+/*
* eeprom_layout_update_field() - update a single field in the layout data.
* @layout: A pointer to an existing struct layout.
* @field_name: The name of the field to update.
@@ -67,8 +89,8 @@ static void eeprom_layout_print(const struct eeprom_layout *layout)
static int eeprom_layout_update_field(struct eeprom_layout *layout,
char *field_name, char *new_data)
{
- int i, err;
- struct eeprom_field *fields = layout->fields;
+ struct eeprom_field *field;
+ int err;
if (new_data == NULL)
return 0;
@@ -76,21 +98,15 @@ static int eeprom_layout_update_field(struct eeprom_layout *layout,
if (field_name == NULL)
return -1;
- for (i = 0; i < layout->num_of_fields; i++) {
- if (fields[i].name == RESERVED_FIELDS ||
- strcmp(fields[i].name, field_name))
- continue;
-
- err = fields[i].update(&fields[i], new_data);
- if (err)
- printf("Invalid data for field %s\n", field_name);
-
- return err;
- }
+ field = eeprom_layout_find_field(layout, field_name, true);
+ if (field == NULL)
+ return -1;
- printf("No such field '%s'\n", field_name);
+ err = field->update(field, new_data);
+ if (err)
+ printf("Invalid data for field %s\n", field_name);
- return -1;
+ return err;
}
/*
@@ -111,14 +127,14 @@ void eeprom_layout_setup(struct eeprom_layout *layout, unsigned char *buf,
else
layout->layout_version = layout_version;
+ layout->data_size = buf_size;
+ layout->print = eeprom_layout_print;
+ layout->update = eeprom_layout_update_field;
+
eeprom_layout_assign(layout, layout_version);
layout->data = buf;
for (i = 0; i < layout->num_of_fields; i++) {
layout->fields[i].buf = buf;
buf += layout->fields[i].size;
}
-
- layout->data_size = buf_size;
- layout->print = eeprom_layout_print;
- layout->update = eeprom_layout_update_field;
}