Skip to content

Commit

Permalink
failsafe: enable press reset / WPS button to load image via TFTP
Browse files Browse the repository at this point in the history
For devices which have WPS button, hold WPS button for 1 second to enter.
For devices only have reset button, hold reset button for 6 seconds to enter.

Signed-off-by: Shiji Yang <[email protected]>
  • Loading branch information
DragonBluep committed May 2, 2023
1 parent ba4c45b commit 113bda4
Showing 1 changed file with 63 additions and 14 deletions.
77 changes: 63 additions & 14 deletions board/ralink/common/cmd_mtkautoboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,43 @@ struct mtk_bootmenu_entry {
}
};

#ifdef CONFIG_FAILSAFE_ON_BUTTON
/* Loop TFTP download mode */
static void mtktftploop(void)
{
#define _tostr(a) #a
#define tostr(a) _tostr(a)

env_set("autostart", "yes");
env_set("ipaddr", "192.168.1.1");
env_set("serverip", "192.168.1.2");
env_set("loadaddr", tostr(CONFIG_SYS_LOAD_ADDR));

while(1) {
run_command("tftp recovery.bin", 0);
mdelay(3000);
}
}

static inline void mtkledblink(void)
{
mdelay(100);
#ifdef MT7621_LED_STATUS1
gpio_direction_output(MT7621_LED_STATUS1, 1);
#endif // MT7621_LED_STATUS1
#ifdef MT7621_LED_STATUS2
gpio_direction_output(MT7621_LED_STATUS2, 0);
#endif // MT7621_LED_STATUS2
mdelay(100);
#ifdef MT7621_LED_STATUS1
gpio_direction_output(MT7621_LED_STATUS1, 0);
#endif // MT7621_LED_STATUS1
#ifdef MT7621_LED_STATUS2
gpio_direction_output(MT7621_LED_STATUS2, 1);
#endif // MT7621_LED_STATUS2
}
#endif

static int do_mtkautoboot(cmd_tbl_t *cmdtp, int flag, int argc,
char *const argv[])
{
Expand All @@ -41,30 +78,42 @@ static int do_mtkautoboot(cmd_tbl_t *cmdtp, int flag, int argc,
u32 delay = CONFIG_MTKAUTOBOOT_DELAY;

#ifdef CONFIG_FAILSAFE_ON_BUTTON
#ifdef MT7621_BUTTON_WPS
for (i = 0; i < 5; i++) {
#else
for (i = 0; i < 30; i++) {
#endif
if (gpio_get_value(MT7621_BUTTON_RESET) != 0)
break;

mdelay(100);
#ifdef MT7621_LED_STATUS1
gpio_direction_output(MT7621_LED_STATUS1, 1);
#endif // MT7621_LED_STATUS1
#ifdef MT7621_LED_STATUS2
gpio_direction_output(MT7621_LED_STATUS2, 0);
#endif // MT7621_LED_STATUS2
mdelay(100);
#ifdef MT7621_LED_STATUS1
gpio_direction_output(MT7621_LED_STATUS1, 0);
#endif // MT7621_LED_STATUS1
#ifdef MT7621_LED_STATUS2
gpio_direction_output(MT7621_LED_STATUS2, 1);
#endif // MT7621_LED_STATUS2
mtkledblink();
}

#ifdef MT7621_BUTTON_WPS
if (i == 5) {
#else
if (i >= 5 && i < 30) {
#endif
printf("Enter web failsafe mode by pressing reset button\n");
run_command("httpd", 0);
}

#ifdef MT7621_BUTTON_WPS
for (i = 0; i < 5; i++) {
if (gpio_get_value(MT7621_BUTTON_WPS) != 0)
break;

mtkledblink();
}
if (i == 5) {
printf("Enter TFTP download mode by pressing WPS button\n");
#else
if (i == 30) {
printf("Enter TFTP download mode by pressing reset button\n");
#endif
printf("Load image \"recovery.bin\" to RAM and then boot it\n");
mtktftploop();
}
#endif // CONFIG_FAILSAFE_ON_BUTTON

for (i = 0; i < ARRAY_SIZE(bootmenu_entries); i++) {
Expand Down

0 comments on commit 113bda4

Please sign in to comment.