summaryrefslogtreecommitdiff
path: root/bootloader/x1000
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/x1000
parent6fb1b8b3421cd73657ac2a84b0b13b975926746f (diff)
downloadrockbox-22cf852db1a37349061a665ea5b7a45bb1b2c2a7.tar.gz
rockbox-22cf852db1a37349061a665ea5b7a45bb1b2c2a7.zip
x1000: bootloader: split off installer code
Change-Id: I75918301214cd415392f8c95e8a07205cfa21659
Diffstat (limited to 'bootloader/x1000')
-rw-r--r--bootloader/x1000/install.c83
-rw-r--r--bootloader/x1000/x1000bootloader.h8
2 files changed, 91 insertions, 0 deletions
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__ */