summaryrefslogtreecommitdiff
path: root/board/freescale/mx7ulp_evk
diff options
context:
space:
mode:
authorJi Luo <ji.luo@nxp.com>2020-05-07 12:52:00 +0800
committerJi Luo <ji.luo@nxp.com>2022-04-18 16:40:10 +0800
commit67afc8c772c8f74f134985e79d1dce9c7c3cd593 (patch)
tree0cdfbffd57ec2e1042b4d7c82b212e301a225db8 /board/freescale/mx7ulp_evk
parent4d54e716c0ce68e056105f12cc19a95e944246dc (diff)
MA-17159 Implement bootloader menu for imx7ulp
According to the spec of android wear, the device MUST provides a bootloader menu for debugging purpose. This commit implements a simple bootloader menu based on imx7ulp_evk revb board, the menu will show when booting with 'VOL+' key pressed, users can press "VOL+" to choose the item, then press "ONOFF" key to confirm. Test: bootloader menu show on imx7ulp_evk revb. Change-Id: I80638a43afa17e312e633b05888c62440380b42b Signed-off-by: Ji Luo <ji.luo@nxp.com> (cherry picked from commit 9d5995caf7146d4955fba2524a7f25d761049e28) (cherry picked from commit 0e9dfdfc5e06b2897c4471ac6d29a70218e4f11c)
Diffstat (limited to 'board/freescale/mx7ulp_evk')
-rw-r--r--board/freescale/mx7ulp_evk/mx7ulp_evk.c110
1 files changed, 109 insertions, 1 deletions
diff --git a/board/freescale/mx7ulp_evk/mx7ulp_evk.c b/board/freescale/mx7ulp_evk/mx7ulp_evk.c
index ce716756b9..9887aeee69 100644
--- a/board/freescale/mx7ulp_evk/mx7ulp_evk.c
+++ b/board/freescale/mx7ulp_evk/mx7ulp_evk.c
@@ -17,6 +17,14 @@
#include <dm.h>
#include <env.h>
+#ifdef CONFIG_BOOTLOADER_MENU
+#include "video.h"
+#include "dm/uclass.h"
+#include "video_font_data.h"
+#include "video_console.h"
+#include "recovery.h"
+#endif
+
DECLARE_GLOBAL_DATA_PTR;
#define UART_PAD_CTRL (PAD_CTL_PUS_UP)
@@ -145,6 +153,15 @@ add:
}
#endif
+#ifdef CONFIG_BOOTLOADER_MENU
+static iomux_cfg_t const vol_pad[] = {
+ MX7ULP_PAD_PTA3__PTA3 | MUX_PAD_CTRL(PAD_CTL_IBE_ENABLE),
+};
+#define VOLP_GPIO IMX_GPIO_NR(1, 3)
+bool is_vol_key_pressed(void);
+int show_bootloader_menu(void);
+#endif
+
int board_late_init(void)
{
env_set("tee", "no");
@@ -156,6 +173,16 @@ int board_late_init(void)
board_late_mmc_env_init();
#endif
+#ifdef CONFIG_BOOTLOADER_MENU
+ mx7ulp_iomux_setup_multiple_pads(vol_pad, ARRAY_SIZE(vol_pad));
+ if (gpio_request(VOLP_GPIO, "volp"))
+ printf("request error\n");
+ gpio_direction_input(VOLP_GPIO);
+
+ if (is_vol_key_pressed())
+ show_bootloader_menu();
+#endif
+
return 0;
}
@@ -164,4 +191,85 @@ bool is_power_key_pressed(void) {
/* the onoff button is 'pressed' by default on evk board */
return (bool)(!(readl(SNVS_HPSR_REVB) & (0x1 << 6)));
}
-#endif
+
+#ifdef CONFIG_BOOTLOADER_MENU
+char bootloader_menu[4][40] = {
+ " * Power off the device\n",
+ " * Start the device normally\n",
+ " * Restart the bootloader\n",
+ " * Boot into recovery mode\n"
+};
+
+bool is_vol_key_pressed(void) {
+ int ret = 0;
+ ret = gpio_get_value(VOLP_GPIO);
+ return (bool)(!!ret);
+}
+
+int show_bootloader_menu(void) {
+ struct udevice *dev, *dev_console;
+ uint32_t focus = 0, i;
+ bool stop_menu = false;
+
+ /* clear screen first */
+ if (uclass_first_device_err(UCLASS_VIDEO, &dev)) {
+ printf("no video device found!\n");
+ return -1;
+ }
+ video_clear(dev);
+
+ if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev_console)) {
+ printf("no text console device found!\n");
+ return -1;
+ }
+
+ vidconsole_position_cursor(dev_console, 0, 1);
+ vidconsole_put_string(dev_console, "Press 'vol+' to choose an item, press\n");
+ vidconsole_put_string(dev_console, "power key to confirm:\n");
+ while (!stop_menu) {
+ /* reset the cursor position. */
+ vidconsole_position_cursor(dev_console, 0, 4);
+ /* show menu */
+ for (i = 0; i < 4; i++) {
+ /* reverse color for the 'focus' line. */
+ if (i == focus)
+ vidconsole_put_string(dev_console, "\x1b[7m");
+ /* show text */
+ vidconsole_put_string(dev_console, bootloader_menu[i]);
+ /* reset color back for the 'next' line. */
+ if (i == focus)
+ vidconsole_put_string(dev_console, "\x1b[0m");
+ }
+ /* check button status */
+ while (1) {
+ if (is_power_key_pressed()) {
+ switch (focus) {
+ case 0: /*TODO*/
+ case 1:
+ break;
+ case 2:
+ do_reset(NULL, 0, 0, NULL);
+ case 3:
+ board_recovery_setup();
+ break;
+ default:
+ break;
+ }
+ stop_menu = true;
+ break;
+ } else if (is_vol_key_pressed()) {
+ focus++;
+ if (focus > 3)
+ focus = 0;
+ mdelay(400);
+ break;
+ }
+ }
+ }
+
+ /* clear screen before exit */
+ video_clear(dev);
+ return 0;
+}
+#endif /* CONFIG_BOOTLOADER_MENU */
+#endif /* CONFIG_ANDROID_SUPPORT*/