-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmenu.c
114 lines (99 loc) · 2.39 KB
/
menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "menu.h"
#include "string.h"
#include "powerpc.h"
#include "powerpc_elf.h"
#include "log.h"
#include "time.h"
#include "fatfs/ff.h"
#include "menu_render.h"
#include "console_common.h"
#include "video_low.h"
#include "malloc.h"
#include "browse.h"
void menu_down(void) {
int max;
if (browse_menu_entries_count) {
max = browse_menu_entries_count;
} else {
max = config_entries_count;
}
menu_selection++;
if (menu_selection == max)
menu_selection = 0;
menu_draw_entries_and_help();
}
void menu_up(void) {
int max;
if (browse_menu_entries_count) {
max = browse_menu_entries_count;
} else {
max = config_entries_count;
}
if (menu_selection == 0)
menu_selection = max-1;
else
menu_selection--;
menu_draw_entries_and_help();
}
int menu_activate(void) {
int m_err;
if (browse_menu_entries_count) {
return menu_browse_activate();
}
stanza *sel = &config_entries[menu_selection];
if (sel->reboot) {
VIDEO_Shutdown();
powerpc_reset();
return 0;
}
if (sel->poweroff) {
VIDEO_Shutdown();
powerpc_poweroff();
return 0;
}
// if root is set, initialize the corresponding volume
FATFS fatfs;
char target[3];
if (sel->root) {
memcpy(target, sel->root, 3);
target[2] = 0;
FRESULT res = f_mount(&fatfs, target, 1);
if (res != FR_OK) {
log_printf("could not mount %s: %d\n", target, res);
return res;
}
}
//NOTE: fatfs is not unmounted when browsing, re-mounting will cleanup the previous object
if (sel->browse) {
old_menu_selection = menu_selection;
// directory browse, uses 'root' to set starting partition and directory
// otherwise starts from first partition and root directory
if (sel->root) {
memcpy(browse_current_path, sel->root, strlen(sel->root)+1);
} else {
// use first logical drive by default
browse_current_path[0] = '0';
browse_current_path[1] = ':';
browse_current_path[2] = 0;
}
return menu_browse();
}
int err;
if (!sel->kernel) {
log_printf("BUG: invalid menu entry\n");
err = -1;
goto unmount_and_exit;
}
// at this point root must have been setup
// and we are going to boot a kernel
// root has never trailing slash, kernel has always leading slash
char *kernel_fn = strcat(sel->root, sel->kernel);
err = try_boot_file(kernel_fn, sel->kernel_args);
free(kernel_fn);
unmount_and_exit:
m_err = f_mount(NULL, target, 0);
if (m_err) {
log_printf("failed to unmount: %d\n", m_err);
}
return err;
}