4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 static char *menu_file
;
29 static int menu_file_size
;
30 static char *menu_lines
[1024];
31 static int menu_lines_cnt
;
33 static menu_entry_t
*menu_entries
[9];
34 static int menu_entries_cnt
;
36 static int default_option
= 0;
37 static int timeout_option
= 10;
39 extern char *bootpath
;
41 menu_entry_t
*execute_menu()
43 menu_entry_t
*menu
= NULL
;
45 if (menu_entries_cnt
== 1)
47 menu
= menu_entries
[0];
49 else if (menu_entries_cnt
> 1)
52 int selected
= default_option
;
55 printf("\r\nAvailable boot configurations:\r\n");
57 for (i
=0; i
< menu_entries_cnt
; i
++)
59 printf("%c. %s\r\n", (i
+1) < 10 ? i
+'1':i
+'A', menu_entries
[i
]->m_title
);
63 while (ofw_read(stdin
, &chr
, 1) < 0) {
64 ofw_interpret("10 ms");
67 if (chr
>= '1' && chr
<= '9')
69 else if (chr
>= 'A' && chr
<= 'Z')
76 if (chr
>= 1 && chr
<= menu_entries_cnt
) {
77 D(bug("[BOOT] correct key\r\n"));
83 menu
= menu_entries
[selected
];
84 D(bug("[BOOT] Selected configuration: \"%s\"\r\n", menu
->m_title
));
90 int load_menu(uint8_t *load_base
)
97 D(bug("[BOOT] Trying to load menu.lst file\r\n"));
99 /* Clear memory before loading a text file */
100 ptr
= (uint32_t *)load_base
;
101 for (i
=0; i
< LOAD_SIZE
/ 4; i
++)
104 sprintf(tmp
, "load %s boot/menu.lst", bootpath
);
105 if (ofw_interpret(tmp
))
107 sprintf(tmp
, "load %s menu.lst", bootpath
);
108 if (ofw_interpret(tmp
))
109 printf("Failed to load menu file\r\n");
114 while(load_base
[menu_file_size
])
117 D(bug("[BOOT] Size of menu file: %d bytes\r\n", menu_file_size
));
119 /* 64 kilobytes of memory should be enough for simple menu ;) */
120 menu_file
= ofw_claim(NULL
, menu_file_size
, 4);
122 if (menu_file
== (char*)-1)
128 memcpy(menu_file
, load_base
, menu_file_size
);
137 ofw_release(menu_file
, menu_file_size
);
139 for (i
=0; i
< menu_entries_cnt
; i
++)
140 ofw_release(menu_entries
[i
], sizeof(menu_entry_t
));
143 char *eat_whitespace(char *c
)
145 while (*c
&& isblank(*c
))
151 char *next_word(char *c
)
153 while (*c
&& !isblank(*c
))
155 while (*c
&& isblank(*c
))
161 void parse_menu(unsigned long def_virt
)
166 menu_entry_t
*menu
= NULL
;
168 for (i
=0; i
< menu_file_size
; i
++)
172 menu_lines
[menu_lines_cnt
++] = &menu_file
[i
];
178 if (menu_file
[i
] == '\r') {
181 else if (menu_file
[i
] == '\n') {
187 for (i
=0; i
< menu_lines_cnt
; i
++)
189 char *str
= eat_whitespace(menu_lines
[i
]);
191 D(bug("[BOOT] Line: "));
200 else if (!strncasecmp(str
, "timeout", 7) && isspace(str
[7]))
202 str
= next_word(str
);
203 timeout_option
= atoi(str
);
205 D(bug("[BOOT] Found new timeout = %d\r\n", timeout_option
));
208 else if (!strncasecmp(str
, "default", 7) && isspace(str
[7]))
210 str
= next_word(str
);
211 default_option
= atoi(str
);
213 D(bug("[BOOT] Found new default = %d\r\n", default_option
));
215 else if (!strncasecmp(str
, "title", 5) && isspace(str
[5]))
217 if (menu_entries_cnt
< MAX_MENU_ENTRIES
)
221 menu
= menu_entries
[menu_entries_cnt
++] = ofw_claim(NULL
, sizeof(menu_entry_t
), 4);
223 menu
->m_title
= next_word(str
);
224 menu
->m_kernel
= NULL
;
225 menu
->m_modules_cnt
= 0;
226 menu
->m_virtual
= def_virt
;
228 j
= strlen(menu
->m_title
);
229 while (isspace(menu
->m_title
[--j
]))
230 menu
->m_title
[j
] = 0;
232 D(bug("[BOOT] Found new title '%s'\r\n", menu
->m_title
));
236 else if (!strncasecmp(str
, "virtual_addr", 12) && isspace(str
[12]))
240 char *c
= next_word(str
);
242 menu
->m_virtual
= atoi(c
);
245 else if (!strncasecmp(str
, "kernel", 6) && isspace(str
[6]))
247 D(bug("[BOOT] Found new kernel\r\n"));
251 char *c
= next_word(str
);
253 menu
->m_cmdline
= NULL
;
254 while(*c
&& !isblank(*c
))
266 if (menu
->m_cmdline
&& strlen(menu
->m_cmdline
))
268 char *c
= menu
->m_cmdline
+ strlen(menu
->m_cmdline
);
269 while (--c
> menu
->m_cmdline
)
280 else if (!strncasecmp(str
, "module", 6) && isspace(str
[6]))
282 D(bug("[BOOT] Found new module\r\n"));
283 if (menu
&& menu
->m_modules_cnt
< MAX_MODULES
)
285 menu
->m_modules
[menu
->m_modules_cnt
++] = next_word(str
);