expo: Allow menu items to have values
At present menu items are stored according to their sequence number in
the menu. In some cases we may want to have holes in that sequence, or
not use a sequence at all.
Add a new 'value' property for menu items. This will be used for
reading and writing, if present. If there is no 'value' property, then
the normal sequence number will be used instead.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/boot/expo_build.c b/boot/expo_build.c
index a4df798..fece3ea 100644
--- a/boot/expo_build.c
+++ b/boot/expo_build.c
@@ -227,10 +227,10 @@
static int menu_build(struct build_info *info, ofnode node, struct scene *scn,
uint id, struct scene_obj **objp)
{
+ const u32 *item_ids, *item_values;
struct scene_obj_menu *menu;
+ int ret, size, i, num_items;
uint title_id, menu_id;
- const u32 *item_ids;
- int ret, size, i;
const char *name;
name = ofnode_get_name(node);
@@ -254,9 +254,15 @@
return log_msg_ret("itm", -EINVAL);
if (!size || size % sizeof(u32))
return log_msg_ret("isz", -EINVAL);
- size /= sizeof(u32);
+ num_items = size / sizeof(u32);
- for (i = 0; i < size; i++) {
+ item_values = ofnode_read_prop(node, "item-value", &size);
+ if (item_values) {
+ if (size != num_items * sizeof(u32))
+ return log_msg_ret("vsz", -EINVAL);
+ }
+
+ for (i = 0; i < num_items; i++) {
struct scene_menitem *item;
uint label, key, desc;
@@ -280,6 +286,8 @@
desc, 0, 0, &item);
if (ret < 0)
return log_msg_ret("mi", ret);
+ if (item_values)
+ item->value = fdt32_to_cpu(item_values[i]);
}
*objp = &menu->obj;
diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index be25f6a..ec9008e 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -282,6 +282,16 @@
uint seq);
/**
+ * scene_menuitem_find_val() - Find the menu item with a given value
+ *
+ * @menu: Menu to check
+ * @find_val: Value to look for
+ * Return: menu item if found, else NULL
+ */
+struct scene_menitem *scene_menuitem_find_val(const struct scene_obj_menu *menu,
+ int val);
+
+/**
* scene_bbox_union() - update bouding box with the demensions of an object
*
* Updates @bbox so that it encompasses the bounding box of object @id
diff --git a/boot/scene_menu.c b/boot/scene_menu.c
index c331f66..04ff159 100644
--- a/boot/scene_menu.c
+++ b/boot/scene_menu.c
@@ -61,6 +61,22 @@
return NULL;
}
+struct scene_menitem *scene_menuitem_find_val(const struct scene_obj_menu *menu,
+ int val)
+{
+ struct scene_menitem *item;
+ uint i;
+
+ i = 0;
+ list_for_each_entry(item, &menu->item_head, sibling) {
+ if (item->value == val)
+ return item;
+ i++;
+ }
+
+ return NULL;
+}
+
/**
* update_pointers() - Update the pointer object and handle highlights
*
@@ -416,6 +432,7 @@
item->desc_id = desc_id;
item->preview_id = preview_id;
item->flags = flags;
+ item->value = INT_MAX;
list_add_tail(&item->sibling, &menu->item_head);
if (itemp)