diff options
Diffstat (limited to 'bootloader/x1000/install.c')
-rw-r--r-- | bootloader/x1000/install.c | 83 |
1 files changed, 83 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 | |||
28 | extern int init_disk(void); | ||
29 | |||
30 | enum { | ||
31 | INSTALL, | ||
32 | BACKUP, | ||
33 | RESTORE, | ||
34 | }; | ||
35 | |||
36 | static 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 | |||
70 | void bootloader_install(void) | ||
71 | { | ||
72 | bootloader_action(INSTALL); | ||
73 | } | ||
74 | |||
75 | void bootloader_backup(void) | ||
76 | { | ||
77 | bootloader_action(BACKUP); | ||
78 | } | ||
79 | |||
80 | void bootloader_restore(void) | ||
81 | { | ||
82 | bootloader_action(RESTORE); | ||
83 | } | ||