summaryrefslogtreecommitdiff
path: root/utils/nwztools/plattools/dualboot.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/nwztools/plattools/dualboot.c')
-rw-r--r--utils/nwztools/plattools/dualboot.c114
1 files changed, 45 insertions, 69 deletions
diff --git a/utils/nwztools/plattools/dualboot.c b/utils/nwztools/plattools/dualboot.c
index 965fabed72..a5d04fa4ed 100644
--- a/utils/nwztools/plattools/dualboot.c
+++ b/utils/nwztools/plattools/dualboot.c
@@ -29,7 +29,14 @@
29 * error, the OF is run. This seems like the safest option since the OF is 29 * error, the OF is run. This seems like the safest option since the OF is
30 * always there and might do magic things. */ 30 * always there and might do magic things. */
31 31
32bool boot_rockbox(void) 32enum boot_mode
33{
34 BOOT_ROCKBOX,
35 BOOT_TOOLS,
36 BOOT_OF
37};
38
39enum boot_mode get_boot_mode(void)
33{ 40{
34 /* get time */ 41 /* get time */
35 struct timeval deadline; 42 struct timeval deadline;
@@ -37,7 +44,7 @@ bool boot_rockbox(void)
37 { 44 {
38 nwz_lcdmsg(false, 0, 2, "Cannot get time"); 45 nwz_lcdmsg(false, 0, 2, "Cannot get time");
39 sleep(2); 46 sleep(2);
40 return false; 47 return BOOT_OF;
41 } 48 }
42 /* open input device */ 49 /* open input device */
43 int input_fd = nwz_key_open(); 50 int input_fd = nwz_key_open();
@@ -45,11 +52,11 @@ bool boot_rockbox(void)
45 { 52 {
46 nwz_lcdmsg(false, 0, 2, "Cannot open input device"); 53 nwz_lcdmsg(false, 0, 2, "Cannot open input device");
47 sleep(2); 54 sleep(2);
48 return false; 55 return BOOT_OF;
49 } 56 }
50 deadline.tv_sec += 5; 57 deadline.tv_sec += 5;
51 /* wait for user action */ 58 /* wait for user action */
52 bool boot_rb = false; 59 enum boot_mode mode = BOOT_OF;
53 while(true) 60 while(true)
54 { 61 {
55 /* get time */ 62 /* get time */
@@ -69,7 +76,8 @@ bool boot_rockbox(void)
69 int sec_left = deadline.tv_sec - cur_time.tv_sec; 76 int sec_left = deadline.tv_sec - cur_time.tv_sec;
70 sec_left += (deadline.tv_usec - cur_time.tv_usec + 999999) / 1000000; /* round up */ 77 sec_left += (deadline.tv_usec - cur_time.tv_usec + 999999) / 1000000; /* round up */
71 nwz_lcdmsgf(false, 0, 2, "Booting OF in %d seconds ", sec_left); 78 nwz_lcdmsgf(false, 0, 2, "Booting OF in %d seconds ", sec_left);
72 nwz_lcdmsg(false, 0, 3, "Press BACK to boot RB"); 79 nwz_lcdmsg(false, 0, 3, "Press BACK to run tools");
80 nwz_lcdmsg(false, 0, 3, "Press PLAY to boot RB");
73 /* wait for a key (1s) */ 81 /* wait for a key (1s) */
74 int ret = nwz_key_wait_event(input_fd, 1000000); 82 int ret = nwz_key_wait_event(input_fd, 1000000);
75 if(ret != 1) 83 if(ret != 1)
@@ -77,14 +85,21 @@ bool boot_rockbox(void)
77 struct input_event evt; 85 struct input_event evt;
78 if(nwz_key_read_event(input_fd, &evt) != 1) 86 if(nwz_key_read_event(input_fd, &evt) != 1)
79 continue; 87 continue;
80 if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_BACK && !nwz_key_event_is_press(&evt)) 88 if(nwz_key_event_is_press(&evt))
89 continue;
90 if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_PLAY)
81 { 91 {
82 boot_rb = true; 92 mode = BOOT_ROCKBOX;
93 break;
94 }
95 else if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_BACK)
96 {
97 mode = BOOT_TOOLS;
83 break; 98 break;
84 } 99 }
85 } 100 }
86 nwz_key_close(input_fd); 101 nwz_key_close(input_fd);
87 return boot_rb; 102 return mode;
88} 103}
89 104
90static char *boot_rb_argv[] = 105static char *boot_rb_argv[] =
@@ -97,41 +112,40 @@ static char *boot_rb_argv[] =
97 NULL 112 NULL
98}; 113};
99 114
100static void wait_key(void)
101{
102 int input_fd = nwz_key_open();
103 /* display input state in a loop */
104 while(1)
105 {
106 /* wait for event (10ms) */
107 int ret = nwz_key_wait_event(input_fd, 10000);
108 if(ret != 1)
109 continue;
110 struct input_event evt;
111 if(nwz_key_read_event(input_fd, &evt) != 1)
112 continue;
113 if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_BACK && !nwz_key_event_is_press(&evt))
114 break;
115 }
116 /* finish nicely */
117 nwz_key_close(input_fd);
118}
119
120int NWZ_TOOL_MAIN(all_tools)(int argc, char **argv); 115int NWZ_TOOL_MAIN(all_tools)(int argc, char **argv);
121 116
122int main(int argc, char **argv) 117int main(int argc, char **argv)
123{ 118{
124#if 0 119 /* make sure backlight is on and we are running the standard lcd mode */
120 int fb_fd = nwz_fb_open(true);
121 if(fb_fd >= 0)
122 {
123 struct nwz_fb_brightness bl;
124 nwz_fb_get_brightness(fb_fd, &bl);
125 bl.level = NWZ_FB_BL_MAX_LEVEL;
126 nwz_fb_set_brightness(fb_fd, &bl);
127 nwz_fb_set_standard_mode(fb_fd);
128 nwz_fb_close(fb_fd);
129 }
125 nwz_lcdmsg(true, 0, 0, "dualboot"); 130 nwz_lcdmsg(true, 0, 0, "dualboot");
126 if(boot_rockbox()) 131 /* run all tools menu */
132 enum boot_mode mode = get_boot_mode();
133 if(mode == BOOT_TOOLS)
134 {
135 /* run tools and then run OF */
136 NWZ_TOOL_MAIN(all_tools)(argc, argv);
137 }
138 else if(mode == BOOT_ROCKBOX)
127 { 139 {
128 /* boot rockox */ 140 /* boot rockox */
129 nwz_lcdmsg(true, 0, 3, "Booting rockbox..."); 141 nwz_lcdmsg(true, 0, 3, "Booting rockbox...");
142 /* in the future, we will run rockbox here, for now we just print a
143 * message */
130 execvp("/usr/local/bin/lcdmsg", boot_rb_argv); 144 execvp("/usr/local/bin/lcdmsg", boot_rb_argv);
145 /* fallback to OF in case of failure */
131 nwz_lcdmsg(false, 0, 4, "failed."); 146 nwz_lcdmsg(false, 0, 4, "failed.");
132 sleep(5); 147 sleep(5);
133 } 148 }
134 /* if for some reason, running rockbox failed, then try to run the OF */
135 /* boot OF */ 149 /* boot OF */
136 nwz_lcdmsg(true, 0, 3, "Booting OF..."); 150 nwz_lcdmsg(true, 0, 3, "Booting OF...");
137 execvp("/usr/local/bin/SpiderApp.of", argv); 151 execvp("/usr/local/bin/SpiderApp.of", argv);
@@ -140,42 +154,4 @@ int main(int argc, char **argv)
140 /* if we reach this point, everything failed, so return an error so that 154 /* if we reach this point, everything failed, so return an error so that
141 * sysmgrd knows something is wrong */ 155 * sysmgrd knows something is wrong */
142 return 1; 156 return 1;
143#elif 0
144 const char *args_mount[] = {"mount", NULL};
145 int status;
146 char *output = nwz_run_pipe("mount", args_mount, &status);
147 nwz_lcdmsgf(true, 0, 0, "%d\n%s", status, output);
148 free(output);
149 wait_key();
150 const char *args_ls[] = {"ls", "/var", NULL};
151 output = nwz_run_pipe("ls", args_ls, &status);
152 nwz_lcdmsgf(true, 0, 0, "%d\n%s", status, output);
153 free(output);
154 wait_key();
155 const char *args_glogctl[] = {"glogctl", "flush", NULL};
156 output = nwz_run_pipe("/usr/local/bin/glogctl", args_glogctl, &status);
157 nwz_lcdmsgf(true, 0, 0, "%d\n%s", status, output);
158 free(output);
159 wait_key();
160 system("cp /var/GEMINILOG* /contents/");
161 sync();
162 execvp("/usr/local/bin/SpiderApp.of", argv);
163 return 0;
164#else
165 /* make sure backlight is on */
166 int fb_fd = nwz_fb_open(true);
167 if(fb_fd >= 0)
168 {
169 struct nwz_fb_brightness bl;
170 nwz_fb_get_brightness(fb_fd, &bl);
171 bl.level = NWZ_FB_BL_MAX_LEVEL;
172 nwz_fb_set_brightness(fb_fd, &bl);
173 nwz_fb_close(fb_fd);
174 }
175 /* run all tools menu */
176 NWZ_TOOL_MAIN(all_tools)(argc, argv);
177 /* run OF */
178 execvp("/usr/local/bin/SpiderApp.of", argv);
179 return 0;
180#endif
181} 157}