summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-03-05 09:25:09 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-03-12 18:25:10 +0000
commit905591215fdad421f9985ad846b082b86a9ed0b7 (patch)
treebcaab46908cb4112e8f62fd5ba938193e4747c7f
parente2fcbd04ea8a9334b6c961a2f19933d8b9d675d4 (diff)
downloadrockbox-905591215f.tar.gz
rockbox-905591215f.zip
x1000: bootloader: split off recovery menu code
Change-Id: I6c6a25dc248b5dcbca796781f761bef05337431c
-rw-r--r--bootloader/SOURCES1
-rw-r--r--bootloader/x1000.c109
-rw-r--r--bootloader/x1000/recovery.c136
-rw-r--r--bootloader/x1000/x1000bootloader.h6
4 files changed, 143 insertions, 109 deletions
diff --git a/bootloader/SOURCES b/bootloader/SOURCES
index e818fab916..16391f8528 100644
--- a/bootloader/SOURCES
+++ b/bootloader/SOURCES
@@ -92,4 +92,5 @@ x1000.c
x1000/boot.c
x1000/gui.c
x1000/install.c
+x1000/recovery.c
#endif
diff --git a/bootloader/x1000.c b/bootloader/x1000.c
index c57ddfff4e..8b1dae3050 100644
--- a/bootloader/x1000.c
+++ b/bootloader/x1000.c
@@ -56,38 +56,12 @@
#include <stdio.h>
#include <stdarg.h>
-enum {
- MENUITEM_HEADING,
- MENUITEM_ACTION,
-};
-
-struct menuitem {
- int type;
- const char* text;
- void(*action)(void);
-};
-
void init_lcd(void);
void init_usb(void);
int init_disk(void);
-void recovery_menu(void) __attribute__((noreturn));
-
void usb_mode(void);
-/* Defines the recovery menu contents */
-const struct menuitem recovery_items[] = {
- {MENUITEM_HEADING, "System", NULL},
- {MENUITEM_ACTION, "Start Rockbox", &boot_rockbox},
- {MENUITEM_ACTION, "USB mode", &usb_mode},
- {MENUITEM_ACTION, "Shutdown", &shutdown},
- {MENUITEM_ACTION, "Reboot", &reboot},
- {MENUITEM_HEADING, "Bootloader", NULL},
- {MENUITEM_ACTION, "Install or update", &bootloader_install},
- {MENUITEM_ACTION, "Backup", &bootloader_backup},
- {MENUITEM_ACTION, "Restore", &bootloader_restore},
-};
-
/* Flags to indicate if hardware was already initialized */
bool usb_inited = false;
bool disk_inited = false;
@@ -126,89 +100,6 @@ int init_disk(void)
return 0;
}
-void put_help_line(int line, const char* str1, const char* str2)
-{
- int width = LCD_WIDTH / SYSFONT_WIDTH;
- lcd_puts(0, line, str1);
- lcd_puts(width - strlen(str2), line, str2);
-}
-
-void recovery_menu(void)
-{
- const int n_items = sizeof(recovery_items)/sizeof(struct menuitem);
-
- int selection = 0;
- while(recovery_items[selection].type != MENUITEM_ACTION)
- ++selection;
-
- while(1) {
- clearscreen();
- putcenter_y(0, "Rockbox recovery menu");
-
- int top_line = 2;
-
- /* draw the menu */
- for(int i = 0; i < n_items; ++i) {
- switch(recovery_items[i].type) {
- case MENUITEM_HEADING:
- lcd_putsf(0, top_line+i, "[%s]", recovery_items[i].text);
- break;
-
- case MENUITEM_ACTION:
- lcd_puts(3, top_line+i, recovery_items[i].text);
- break;
-
- default:
- break;
- }
- }
-
- /* draw the selection marker */
- lcd_puts(0, top_line+selection, "=>");
-
- /* draw the help text */
- int line = (LCD_HEIGHT - SYSFONT_HEIGHT)/SYSFONT_HEIGHT - 3;
- put_help_line(line++, BL_DOWN_NAME "/" BL_UP_NAME, "move cursor");
- put_help_line(line++, BL_SELECT_NAME, "select item");
- put_help_line(line++, BL_QUIT_NAME, "power off");
-
- lcd_update();
-
- /* handle input */
- switch(get_button(TIMEOUT_BLOCK)) {
- case BL_SELECT: {
- if(recovery_items[selection].action)
- recovery_items[selection].action();
- } break;
-
- case BL_UP:
- for(int i = selection-1; i >= 0; --i) {
- if(recovery_items[i].action) {
- selection = i;
- break;
- }
- }
- break;
-
- case BL_DOWN:
- for(int i = selection+1; i < n_items; ++i) {
- if(recovery_items[i].action) {
- selection = i;
- break;
- }
- }
- break;
-
- case BL_QUIT:
- shutdown();
- break;
-
- default:
- break;
- }
- }
-}
-
void usb_mode(void)
{
init_usb();
diff --git a/bootloader/x1000/recovery.c b/bootloader/x1000/recovery.c
new file mode 100644
index 0000000000..809bd6578a
--- /dev/null
+++ b/bootloader/x1000/recovery.c
@@ -0,0 +1,136 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2021-2022 Aidan MacDonald
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "x1000bootloader.h"
+#include "lcd.h"
+#include "font.h"
+#include "button.h"
+#include "kernel.h"
+#include <string.h>
+
+extern void usb_mode(void);
+
+enum {
+ MENUITEM_HEADING,
+ MENUITEM_ACTION,
+};
+
+struct menuitem {
+ int type;
+ const char* text;
+ void(*action)(void);
+};
+
+/* Defines the recovery menu contents */
+static const struct menuitem recovery_items[] = {
+ {MENUITEM_HEADING, "System", NULL},
+ {MENUITEM_ACTION, "Start Rockbox", &boot_rockbox},
+ {MENUITEM_ACTION, "USB mode", &usb_mode},
+ {MENUITEM_ACTION, "Shutdown", &shutdown},
+ {MENUITEM_ACTION, "Reboot", &reboot},
+ {MENUITEM_HEADING, "Bootloader", NULL},
+ {MENUITEM_ACTION, "Install or update", &bootloader_install},
+ {MENUITEM_ACTION, "Backup", &bootloader_backup},
+ {MENUITEM_ACTION, "Restore", &bootloader_restore},
+};
+
+static void put_help_line(int line, const char* str1, const char* str2)
+{
+ int width = LCD_WIDTH / SYSFONT_WIDTH;
+ lcd_puts(0, line, str1);
+ lcd_puts(width - strlen(str2), line, str2);
+}
+
+void recovery_menu(void)
+{
+ const int n_items = sizeof(recovery_items)/sizeof(struct menuitem);
+
+ int selection = 0;
+ while(recovery_items[selection].type != MENUITEM_ACTION)
+ ++selection;
+
+ while(1) {
+ clearscreen();
+ putcenter_y(0, "Rockbox recovery menu");
+
+ int top_line = 2;
+
+ /* draw the menu */
+ for(int i = 0; i < n_items; ++i) {
+ switch(recovery_items[i].type) {
+ case MENUITEM_HEADING:
+ lcd_putsf(0, top_line+i, "[%s]", recovery_items[i].text);
+ break;
+
+ case MENUITEM_ACTION:
+ lcd_puts(3, top_line+i, recovery_items[i].text);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ /* draw the selection marker */
+ lcd_puts(0, top_line+selection, "=>");
+
+ /* draw the help text */
+ int line = (LCD_HEIGHT - SYSFONT_HEIGHT)/SYSFONT_HEIGHT - 3;
+ put_help_line(line++, BL_DOWN_NAME "/" BL_UP_NAME, "move cursor");
+ put_help_line(line++, BL_SELECT_NAME, "select item");
+ put_help_line(line++, BL_QUIT_NAME, "power off");
+
+ lcd_update();
+
+ /* handle input */
+ switch(get_button(TIMEOUT_BLOCK)) {
+ case BL_SELECT: {
+ if(recovery_items[selection].action)
+ recovery_items[selection].action();
+ } break;
+
+ case BL_UP:
+ for(int i = selection-1; i >= 0; --i) {
+ if(recovery_items[i].action) {
+ selection = i;
+ break;
+ }
+ }
+ break;
+
+ case BL_DOWN:
+ for(int i = selection+1; i < n_items; ++i) {
+ if(recovery_items[i].action) {
+ selection = i;
+ break;
+ }
+ }
+ break;
+
+ case BL_QUIT:
+ shutdown();
+ break;
+
+ default:
+ break;
+ }
+ }
+}
diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h
index 47f340532d..05f421fc61 100644
--- a/bootloader/x1000/x1000bootloader.h
+++ b/bootloader/x1000/x1000bootloader.h
@@ -92,4 +92,10 @@ void boot_rockbox(void);
void shutdown(void);
void reboot(void);
+/*
+ * Misc
+ */
+
+void recovery_menu(void) __attribute__((noreturn));
+
#endif /* __X1000BOOTLOADER_H__ */