Add nvramtool -D option that allows taking cmos data from
a plain binary file. Overrides using cmos.default in CBFS if both -C and -D are given. Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com> Acked-by: Stefan Reinauer <stepan@coreboot.org> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@6286 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
parent
269e932340
commit
202be7b6b7
|
@ -82,7 +82,8 @@ void usage(FILE * outfile)
|
||||||
"LAYOUT_FILE.\n"
|
"LAYOUT_FILE.\n"
|
||||||
" -t: Use CMOS layout specified by CMOS option "
|
" -t: Use CMOS layout specified by CMOS option "
|
||||||
"table.\n"
|
"table.\n"
|
||||||
" -C CBFS_FILE: Use CBFS file for layout and CMOS defaults.\n"
|
" -C CBFS_FILE: Use CBFS file for layout and CMOS data.\n"
|
||||||
|
" -D CMOS_FILE: Use CMOS file for CMOS data (overrides CMOS of -C).\n"
|
||||||
" [-n] -r NAME: Show parameter NAME. If -n is given, "
|
" [-n] -r NAME: Show parameter NAME. If -n is given, "
|
||||||
"show value only.\n"
|
"show value only.\n"
|
||||||
" -e NAME: Show all possible values for parameter "
|
" -e NAME: Show all possible values for parameter "
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
\*****************************************************************************/
|
\*****************************************************************************/
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "opts.h"
|
#include "opts.h"
|
||||||
#include "lbtable.h"
|
#include "lbtable.h"
|
||||||
|
@ -93,6 +97,7 @@ static const hexdump_format_t cmos_dump_format =
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
void *cmos_default = NULL;
|
||||||
cmos_layout_get_fn_t fn = get_layout_from_cmos_table;
|
cmos_layout_get_fn_t fn = get_layout_from_cmos_table;
|
||||||
|
|
||||||
parse_nvramtool_args(argc, argv);
|
parse_nvramtool_args(argc, argv);
|
||||||
|
@ -105,12 +110,38 @@ int main(int argc, char *argv[])
|
||||||
fn = get_layout_from_cmos_table;
|
fn = get_layout_from_cmos_table;
|
||||||
} else if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CBFS_FILE].found) {
|
} else if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CBFS_FILE].found) {
|
||||||
open_cbfs(nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CBFS_FILE].param);
|
open_cbfs(nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CBFS_FILE].param);
|
||||||
void *cmosdefault = cbfs_find_file("cmos.default", CBFS_COMPONENT_CMOS_DEFAULT, NULL);
|
if (!nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].found) {
|
||||||
if (cmosdefault == NULL) {
|
cmos_default = cbfs_find_file("cmos.default", CBFS_COMPONENT_CMOS_DEFAULT, NULL);
|
||||||
printf("Need a cmos.default in the CBFS image for now.\n");
|
if (cmos_default == NULL) {
|
||||||
|
fprintf(stderr, "Need a cmos.default in the CBFS image or separate cmos file (-D).\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].found) {
|
||||||
|
int fd;
|
||||||
|
struct stat fd_stat;
|
||||||
|
if ((fd = open(nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param, O_RDWR | O_CREAT, 0666)) < 0) {
|
||||||
|
fprintf(stderr, "Couldn't open '%s'\n", nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
select_hal(HAL_MEMORY, cmosdefault);
|
if (fstat(fd, &fd_stat) == -1) {
|
||||||
|
fprintf(stderr, "Couldn't stat '%s'\n", nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (fd_stat.st_size < 128) {
|
||||||
|
lseek(fd, 127, SEEK_SET);
|
||||||
|
write(fd, "\0", 1);
|
||||||
|
fsync(fd);
|
||||||
|
}
|
||||||
|
cmos_default = mmap(NULL, 128, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
|
if (cmos_default == MAP_FAILED) {
|
||||||
|
fprintf(stderr, "Couldn't map '%s'\n", nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cmos_default) {
|
||||||
|
select_hal(HAL_MEMORY, cmos_default);
|
||||||
fn = get_layout_from_cbfs_file;
|
fn = get_layout_from_cbfs_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ static void register_op_modifier(nvramtool_op_modifier_t mod, char mod_param[]);
|
||||||
static void resolve_op_modifiers(void);
|
static void resolve_op_modifiers(void);
|
||||||
static void sanity_check_args(void);
|
static void sanity_check_args(void);
|
||||||
|
|
||||||
static const char getopt_string[] = "-ab:B:c::C:de:hil::np:r:tvw:xX:y:Y";
|
static const char getopt_string[] = "-ab:B:c::C:dD:e:hil::np:r:tvw:xX:y:Y";
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* parse_nvramtool_args
|
* parse_nvramtool_args
|
||||||
|
@ -89,6 +89,10 @@ void parse_nvramtool_args(int argc, char *argv[])
|
||||||
case 'd':
|
case 'd':
|
||||||
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_DUMP, NULL);
|
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_DUMP, NULL);
|
||||||
break;
|
break;
|
||||||
|
case 'D':
|
||||||
|
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_FILE,
|
||||||
|
optarg);
|
||||||
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_PARAM_VALUES,
|
register_op(&op_found, NVRAMTOOL_OP_SHOW_PARAM_VALUES,
|
||||||
optarg);
|
optarg);
|
||||||
|
|
|
@ -59,6 +59,7 @@ typedef struct {
|
||||||
typedef enum { NVRAMTOOL_MOD_SHOW_VALUE_ONLY = 0,
|
typedef enum { NVRAMTOOL_MOD_SHOW_VALUE_ONLY = 0,
|
||||||
NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE,
|
NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE,
|
||||||
NVRAMTOOL_MOD_USE_CBFS_FILE,
|
NVRAMTOOL_MOD_USE_CBFS_FILE,
|
||||||
|
NVRAMTOOL_MOD_USE_CMOS_FILE,
|
||||||
NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE,
|
NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE,
|
||||||
NVRAMTOOL_NUM_OP_MODIFIERS /* must always be last */
|
NVRAMTOOL_NUM_OP_MODIFIERS /* must always be last */
|
||||||
} nvramtool_op_modifier_t;
|
} nvramtool_op_modifier_t;
|
||||||
|
|
Loading…
Reference in New Issue