* main ****************************************************************************/
| 89 | * main |
| 90 | ****************************************************************************/ |
| 91 | int main(int argc, char *argv[]) |
| 92 | { |
| 93 | void *cmos_default = NULL; |
| 94 | cmos_layout_get_fn_t fn = get_layout_from_cmos_table; |
| 95 | |
| 96 | parse_nvramtool_args(argc, argv); |
| 97 | |
| 98 | /* If we should operate on a CBFS file default to reading the layout |
| 99 | * and CMOS contents from it. */ |
| 100 | if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CBFS_FILE].found) { |
| 101 | open_cbfs(nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CBFS_FILE].param); |
| 102 | if (!nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].found) { |
| 103 | cmos_default = cbfs_find_file("cmos.default", CBFS_COMPONENT_CMOS_DEFAULT, NULL); |
| 104 | if (cmos_default == NULL) { |
| 105 | fprintf(stderr, "Need a cmos.default in the CBFS image or separate CMOS file (-D).\n"); |
| 106 | exit(1); |
| 107 | } |
| 108 | } |
| 109 | fn = get_layout_from_cbfs_file; |
| 110 | } |
| 111 | |
| 112 | /* If the user wants to use a specific layout file or explicitly use |
| 113 | * the coreboot option table allow him to override previous settings. */ |
| 114 | if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found) { |
| 115 | set_layout_filename(nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].param); |
| 116 | fn = get_layout_from_file; |
| 117 | } else if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found) { |
| 118 | fn = get_layout_from_cmos_table; |
| 119 | } |
| 120 | |
| 121 | /* Allow the user to use a file for the CMOS contents, possibly |
| 122 | * overriding a previously opened "cmos.default" file from the CBFS. */ |
| 123 | if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].found) { |
| 124 | struct stat fd_stat; |
| 125 | int fd; |
| 126 | |
| 127 | if ((fd = open(nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param, O_RDWR | O_CREAT, 0666)) < 0) { |
| 128 | fprintf(stderr, "Couldn't open '%s'\n", nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param); |
| 129 | exit(1); |
| 130 | } |
| 131 | |
| 132 | if (fstat(fd, &fd_stat) == -1) { |
| 133 | fprintf(stderr, "Couldn't stat '%s'\n", nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param); |
| 134 | exit(1); |
| 135 | } |
| 136 | |
| 137 | if (fd_stat.st_size < CMOS_SIZE) { |
| 138 | if ((lseek(fd, CMOS_SIZE - 1, SEEK_SET) == -1) || |
| 139 | (write(fd, "\0", 1) != 1)) { |
| 140 | fprintf(stderr, "Unable to extended '%s' to its full size.\n", |
| 141 | nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param); |
| 142 | exit(1); |
| 143 | } |
| 144 | #ifndef __MINGW32__ |
| 145 | fsync(fd); |
| 146 | #else |
| 147 | FlushFileBuffers ((HANDLE) _get_osfhandle (fd)); |
| 148 | #endif |
nothing calls this directly
no test coverage detected