summaryrefslogtreecommitdiff
path: root/bootloader
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-03-05 09:21:58 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-03-12 18:25:10 +0000
commit22cf852db1a37349061a665ea5b7a45bb1b2c2a7 (patch)
tree20e93e0c52a390785b0d59889746913036792ecf /bootloader
parent6fb1b8b3421cd73657ac2a84b0b13b975926746f (diff)
downloadrockbox-22cf852db1a37349061a665ea5b7a45bb1b2c2a7.tar.gz
rockbox-22cf852db1a37349061a665ea5b7a45bb1b2c2a7.zip
x1000: bootloader: split off installer code
Change-Id: I75918301214cd415392f8c95e8a07205cfa21659
Diffstat (limited to 'bootloader')
-rw-r--r--bootloader/SOURCES1
-rw-r--r--bootloader/x1000.c58
-rw-r--r--bootloader/x1000/install.c83
-rw-r--r--bootloader/x1000/x1000bootloader.h8
4 files changed, 92 insertions, 58 deletions
diff --git a/bootloader/SOURCES b/bootloader/SOURCES
index 39b46b0b8d..0aa5985ef5 100644
--- a/bootloader/SOURCES
+++ b/bootloader/SOURCES
@@ -90,4 +90,5 @@ show_logo.c
90#elif defined(FIIO_M3K) || defined(SHANLING_Q1) || defined(EROS_QN) 90#elif defined(FIIO_M3K) || defined(SHANLING_Q1) || defined(EROS_QN)
91x1000.c 91x1000.c
92x1000/gui.c 92x1000/gui.c
93x1000/install.c
93#endif 94#endif
diff --git a/bootloader/x1000.c b/bootloader/x1000.c
index a079c478d5..72a02188c3 100644
--- a/bootloader/x1000.c
+++ b/bootloader/x1000.c
@@ -77,9 +77,6 @@ void boot_rockbox(void);
77void usb_mode(void); 77void usb_mode(void);
78void shutdown(void); 78void shutdown(void);
79void reboot(void); 79void reboot(void);
80void bootloader_install(void);
81void bootloader_backup(void);
82void bootloader_restore(void);
83 80
84/* Defines the recovery menu contents */ 81/* Defines the recovery menu contents */
85const struct menuitem recovery_items[] = { 82const struct menuitem recovery_items[] = {
@@ -274,61 +271,6 @@ void reboot(void)
274 while(1); 271 while(1);
275} 272}
276 273
277enum {
278 INSTALL,
279 BACKUP,
280 RESTORE,
281};
282
283void bootloader_action(int which)
284{
285 if(init_disk() != 0) {
286 splash2(5*HZ, "Install aborted", "Cannot access SD card");
287 return;
288 }
289
290 const char* msg;
291 switch(which) {
292 case INSTALL: msg = "Installing"; break;
293 case BACKUP: msg = "Backing up"; break;
294 case RESTORE: msg = "Restoring"; break;
295 default: return; /* can't happen */
296 }
297
298 splash(0, msg);
299
300 int rc;
301 switch(which) {
302 case INSTALL: rc = install_bootloader("/bootloader." BOOTFILE_EXT); break;
303 case BACKUP: rc = backup_bootloader(BOOTBACKUP_FILE); break;
304 case RESTORE: rc = restore_bootloader(BOOTBACKUP_FILE); break;
305 default: return;
306 }
307
308 static char buf[64];
309 snprintf(buf, sizeof(buf), "%s (%d)", installer_strerror(rc), rc);
310 const char* msg1 = rc == 0 ? "Success" : buf;
311 const char* msg2 = "Press " BL_QUIT_NAME " to continue";
312 splash2(0, msg1, msg2);
313
314 while(get_button(TIMEOUT_BLOCK) != BL_QUIT);
315}
316
317void bootloader_install(void)
318{
319 bootloader_action(INSTALL);
320}
321
322void bootloader_backup(void)
323{
324 bootloader_action(BACKUP);
325}
326
327void bootloader_restore(void)
328{
329 bootloader_action(RESTORE);
330}
331
332void main(void) 274void main(void)
333{ 275{
334 system_init(); 276 system_init();
diff --git a/bootloader/x1000/install.c b/bootloader/x1000/install.c
new file mode 100644
index 0000000000..aa4fdde3b0
--- /dev/null
+++ b/bootloader/x1000/install.c
@@ -0,0 +1,83 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021-2022 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "x1000bootloader.h"
23#include "kernel.h"
24#include "button.h"
25#include "installer-x1000.h"
26#include <stdio.h>
27
28extern int init_disk(void);
29
30enum {
31 INSTALL,
32 BACKUP,
33 RESTORE,
34};
35
36static void bootloader_action(int which)
37{
38 if(init_disk() != 0) {
39 splash2(5*HZ, "Install aborted", "Cannot access SD card");
40 return;
41 }
42
43 const char* msg;
44 switch(which) {
45 case INSTALL: msg = "Installing"; break;
46 case BACKUP: msg = "Backing up"; break;
47 case RESTORE: msg = "Restoring"; break;
48 default: return; /* can't happen */
49 }
50
51 splash(0, msg);
52
53 int rc;
54 switch(which) {
55 case INSTALL: rc = install_bootloader("/bootloader." BOOTFILE_EXT); break;
56 case BACKUP: rc = backup_bootloader(BOOTBACKUP_FILE); break;
57 case RESTORE: rc = restore_bootloader(BOOTBACKUP_FILE); break;
58 default: return;
59 }
60
61 static char buf[64];
62 snprintf(buf, sizeof(buf), "%s (%d)", installer_strerror(rc), rc);
63 const char* msg1 = rc == 0 ? "Success" : buf;
64 const char* msg2 = "Press " BL_QUIT_NAME " to continue";
65 splash2(0, msg1, msg2);
66
67 while(get_button(TIMEOUT_BLOCK) != BL_QUIT);
68}
69
70void bootloader_install(void)
71{
72 bootloader_action(INSTALL);
73}
74
75void bootloader_backup(void)
76{
77 bootloader_action(BACKUP);
78}
79
80void bootloader_restore(void)
81{
82 bootloader_action(RESTORE);
83}
diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h
index df891e54bb..fb7aa80e7f 100644
--- a/bootloader/x1000/x1000bootloader.h
+++ b/bootloader/x1000/x1000bootloader.h
@@ -76,4 +76,12 @@ void init_lcd(void);
76 76
77void gui_shutdown(void); 77void gui_shutdown(void);
78 78
79/*
80 * Installer
81 */
82
83void bootloader_install(void);
84void bootloader_backup(void);
85void bootloader_restore(void);
86
79#endif /* __X1000BOOTLOADER_H__ */ 87#endif /* __X1000BOOTLOADER_H__ */