vboot: move VbExGetLocalizationCount to vboot2
Rename VbExGetLocalizationCount to vb2ex_get_locale_count.
Change signature to return by value instead of by parameter.
BUG=b:146399181, b:156070974
TEST=make clean && make runtests
BRANCH=none
Change-Id: I4e3986007034724f01c9d42a382398ddacd59f33
Signed-off-by: Joel Kitching <kitching@google.com>
Cq-Depend: chromium:2190612
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2193151
Tested-by: Joel Kitching <kitching@chromium.org>
Commit-Queue: Joel Kitching <kitching@chromium.org>
Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index b1bc2ed..f8a1b4e 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -968,13 +968,6 @@
*/
vb2_error_t vb2ex_commit_data(struct vb2_context *ctx);
-/**
- * Check that physical presence button is currently pressed by the user.
- *
- * @returns 1 for pressed, 0 for not.
- */
-int vb2ex_physical_presence_pressed(void);
-
/*****************************************************************************/
/* Auxiliary firmware (auxfw) */
@@ -1213,4 +1206,18 @@
uint32_t selected_item,
uint32_t disabled_item_mask);
+/**
+ * Check that physical presence button is currently pressed by the user.
+ *
+ * @returns 1 for pressed, 0 for not.
+ */
+int vb2ex_physical_presence_pressed(void);
+
+/**
+ * Get the number of supported locales.
+ *
+ * @returns Number of locales. 0 if none or on error.
+ */
+uint32_t vb2ex_get_locale_count(void);
+
#endif /* VBOOT_REFERENCE_2API_H_ */
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index a8da939..4931d59 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -613,14 +613,6 @@
*/
vb2_error_t VbExLegacy(enum VbAltFwIndex_t altfw_num);
-/**
- * Return number of locales supported
- *
- * @param count Pointer to the number of locales.
- * @return VBERROR_... error, VB2_SUCCESS on success.
- */
-vb2_error_t VbExGetLocalizationCount(uint32_t *count);
-
enum vb_altfw {
VB_ALTFW_COUNT = 9, /* We allow 9 bootloaders, numbered 1-9 */
};
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index e10a421..9461d5d 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -5,6 +5,7 @@
* Display functions used in kernel selection.
*/
+#include "2api.h"
#include "2common.h"
#include "2misc.h"
#include "2nvstorage.h"
@@ -21,9 +22,8 @@
static uint32_t disp_disabled_idx_mask = 0;
__attribute__((weak))
-vb2_error_t VbExGetLocalizationCount(uint32_t *count) {
- *count = 0;
- return VB2_ERROR_UNKNOWN;
+uint32_t vb2ex_get_locale_count(void) {
+ return 0;
}
__attribute__((weak))
@@ -243,7 +243,8 @@
case VB_KEY_DOWN:
/* Arrow keys = change localization */
loc = vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX);
- if (VB2_SUCCESS != VbExGetLocalizationCount(&count))
+ count = vb2ex_get_locale_count();
+ if (count == 0)
loc = 0; /* No localization count (bad GBB?) */
else if (VB_KEY_RIGHT == key || VB_KEY_UP == key)
loc = (loc < count - 1 ? loc + 1 : 0);
diff --git a/firmware/lib/vboot_ui_legacy_menu.c b/firmware/lib/vboot_ui_legacy_menu.c
index 1e1462b..26de487 100644
--- a/firmware/lib/vboot_ui_legacy_menu.c
+++ b/firmware/lib/vboot_ui_legacy_menu.c
@@ -700,7 +700,8 @@
int i;
/* Initialize language menu with the correct amount of entries. */
- if (VB2_SUCCESS != VbExGetLocalizationCount(&count) || count == 0)
+ count = vb2ex_get_locale_count();
+ if (count == 0)
count = 1; /* Fall back to 1 language entry on failure */
items = malloc(count * sizeof(struct vb2_menu_item));
diff --git a/tests/vboot_display_tests.c b/tests/vboot_display_tests.c
index b57915f..c902614 100644
--- a/tests/vboot_display_tests.c
+++ b/tests/vboot_display_tests.c
@@ -45,13 +45,9 @@
}
/* Mocks */
-vb2_error_t VbExGetLocalizationCount(uint32_t *count) {
+uint32_t vb2ex_get_locale_count(void) {
- if (mock_localization_count == 0xffffffff)
- return VB2_ERROR_UNKNOWN;
-
- *count = mock_localization_count;
- return VB2_SUCCESS;
+ return mock_localization_count;
}
uint32_t VbExGetAltFwIdxMask() {
@@ -113,7 +109,7 @@
/* Reset localization if localization count is invalid */
ResetMocks();
vb2_nv_set(ctx, VB2_NV_LOCALIZATION_INDEX, 1);
- mock_localization_count = 0xffffffff;
+ mock_localization_count = 0;
VbCheckDisplayKey(ctx, VB_KEY_UP, NULL);
TEST_EQ(vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX), 0,
"DisplayKey invalid");
diff --git a/tests/vboot_legacy_menu_tests.c b/tests/vboot_legacy_menu_tests.c
index 80325f8..4a0dfaa 100644
--- a/tests/vboot_legacy_menu_tests.c
+++ b/tests/vboot_legacy_menu_tests.c
@@ -118,9 +118,8 @@
return &gbb;
}
-vb2_error_t VbExGetLocalizationCount(uint32_t *count) {
- *count = 1;
- return VB2_SUCCESS;
+uint32_t vb2ex_get_locale_count(void) {
+ return 1;
}
uint32_t VbExGetAltFwIdxMask() {