2012-11-16 15:05:11 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 secunet Security Networks AG
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <coreboot_tables.h>
|
2016-04-24 01:24:57 +02:00
|
|
|
#include <libpayload.h>
|
2012-11-16 15:05:11 +01:00
|
|
|
|
|
|
|
#include <curses.h>
|
|
|
|
#include <form.h>
|
2016-04-24 01:24:57 +02:00
|
|
|
#include <menu.h>
|
2012-11-16 15:05:11 +01:00
|
|
|
|
|
|
|
#ifndef HOSTED
|
|
|
|
#define HOSTED 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int min(int x, int y)
|
|
|
|
{
|
|
|
|
if (x < y)
|
|
|
|
return x;
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int max(int x, int y)
|
|
|
|
{
|
|
|
|
if (x > y)
|
|
|
|
return x;
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void render_form(FORM *form)
|
|
|
|
{
|
|
|
|
int y, x, line;
|
|
|
|
WINDOW *w = form_win(form);
|
|
|
|
WINDOW *inner_w = form_sub(form);
|
2016-04-24 01:24:57 +02:00
|
|
|
int numlines = getmaxy(w) - 2;
|
2012-11-16 15:05:11 +01:00
|
|
|
getyx(inner_w, y, x);
|
|
|
|
line = y - (y % numlines);
|
2016-04-24 01:24:57 +02:00
|
|
|
WINDOW *der = derwin(w, getmaxy(w) - 2, getmaxx(w) - 2, 1, 1);
|
2012-11-16 15:05:11 +01:00
|
|
|
wclear(der);
|
|
|
|
wrefresh(der);
|
|
|
|
delwin(der);
|
2016-04-24 01:24:57 +02:00
|
|
|
copywin(inner_w, w, line, 0, 1, 1,
|
|
|
|
min(numlines, getmaxy(inner_w) - line), 68, 0);
|
2012-11-16 15:05:11 +01:00
|
|
|
wmove(w, y + 1 - line, x + 1);
|
|
|
|
wrefresh(w);
|
|
|
|
}
|
|
|
|
|
2016-08-18 10:32:27 +02:00
|
|
|
/* determine number of options, and maximum option name length */
|
|
|
|
static int count_cmos_options(struct cb_cmos_entries *option, int *numopts,
|
|
|
|
int *maxlength)
|
2012-11-16 15:05:11 +01:00
|
|
|
{
|
2016-08-18 10:32:27 +02:00
|
|
|
int n_opts = 0;
|
|
|
|
int max_l = 0;
|
2012-11-16 15:05:11 +01:00
|
|
|
|
|
|
|
while (option) {
|
2016-04-24 01:24:57 +02:00
|
|
|
if ((option->config != 'r') &&
|
2016-04-26 20:33:44 +02:00
|
|
|
(strcmp("check_sum", (char *)option->name) != 0)) {
|
2016-08-18 10:32:27 +02:00
|
|
|
max_l = max(max_l, strlen((char *)option->name));
|
|
|
|
n_opts++;
|
2012-11-16 15:05:11 +01:00
|
|
|
}
|
2016-08-18 10:32:27 +02:00
|
|
|
|
2012-11-16 15:05:11 +01:00
|
|
|
option = next_cmos_entry(option);
|
|
|
|
}
|
2016-08-18 10:32:27 +02:00
|
|
|
|
|
|
|
if (n_opts == 0) {
|
2012-11-16 15:05:11 +01:00
|
|
|
printf("NO CMOS OPTIONS FOUND. EXITING!!!");
|
2016-08-18 10:32:27 +02:00
|
|
|
return -1;
|
2012-11-16 15:05:11 +01:00
|
|
|
}
|
|
|
|
|
2016-08-18 10:32:27 +02:00
|
|
|
*numopts = n_opts;
|
|
|
|
*maxlength = max_l;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* walk over options, fetch details */
|
|
|
|
static void cmos_walk_options(struct cb_cmos_option_table *opttbl,
|
|
|
|
FIELD **fields, int numopts, int maxlength)
|
|
|
|
{
|
|
|
|
struct cb_cmos_entries *option = first_cmos_entry(opttbl);
|
2017-01-20 23:29:21 +01:00
|
|
|
int i;
|
2016-08-18 10:32:27 +02:00
|
|
|
|
2017-01-20 23:29:21 +01:00
|
|
|
for (i = 0; i < numopts; i++) {
|
2016-04-24 01:24:57 +02:00
|
|
|
while ((option->config == 'r') ||
|
2016-04-26 20:33:44 +02:00
|
|
|
(strcmp("check_sum", (char *)option->name) == 0)) {
|
2012-11-16 15:05:11 +01:00
|
|
|
option = next_cmos_entry(option);
|
|
|
|
}
|
2016-04-24 01:24:57 +02:00
|
|
|
fields[2 * i] =
|
2016-04-26 20:33:44 +02:00
|
|
|
new_field(1, strlen((char *)option->name), i * 2, 1, 0, 0);
|
|
|
|
set_field_buffer(fields[2 * i], 0, (char *)option->name);
|
2016-04-24 01:24:57 +02:00
|
|
|
field_opts_off(fields[2 * i], O_ACTIVE);
|
2012-11-16 15:05:11 +01:00
|
|
|
|
2016-04-24 01:24:57 +02:00
|
|
|
fields[2 * i + 1] =
|
|
|
|
new_field(1, 40, i * 2, maxlength + 2, 0, 0);
|
2012-11-16 15:05:11 +01:00
|
|
|
char *buf = NULL;
|
2016-04-24 01:24:57 +02:00
|
|
|
int fail =
|
2016-04-26 20:33:44 +02:00
|
|
|
get_option_as_string(use_nvram, opttbl, &buf, (char *)option->name);
|
2012-11-16 15:05:11 +01:00
|
|
|
switch (option->config) {
|
|
|
|
case 'h': {
|
2016-04-24 01:24:57 +02:00
|
|
|
set_field_type(fields[2 * i + 1], TYPE_INTEGER, 0, 0,
|
|
|
|
(1 << option->length) - 1);
|
|
|
|
field_opts_on(fields[2 * i + 1], O_BLANK);
|
2012-11-16 15:05:11 +01:00
|
|
|
break;
|
2016-04-24 01:24:57 +02:00
|
|
|
}
|
2012-11-16 15:05:11 +01:00
|
|
|
case 's': {
|
2016-04-24 01:24:57 +02:00
|
|
|
set_max_field(fields[2 * i + 1], option->length / 8);
|
|
|
|
field_opts_off(fields[2 * i + 1], O_STATIC);
|
2012-11-16 15:05:11 +01:00
|
|
|
break;
|
2016-04-24 01:24:57 +02:00
|
|
|
}
|
2012-11-16 15:05:11 +01:00
|
|
|
case 'e': {
|
|
|
|
int numvals = 0;
|
2016-04-24 01:24:57 +02:00
|
|
|
struct cb_cmos_enums *cmos_enum =
|
|
|
|
first_cmos_enum_of_id(opttbl, option->config_id);
|
2012-11-16 15:05:11 +01:00
|
|
|
|
|
|
|
/* if invalid data in CMOS, set buf to first enum */
|
|
|
|
if (fail && cmos_enum) {
|
2016-04-26 20:33:44 +02:00
|
|
|
buf = (char *)cmos_enum->text;
|
2012-11-16 15:05:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while (cmos_enum) {
|
|
|
|
numvals++;
|
2016-04-24 01:24:57 +02:00
|
|
|
cmos_enum = next_cmos_enum_of_id(
|
|
|
|
cmos_enum, option->config_id);
|
2012-11-16 15:05:11 +01:00
|
|
|
}
|
|
|
|
|
2016-04-24 01:24:57 +02:00
|
|
|
char **values = malloc(sizeof(char *) * (numvals + 1));
|
2012-11-16 15:05:11 +01:00
|
|
|
int cnt = 0;
|
|
|
|
|
2016-04-24 01:24:57 +02:00
|
|
|
cmos_enum =
|
|
|
|
first_cmos_enum_of_id(opttbl, option->config_id);
|
2012-11-16 15:05:11 +01:00
|
|
|
while (cmos_enum) {
|
2016-04-26 20:33:44 +02:00
|
|
|
values[cnt] = (char *)cmos_enum->text;
|
2012-11-16 15:05:11 +01:00
|
|
|
cnt++;
|
2016-04-24 01:24:57 +02:00
|
|
|
cmos_enum = next_cmos_enum_of_id(
|
|
|
|
cmos_enum, option->config_id);
|
2012-11-16 15:05:11 +01:00
|
|
|
}
|
|
|
|
values[cnt] = NULL;
|
2016-04-24 01:24:57 +02:00
|
|
|
field_opts_off(fields[2 * i + 1], O_EDIT);
|
|
|
|
set_field_type(fields[2 * i + 1], TYPE_ENUM, values, 1,
|
|
|
|
1);
|
2012-11-16 15:05:11 +01:00
|
|
|
free(values); // copied by set_field_type
|
|
|
|
break;
|
2016-04-24 01:24:57 +02:00
|
|
|
}
|
2012-11-16 15:05:11 +01:00
|
|
|
default:
|
2016-04-24 01:24:57 +02:00
|
|
|
break;
|
2012-11-16 15:05:11 +01:00
|
|
|
}
|
2016-04-24 01:24:57 +02:00
|
|
|
if (buf)
|
|
|
|
set_field_buffer(fields[2 * i + 1], 0, buf);
|
2012-11-16 15:05:11 +01:00
|
|
|
#if HOSTED
|
2016-04-24 01:24:57 +02:00
|
|
|
// underline is non-trivial on VGA text
|
|
|
|
set_field_back(fields[2 * i + 1], A_UNDERLINE);
|
2012-11-16 15:05:11 +01:00
|
|
|
#endif
|
2016-04-24 01:24:57 +02:00
|
|
|
field_opts_off(fields[2 * i + 1],
|
|
|
|
O_BLANK | O_AUTOSKIP | O_NULLOK);
|
2012-11-16 15:05:11 +01:00
|
|
|
|
|
|
|
option = next_cmos_entry(option);
|
|
|
|
}
|
2016-08-18 10:32:27 +02:00
|
|
|
|
2016-04-24 01:24:57 +02:00
|
|
|
fields[2 * numopts] = NULL;
|
2016-08-18 10:32:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
int ch, done;
|
2017-01-20 23:29:21 +01:00
|
|
|
int i;
|
2016-08-18 10:32:27 +02:00
|
|
|
|
2017-03-13 17:56:17 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LP_USB))
|
|
|
|
usb_initialize();
|
2017-03-10 17:34:03 +01:00
|
|
|
|
2016-08-18 10:32:27 +02:00
|
|
|
/* coreboot data structures */
|
|
|
|
lib_get_sysinfo();
|
|
|
|
|
|
|
|
struct cb_cmos_option_table *opttbl = get_system_option_table();
|
|
|
|
|
2016-08-18 10:32:27 +02:00
|
|
|
if (opttbl == NULL) {
|
|
|
|
printf("Could not find coreboot option table.\n");
|
2016-08-18 10:32:27 +02:00
|
|
|
halt();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* prep CMOS layout into libcurses data structures */
|
|
|
|
|
|
|
|
struct cb_cmos_entries *option = first_cmos_entry(opttbl);
|
|
|
|
int numopts = 0;
|
|
|
|
int maxlength = 0;
|
|
|
|
|
|
|
|
count_cmos_options(option, &numopts, &maxlength);
|
|
|
|
|
|
|
|
FIELD **fields = malloc(sizeof(FIELD *) * (2 * numopts + 1));
|
|
|
|
|
|
|
|
cmos_walk_options(opttbl, fields, numopts, maxlength);
|
2012-11-16 15:05:11 +01:00
|
|
|
|
2015-02-24 20:33:35 +01:00
|
|
|
/* display initialization */
|
|
|
|
initscr();
|
|
|
|
keypad(stdscr, TRUE);
|
|
|
|
cbreak();
|
|
|
|
noecho();
|
|
|
|
|
|
|
|
if (start_color()) {
|
2016-04-24 01:24:57 +02:00
|
|
|
assume_default_colors(COLOR_BLUE, COLOR_CYAN);
|
2015-02-24 20:33:35 +01:00
|
|
|
}
|
|
|
|
leaveok(stdscr, TRUE);
|
|
|
|
curs_set(1);
|
|
|
|
|
|
|
|
erase();
|
|
|
|
box(stdscr, 0, 0);
|
|
|
|
mvaddstr(0, 2, "coreboot configuration utility");
|
|
|
|
refresh();
|
|
|
|
|
2012-11-16 15:05:11 +01:00
|
|
|
FORM *form = new_form(fields);
|
2016-04-24 01:24:57 +02:00
|
|
|
int numlines = min(numopts * 2, 16);
|
|
|
|
WINDOW *w = newwin(numlines + 2, 70, 2, 1);
|
|
|
|
WINDOW *inner_w = newpad(numopts * 2, 68);
|
2012-11-16 15:05:11 +01:00
|
|
|
box(w, 0, 0);
|
|
|
|
mvwaddstr(w, 0, 2, "Press F1 when done");
|
|
|
|
set_form_win(form, w);
|
|
|
|
set_form_sub(form, inner_w);
|
|
|
|
post_form(form);
|
|
|
|
|
|
|
|
done = 0;
|
2016-04-24 01:24:57 +02:00
|
|
|
while (!done) {
|
2015-02-01 15:24:43 +01:00
|
|
|
render_form(form);
|
2016-04-24 01:24:57 +02:00
|
|
|
ch = getch();
|
|
|
|
if (ch == ERR)
|
|
|
|
continue;
|
2012-11-16 15:05:11 +01:00
|
|
|
switch (ch) {
|
|
|
|
case KEY_DOWN:
|
|
|
|
form_driver(form, REQ_NEXT_FIELD);
|
|
|
|
break;
|
|
|
|
case KEY_UP:
|
|
|
|
form_driver(form, REQ_PREV_FIELD);
|
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
|
|
|
if (field_type(current_field(form)) == TYPE_ENUM) {
|
|
|
|
form_driver(form, REQ_PREV_CHOICE);
|
|
|
|
} else {
|
|
|
|
form_driver(form, REQ_LEFT_CHAR);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
if (field_type(current_field(form)) == TYPE_ENUM) {
|
|
|
|
form_driver(form, REQ_NEXT_CHOICE);
|
|
|
|
} else {
|
|
|
|
form_driver(form, REQ_RIGHT_CHAR);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
case '\b':
|
|
|
|
form_driver(form, REQ_DEL_PREV);
|
|
|
|
break;
|
|
|
|
case KEY_DC:
|
|
|
|
form_driver(form, REQ_DEL_CHAR);
|
|
|
|
break;
|
|
|
|
case KEY_F(1):
|
2016-04-24 01:24:57 +02:00
|
|
|
done = 1;
|
2012-11-16 15:05:11 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
form_driver(form, ch);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-24 20:33:35 +01:00
|
|
|
endwin();
|
|
|
|
|
2017-01-20 23:29:21 +01:00
|
|
|
for (i = 0; i < numopts; i++) {
|
2016-04-24 01:24:57 +02:00
|
|
|
char *name = field_buffer(fields[2 * i], 0);
|
|
|
|
char *value = field_buffer(fields[2 * i + 1], 0);
|
2014-01-15 22:07:52 +01:00
|
|
|
char *ptr;
|
2016-04-24 01:24:57 +02:00
|
|
|
for (ptr = value + strlen(value) - 1;
|
|
|
|
ptr >= value && *ptr == ' '; ptr--)
|
|
|
|
;
|
2014-01-15 22:07:52 +01:00
|
|
|
ptr[1] = '\0';
|
2012-11-16 15:05:11 +01:00
|
|
|
set_option_from_string(use_nvram, opttbl, value, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
unpost_form(form);
|
|
|
|
free_form(form);
|
|
|
|
|
2014-01-15 22:09:25 +01:00
|
|
|
/* reboot */
|
2016-04-24 01:24:57 +02:00
|
|
|
outb(0x6, 0xcf9);
|
2012-11-16 15:05:11 +01:00
|
|
|
halt();
|
|
|
|
}
|