kexec-tools: Fix option/argument parsing
Subsystems (2)
PATCH v2 1/1 kexec-tools: Fix option/argument parsing
Hi,
v2 changes:
- Fixed ARM's multiline KEXEC_ALL_OPTIONS #define
- Removed opterr=0 from main()'s getopts_long() scan, and handle unknown options in main() (as it now knows about all allowed opts). Previously it relied on the file_type->load()er parsing & complaining about unknown options; if the loader didn't parse them, no complaint.
Tested on x86, ppc and compile-tested on my new crisv32-axis-linux-gnu crosscompiler :-)
Cheers,
Matt
---
The argument parsing is currently a bit broken as main()'s getopt_long() knows nothing about either the architecture-specific options or, even more specifically, the architecture-and-loader-specific options.
This patch introduces new #defines for all architectures, KEXEC_ALL_OPTIONS and KEXEC_ALL_OPT_STR. These contain all possible options for a given build, and the getopt_long() passes in main() and arch_process_options() will now recognise arch- and loader-specific options; these will not be re-ordered in argv[], there is no confusion over which argv[] entry is the kernel filename, and using '--opt=foo' and '--opt foo' both work.
All architectures have command line options (and #define OPT_BLAHs) consolidated into their include/arch/option.h files. x86_64 builds parts of i386/ as well, so now both share a single option.h file (with a symlink).
--- kexec/arch/alpha/include/arch/options.h | 9 +++++ kexec/arch/arm/include/arch/options.h | 29 +++++++++++++++++ kexec/arch/arm/kexec-zImage-arm.c | 3 +- kexec/arch/cris/include/arch/options.h | 32 ++++++++++++++++-- kexec/arch/cris/kexec-elf-cris.c | 4 +- kexec/arch/i386/include/arch/options.h | 51 ++++++++++++++++++++++++++++++ kexec/arch/i386/kexec-beoboot-x86.c | 3 +- kexec/arch/i386/kexec-bzImage.c | 6 +-- kexec/arch/i386/kexec-elf-x86.c | 7 +--- kexec/arch/i386/kexec-multiboot-x86.c | 5 +-- kexec/arch/i386/kexec-x86.c | 4 +- kexec/arch/ia64/include/arch/options.h | 33 ++++++++++++++++++- kexec/arch/ia64/kexec-elf-ia64.c | 7 +--- kexec/arch/mips/include/arch/options.h | 27 +++++++++++++++- kexec/arch/mips/kexec-elf-mips.c | 3 +- kexec/arch/ppc/include/arch/options.h | 34 ++++++++++++++++++++ kexec/arch/ppc/kexec-dol-ppc.c | 4 +- kexec/arch/ppc/kexec-elf-ppc.c | 7 +--- kexec/arch/ppc/kexec-uImage-ppc.c | 6 +-- kexec/arch/ppc64/include/arch/options.h | 37 ++++++++++++++++++++- kexec/arch/ppc64/kexec-elf-ppc64.c | 12 ++++--- kexec/arch/ppc64/kexec-ppc64.c | 12 +++---- kexec/arch/s390/include/arch/options.h | 28 ++++++++++++++++- kexec/arch/s390/kexec-image.c | 4 +-- kexec/arch/sh/include/arch/options.h | 26 +++++++++++++-- kexec/arch/sh/kexec-sh.c | 7 +++- kexec/arch/x86_64/include/arch/options.h | 23 +------------- kexec/arch/x86_64/kexec-elf-x86_64.c | 7 +--- kexec/arch/x86_64/kexec-x86_64.c | 4 +- kexec/kexec.c | 6 ++-- 30 files changed, 341 insertions(+), 99 deletions(-) mode change 100644 => 120000 kexec/arch/x86_64/include/arch/options.h
kexec/arch/alpha/include/arch/options.h +9 -0
@@ -3,9 +3,18 @@#define OPT_ARCH_MAX (OPT_MAX+0) +/* Options relevant to the architecture (excluding loader-specific ones), +* in this case none: +*/ #define KEXEC_ARCH_OPTIONS \ KEXEC_OPTIONS \#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" +/* See the other architectures for details of these; Alpha has no +* loader-specific options yet. +*/ +#define KEXEC_ALL_OPTIONS KEXEC_ARCH_OPTIONS +#define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR +#endif /* KEXEC_ARCH_ALPHA_OPTIONS_H */
kexec/arch/arm/include/arch/options.h +29 -0
@@ -3,9 +3,38 @@#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_APPEND 'a' +#define OPT_RAMDISK 'r' + +/* Options relevant to the architecture (excluding loader-specific ones), +* in this case none: +*/ #define KEXEC_ARCH_OPTIONS \ KEXEC_OPTIONS \#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" +/* The following two #defines list ALL of the options added by all of the +* architecture's loaders. +* o main() uses this complete list to scan for its options, ignoring +* arch-specific/loader-specific ones. +* o Then, arch_process_options() uses this complete list to scan for its +* options, ignoring general/loader-specific ones. +* o Then, the file_type[n].load re-scans for options, using +* KEXEC_ARCH_OPTIONS plus its loader-specific options subset. +* Any unrecognised options cause an error here. +* +* This is done so that main()'s/arch_process_options()'s getopt_long() calls +* don't choose a kernel filename from random arguments to options they don't +* recognise -- as they now recognise (if not act upon) all possible options. +*/ +#define KEXEC_ALL_OPTIONS \ + KEXEC_ARCH_OPTIONS \ + { "command-line", 1, 0, OPT_APPEND }, \ + { "append", 1, 0, OPT_APPEND }, \ + { "initrd", 1, 0, OPT_RAMDISK }, \ + { "ramdisk", 1, 0, OPT_RAMDISK }, + +#define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR "a:r:" +#endif /* KEXEC_ARCH_ARM_OPTIONS_H */
kexec/arch/arm/kexec-zImage-arm.c +1 -2
@@ -219,8 +219,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,off_t ramdisk_length;off_t ramdisk_offset;int opt; -#define OPT_APPEND 'a' -#define OPT_RAMDISK 'r' +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS { "command-line", 1, 0, OPT_APPEND },
kexec/arch/cris/include/arch/options.h +28 -4
@@ -1,11 +1,35 @@ -#ifndef KEXEC_ARCH_MIPS_OPTIONS_H -#define KEXEC_ARCH_MIPS_OPTIONS_H +#ifndef KEXEC_ARCH_CRIS_OPTIONS_H +#define KEXEC_ARCH_CRIS_OPTIONS_H -#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_APPEND (OPT_ARCH_MAX+0) +/* Options relevant to the architecture (excluding loader-specific ones), +* in this case none: +*/ #define KEXEC_ARCH_OPTIONS \ KEXEC_OPTIONS \#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" -#endif /* KEXEC_ARCH_MIPS_OPTIONS_H */ +/* The following two #defines list ALL of the options added by all of the +* architecture's loaders. +* o main() uses this complete list to scan for its options, ignoring +* arch-specific/loader-specific ones. +* o Then, arch_process_options() uses this complete list to scan for its +* options, ignoring general/loader-specific ones. +* o Then, the file_type[n].load re-scans for options, using +* KEXEC_ARCH_OPTIONS plus its loader-specific options subset. +* Any unrecognised options cause an error here. +* +* This is done so that main()'s/arch_process_options()'s getopt_long() calls +* don't choose a kernel filename from random arguments to options they don't +* recognise -- as they now recognise (if not act upon) all possible options. +*/ +#define KEXEC_ALL_OPTIONS \ + KEXEC_ARCH_OPTIONS \ + {"append", 1, 0, OPT_APPEND}, + +#define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR + +#endif /* KEXEC_ARCH_CRIS_OPTIONS_H */
kexec/arch/cris/kexec-elf-cris.c +2 -2
@@ -40,8 +40,6 @@#include <arch/options.h> #include "kexec-cris.h" -#define OPT_APPEND (OPT_ARCH_MAX+0) -int elf_cris_probe (const char *buf,off_t len) {struct mem_ehdr ehdr;
@@ -89,8 +87,10 @@ int elf_cris_load(int argc, char **argv, const char *buf, off_t len,unsigned int regs[16 ]; } cris_regframe; +/* See options.h -- add any more there, too. */ static const struct option options[] = { KEXEC_ARCH_OPTIONS + {"append" ,1 ,0 ,OPT_APPEND }, {0 ,0 ,0 ,0 }, };
kexec/arch/i386/include/arch/options.h +51 -0
68 lines not on this page · raw message
kexec/arch/i386/kexec-beoboot-x86.c +2 -1
@@ -84,7 +84,8 @@ int beoboot_load(int argc, char **argv, const char *buf, off_t UNUSED(len),int debug, real_mode_entry;int opt;int result; -#define OPT_REAL_MODE (OPT_ARCH_MAX+0) + +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS { "debug", 0, 0, OPT_DEBUG },
kexec/arch/i386/kexec-bzImage.c +2 -4
@@ -341,10 +341,8 @@ int bzImage_load(int argc, char **argv, const char *buf, off_t len,int debug, real_mode_entry;int opt;int result; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) -#define OPT_RAMDISK (OPT_ARCH_MAX+2) -#define OPT_REAL_MODE (OPT_ARCH_MAX+3) + +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS { "debug", 0, 0, OPT_DEBUG },
kexec/arch/i386/kexec-elf-x86.c +1 -6
@@ -99,13 +99,8 @@ int elf_x86_load(int argc, char **argv, const char *buf, off_t len,#define ARG_STYLE_LINUX 1#define ARG_STYLE_NONE 2int opt; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) -#define OPT_RAMDISK (OPT_ARCH_MAX+2) -#define OPT_ARGS_ELF (OPT_ARCH_MAX+3) -#define OPT_ARGS_LINUX (OPT_ARCH_MAX+4) -#define OPT_ARGS_NONE (OPT_ARCH_MAX+5) +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS { "command-line", 1, NULL, OPT_APPEND },
kexec/arch/i386/kexec-multiboot-x86.c +1 -4
@@ -157,10 +157,7 @@ int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len,uint32_t u;int opt;int modules, mod_command_line_space; -#define OPT_CL (OPT_ARCH_MAX+0) -#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) -#define OPT_MOD (OPT_ARCH_MAX+2) -#define OPT_VGA (OPT_ARCH_MAX+3) +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS { "command-line", 1, 0, OPT_CL },
kexec/arch/i386/kexec-x86.c +2 -2
@@ -69,10 +69,10 @@ struct arch_options_t arch_options = {int arch_process_options (int argc,char **argv) {static const struct option options[] = { - KEXEC_ARCH_OPTIONS + KEXEC_ALL_OPTIONS {0 ,0 ,NULL ,0 }, }; -static const char short_options[] =KEXEC_ARCH_OPT_STR ; +static const char short_options[] =KEXEC_ALL_OPT_STR ;int opt;unsigned long value;char *end;
kexec/arch/ia64/include/arch/options.h +32 -1
@@ -1,11 +1,42 @@#ifndef KEXEC_ARCH_IA64_OPTIONS_H #define KEXEC_ARCH_IA64_OPTIONS_H -#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_RAMDISK (OPT_ARCH_MAX+1) +#define OPT_NOIO (OPT_ARCH_MAX+2) +#define OPT_VMM (OPT_ARCH_MAX+3) +/* Options relevant to the architecture (excluding loader-specific ones), +* in this case none: +*/ #define KEXEC_ARCH_OPTIONS \ KEXEC_OPTIONS \#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" +/* The following two #defines list ALL of the options added by all of the +* architecture's loaders. +* o main() uses this complete list to scan for its options, ignoring +* arch-specific/loader-specific ones. +* o Then, arch_process_options() uses this complete list to scan for its +* options, ignoring general/loader-specific ones. +* o Then, the file_type[n].load re-scans for options, using +* KEXEC_ARCH_OPTIONS plus its loader-specific options subset. +* Any unrecognised options cause an error here. +* +* This is done so that main()'s/arch_process_options()'s getopt_long() calls +* don't choose a kernel filename from random arguments to options they don't +* recognise -- as they now recognise (if not act upon) all possible options. +*/ +#define KEXEC_ALL_OPTIONS \ + KEXEC_ARCH_OPTIONS \ + {"command-line", 1, 0, OPT_APPEND}, \ + {"append", 1, 0, OPT_APPEND}, \ + {"initrd", 1, 0, OPT_RAMDISK}, \ + {"noio", 0, 0, OPT_NOIO}, \ + {"vmm", 1, 0, OPT_VMM}, \ + +#define KEXEC_ALL_OPT_STR KEXEC_OPT_STR +#endif /* KEXEC_ARCH_IA64_OPTIONS_H */
kexec/arch/ia64/kexec-elf-ia64.c +2 -5
@@ -45,11 +45,6 @@#include "crashdump-ia64.h" #include <arch/options.h> -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_NOIO (OPT_ARCH_MAX+2) -#define OPT_VMM (OPT_ARCH_MAX+3) -static const int probe_debug =0 ;extern unsigned long saved_efi_memmap_size;
@@ -136,6 +131,8 @@ int elf_ia64_load(int argc, char **argv, const char *buf, off_t len,int result;int opt;char *efi_memmap_buf, *boot_param; + +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS {"command-line", 1, 0, OPT_APPEND},
kexec/arch/mips/include/arch/options.h +26 -1
@@ -1,11 +1,36 @@#ifndef KEXEC_ARCH_MIPS_OPTIONS_H #define KEXEC_ARCH_MIPS_OPTIONS_H -#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_APPEND (OPT_ARCH_MAX+0) +/* Options relevant to the architecture (excluding loader-specific ones), +* in this case none: +*/ #define KEXEC_ARCH_OPTIONS \ KEXEC_OPTIONS \#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" +/* The following two #defines list ALL of the options added by all of the +* architecture's loaders. +* o main() uses this complete list to scan for its options, ignoring +* arch-specific/loader-specific ones. +* o Then, arch_process_options() uses this complete list to scan for its +* options, ignoring general/loader-specific ones. +* o Then, the file_type[n].load re-scans for options, using +* KEXEC_ARCH_OPTIONS plus its loader-specific options subset. +* Any unrecognised options cause an error here. +* +* This is done so that main()'s/arch_process_options()'s getopt_long() calls +* don't choose a kernel filename from random arguments to options they don't +* recognise -- as they now recognise (if not act upon) all possible options. +*/ +#define KEXEC_ALL_OPTIONS \ + KEXEC_ARCH_OPTIONS \ + {"command-line", 1, 0, OPT_APPEND}, \ + {"append", 1, 0, OPT_APPEND}, + +#define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR +#endif /* KEXEC_ARCH_MIPS_OPTIONS_H */
kexec/arch/mips/kexec-elf-mips.c +2 -1
@@ -35,7 +35,6 @@ static const int probe_debug = 0;#define BOOTLOADER "kexec"#define MAX_COMMAND_LINE 256#define UPSZ (X ) ((sizeof(X) + 3) & ~3) -#define OPT_APPEND (OPT_ARCH_MAX+0)static char cmdline_buf[256 ] ="kexec " ;int elf_mips_probe (const char *buf,off_t len)
@@ -82,6 +81,8 @@ int elf_mips_load(int argc, char **argv, const char *buf, off_t len,unsigned long cmdline_addr;size_t i;unsigned long bss_start =0 , bss_size =0 ; + +/* See options.h if adding any more options. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS {"command-line", 1, 0, OPT_APPEND},
kexec/arch/ppc/include/arch/options.h +34 -0
@@ -3,9 +3,43 @@#define OPT_ARCH_MAX (OPT_MAX+0) +/* All 'local' loader options: */ +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_GAMECUBE (OPT_ARCH_MAX+1) +#define OPT_DTB (OPT_ARCH_MAX+2) +#define OPT_NODES (OPT_ARCH_MAX+3) + +/* Options relevant to the architecture (excluding loader-specific ones), +* in this case none: +*/ #define KEXEC_ARCH_OPTIONS \ KEXEC_OPTIONS \#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" +/* The following two #defines list ALL of the options added by all of the +* architecture's loaders. +* o main() uses this complete list to scan for its options, ignoring +* arch-specific/loader-specific ones. +* o Then, arch_process_options() uses this complete list to scan for its +* options, ignoring general/loader-specific ones. +* o Then, the file_type[n].load re-scans for options, using +* KEXEC_ARCH_OPTIONS plus its loader-specific options subset. +* Any unrecognised options cause an error here. +* +* This is done so that main()'s/arch_process_options()'s getopt_long() calls +* don't choose a kernel filename from random arguments to options they don't +* recognise -- as they now recognise (if not act upon) all possible options. +*/ +#define KEXEC_ALL_OPTIONS \ + KEXEC_ARCH_OPTIONS \ + {"command-line", 1, 0, OPT_APPEND},\ + {"append", 1, 0, OPT_APPEND},\ + {"gamecube", 1, 0, OPT_GAMECUBE},\ + {"dtb", 1, 0, OPT_DTB},\ + {"reuse-node", 1, 0, OPT_NODES},\ + {"debug", 0, 0, OPT_DEBUG}, + +#define KEXEC_ALL_OPT_STR KEXEC_OPT_STR +#endif /* KEXEC_ARCH_PPC_OPTIONS_H */
kexec/arch/ppc/kexec-dol-ppc.c +2 -2
@@ -335,8 +335,8 @@ int dol_ppc_load(int argc, char **argv, const char *buf, off_t UNUSED(len),unsigned long lowest_start;int i, j, k;int opt; -#define OPT_APPEND (OPT_ARCH_MAX+0) +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS {"debug", 0, 0, OPT_DEBUG},
@@ -344,7 +344,7 @@ int dol_ppc_load(int argc, char **argv, const char *buf, off_t UNUSED(len), {"append", 1, 0, OPT_APPEND}, {0, 0, 0, 0}, }; -static const char short_options[] =KEXEC_ARCH_OPT_STR "d" ; +static const char short_options[] =KEXEC_ARCH_OPT_STR ;/* * Parse the command line arguments
kexec/arch/ppc/kexec-elf-ppc.c +2 -5
@@ -113,10 +113,7 @@ static void gamecube_hack_addresses(struct mem_ehdr *ehdr) } } -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_GAMECUBE (OPT_ARCH_MAX+1) -#define OPT_DTB (OPT_ARCH_MAX+2) -#define OPT_NODES (OPT_ARCH_MAX+3) +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS {"command-line", 1, 0, OPT_APPEND},
@@ -126,7 +123,7 @@ static const struct option options[] = { {"reuse-node", 1, 0, OPT_NODES}, {0, 0, 0, 0}, }; -static const char short_options[] =KEXEC_ARCH_OPT_STR "d" ; +static const char short_options[] =KEXEC_ARCH_OPT_STR ;void elf_ppc_usage (void ) {
kexec/arch/ppc/kexec-uImage-ppc.c +2 -4
@@ -14,9 +14,7 @@#include "fixup_dtb.h" #include <kexec-uImage.h> -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_DTB (OPT_ARCH_MAX+1) -#define OPT_NODES (OPT_ARCH_MAX+2) +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS {"command-line", 1, 0, OPT_APPEND},
@@ -25,7 +23,7 @@ static const struct option options[] = { {"reuse-node", 1, 0, OPT_NODES}, {0, 0, 0, 0}, }; -static const char short_options[] =KEXEC_ARCH_OPT_STR "d" ; +static const char short_options[] =KEXEC_ARCH_OPT_STR ;void uImage_ppc_usage (void ) {
kexec/arch/ppc64/include/arch/options.h +35 -2
@@ -1,13 +1,46 @@#ifndef KEXEC_ARCH_PPC64_OPTIONS_H #define KEXEC_ARCH_PPC64_OPTIONS_H -#define OPT_ARCH_MAX (OPT_MAX+0) -#define OPT_ELF64_CORE (OPT_MAX+1) +#define OPT_ELF64_CORE (OPT_MAX+0) +#define OPT_ARCH_MAX (OPT_MAX+1) +/* All 'local' loader options: */ +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_RAMDISK (OPT_ARCH_MAX+1) +#define OPT_DEVICETREEBLOB (OPT_ARCH_MAX+2) +#define OPT_ARGS_IGNORE (OPT_ARCH_MAX+3) + +/* Options relevant to the architecture (excluding loader-specific ones): */ #define KEXEC_ARCH_OPTIONS \ KEXEC_OPTIONS \ { "elf64-core-headers", 0, 0, OPT_ELF64_CORE }, \#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" +/* The following two #defines list ALL of the options added by all of the +* architecture's loaders. +* o main() uses this complete list to scan for its options, ignoring +* arch-specific/loader-specific ones. +* o Then, arch_process_options() uses this complete list to scan for its +* options, ignoring general/loader-specific ones. +* o Then, the file_type[n].load re-scans for options, using +* KEXEC_ARCH_OPTIONS plus its loader-specific options subset. +* Any unrecognised options cause an error here. +* +* This is done so that main()'s/arch_process_options()'s getopt_long() calls +* don't choose a kernel filename from random arguments to options they don't +* recognise -- as they now recognise (if not act upon) all possible options. +*/ +#define KEXEC_ALL_OPTIONS \ + KEXEC_ARCH_OPTIONS \ + { "command-line", 1, NULL, OPT_APPEND }, \ + { "append", 1, NULL, OPT_APPEND }, \ + { "ramdisk", 1, NULL, OPT_RAMDISK }, \ + { "initrd", 1, NULL, OPT_RAMDISK }, \ + { "devicetreeblob", 1, NULL, OPT_DEVICETREEBLOB }, \ + { "args-linux", 0, NULL, OPT_ARGS_IGNORE }, + +#define KEXEC_ALL_OPT_STR KEXEC_OPT_STR + +#endif /* KEXEC_ARCH_PPC64_OPTIONS_H */
kexec/arch/ppc64/kexec-elf-ppc64.c +7 -5
@@ -93,11 +93,7 @@ int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,uint32_t my_run_at_load;unsigned int slave_code[256 /sizeof (unsigned int )], master_entry; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_DEVICETREEBLOB (OPT_ARCH_MAX+2) -#define OPT_ARGS_IGNORE (OPT_ARCH_MAX+3) - +/* See options.h -- add any more there, too. */ static const struct option options[] = {KEXEC_ARCH_OPTIONS { "command-line", 1, NULL, OPT_APPEND },
@@ -347,5 +343,11 @@ int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,void elf_ppc64_usage (void ) { +fprintf (stderr," --command-line=<Command line> command line to append.\n" ); +fprintf (stderr," --append=<Command line> same as --command-line.\n" ); +fprintf (stderr," --ramdisk=<filename> Initial RAM disk.\n" ); +fprintf (stderr," --initrd=<filename> same as --ramdisk.\n" ); +fprintf (stderr," --devicetreeblob=<filename> Specify device tree blob file.\n" ); +fprintf (stderr,"elf support is still broken\n" ); }
kexec/arch/ppc64/kexec-ppc64.c +5 -7
@@ -735,11 +735,6 @@ int file_types = sizeof(file_type) / sizeof(file_type[0]);void arch_usage (void ) { -fprintf (stderr," --command-line=<Command line> command line to append.\n" ); -fprintf (stderr," --append=<Command line> same as --command-line.\n" ); -fprintf (stderr," --ramdisk=<filename> Initial RAM disk.\n" ); -fprintf (stderr," --initrd=<filename> same as --ramdisk.\n" ); -fprintf (stderr," --devicetreeblob=<filename> Specify device tree blob file.\n" );fprintf (stderr," --elf64-core-headers Prepare core headers in ELF64 format\n" ); }
@@ -749,11 +744,14 @@ struct arch_options_t arch_options = {int arch_process_options (int argc,char **argv) { +/* We look for all options so getopt_long doesn't start reordering +* argv[] before file_type[n].load() gets a look in. +*/ static const struct option options[] = { - KEXEC_ARCH_OPTIONS + KEXEC_ALL_OPTIONS {0 ,0 ,NULL ,0 }, }; -static const char short_options[] =KEXEC_ARCH_OPT_STR ; +static const char short_options[] =KEXEC_ALL_OPT_STR ;int opt; opterr =0 ;/* Don't complain about unrecognized options here */
kexec/arch/s390/include/arch/options.h +27 -1
@@ -1,11 +1,37 @@#ifndef KEXEC_ARCH_S390_OPTIONS_H #define KEXEC_ARCH_S390_OPTIONS_H -#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_APPEND OPT_MAX+0 +#define OPT_RAMDISK OPT_MAX+1 +/* Options relevant to the architecture (excluding loader-specific ones), +* in this case none: +*/ #define KEXEC_ARCH_OPTIONS \ KEXEC_OPTIONS \#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" +/* The following two #defines list ALL of the options added by all of the +* architecture's loaders. +* o main() uses this complete list to scan for its options, ignoring +* arch-specific/loader-specific ones. +* o Then, arch_process_options() uses this complete list to scan for its +* options, ignoring general/loader-specific ones. +* o Then, the file_type[n].load re-scans for options, using +* KEXEC_ARCH_OPTIONS plus its loader-specific options subset. +* Any unrecognised options cause an error here. +* +* This is done so that main()'s/arch_process_options()'s getopt_long() calls +* don't choose a kernel filename from random arguments to options they don't +* recognise -- as they now recognise (if not act upon) all possible options. +*/ +#define KEXEC_ALL_OPTIONS \ + KEXEC_ARCH_OPTIONS \ + {"command-line", 1, 0, OPT_APPEND}, \ + {"initrd", 1, 0, OPT_RAMDISK}, + +#define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR +#endif /* KEXEC_ARCH_S390_OPTIONS_H */
kexec/arch/s390/kexec-image.c +1 -3
@@ -19,9 +19,7 @@#include <getopt.h> #include "../../kexec.h" #include "kexec-s390.h" - -#define OPT_APPEND OPT_MAX+0 -#define OPT_RAMDISK OPT_MAX+1 +#include <arch/options.h> int image_s390_load(int argc, char **argv, const char *kernel_buf,
kexec/arch/sh/include/arch/options.h +23 -3
@@ -7,16 +7,36 @@#define OPT_NBSD_HOWTO (OPT_ARCH_MAX+3)#define OPT_NBSD_MROOT (OPT_ARCH_MAX+4) - +/* Options relevant to the architecture (excluding loader-specific ones): */ #define KEXEC_ARCH_OPTIONS \ KEXEC_OPTIONS \ {"command-line", 1, 0, OPT_APPEND}, \ {"append", 1, 0, OPT_APPEND}, \ {"empty-zero", 1, 0, OPT_APPEND}, \ {"howto", 1, 0, OPT_NBSD_HOWTO}, \ - {"miniroot", 1, 0, OPT_NBSD_MROOT}, \ - + {"miniroot", 1, 0, OPT_NBSD_MROOT}, +/* These options seem to be loader-specific rather than cris-specific, so +* ought to be moved to KEXEC_ALL_OPTIONS below and parsed in the relevant +* loader, e.g. kexec-netbsd-sh.c +*/ #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" +/* The following two #defines list ALL of the options added by all of the +* architecture's loaders. +* o main() uses this complete list to scan for its options, ignoring +* arch-specific/loader-specific ones. +* o Then, arch_process_options() uses this complete list to scan for its +* options, ignoring general/loader-specific ones. +* o Then, the file_type[n].load re-scans for options, using +* KEXEC_ARCH_OPTIONS plus its loader-specific options subset. +* Any unrecognised options cause an error here. +* +* This is done so that main()'s/arch_process_options()'s getopt_long() calls +* don't choose a kernel filename from random arguments to options they don't +* recognise -- as they now recognise (if not act upon) all possible options. +*/ +#define KEXEC_ALL_OPTIONS KEXEC_ARCH_OPTIONS +#define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR +#endif /* KEXEC_ARCH_SH_OPTIONS_H */
kexec/arch/sh/kexec-sh.c +6 -1
@@ -97,8 +97,13 @@ void arch_usage(void)int arch_process_options (int argc,char **argv) { +/* The common options amongst loaders (e.g. --append) should be read +* here, and the loader-specific options (e.g. NetBSD stuff) should +* then be re-parsed in the loader. +* (e.g. in kexec-netbsd-sh.c, for example.) +*/ static const struct option options[] = { - KEXEC_ARCH_OPTIONS + KEXEC_ALL_OPTIONS {0 ,0 ,NULL ,0 }, };static const char short_options[] =KEXEC_ARCH_OPT_STR ;
kexec/arch/x86_64/include/arch/options.h deleted +0 -22
@@ -1,22 +0,0 @@ -#ifndef KEXEC_ARCH_X86_64_OPTIONS_H -#define KEXEC_ARCH_X86_64_OPTIONS_H - -#define OPT_RESET_VGA (OPT_MAX+0) -#define OPT_SERIAL (OPT_MAX+1) -#define OPT_SERIAL_BAUD (OPT_MAX+2) -#define OPT_CONSOLE_VGA (OPT_MAX+3) -#define OPT_CONSOLE_SERIAL (OPT_MAX+4) -#define OPT_ARCH_MAX (OPT_MAX+5) - -#define KEXEC_ARCH_OPTIONS \ - KEXEC_OPTIONS \ - { "reset-vga", 0, 0, OPT_RESET_VGA }, \ - { "serial", 1, 0, OPT_SERIAL }, \ - { "serial-baud", 1, 0, OPT_SERIAL_BAUD }, \ - { "console-vga", 0, 0, OPT_CONSOLE_VGA }, \ - { "console-serial", 0, 0, OPT_CONSOLE_SERIAL }, \ - -#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" - -#endif /* KEXEC_ARCH_X86_64_OPTIONS_H */ -
kexec/arch/x86_64/include/arch/options.h new file +1 -0
@@ -0,0 +1 @@ +../../../i386/include/arch/options.h
kexec/arch/x86_64/kexec-elf-x86_64.c +1 -6
@@ -98,13 +98,8 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,#define ARG_STYLE_LINUX 1#define ARG_STYLE_NONE 2int opt; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) -#define OPT_RAMDISK (OPT_ARCH_MAX+2) -#define OPT_ARGS_ELF (OPT_ARCH_MAX+3) -#define OPT_ARGS_LINUX (OPT_ARCH_MAX+4) -#define OPT_ARGS_NONE (OPT_ARCH_MAX+5) +/* See options.h and add any new options there too! */ static const struct option options[] = {KEXEC_ARCH_OPTIONS { "command-line", 1, NULL, OPT_APPEND },
kexec/arch/x86_64/kexec-x86_64.c +2 -2
@@ -74,10 +74,10 @@ static struct {int arch_process_options (int argc,char **argv) {static const struct option options[] = { - KEXEC_ARCH_OPTIONS + KEXEC_ALL_OPTIONS {0 ,0 ,NULL ,0 }, }; -static const char short_options[] =KEXEC_ARCH_OPT_STR ; +static const char short_options[] =KEXEC_ALL_OPT_STR ;int opt;unsigned long value;char *end;
kexec/kexec.c +3 -3
@@ -1062,17 +1062,17 @@ int main(int argc, char *argv[])int result =0 ;int fileind;static const struct option options[] = { - KEXEC_ARCH_OPTIONS + KEXEC_ALL_OPTIONS {0 ,0 ,0 ,0 }, }; -static const char short_options[] =KEXEC_OPT_STR ; +static const char short_options[] =KEXEC_ALL_OPT_STR ;arch_init (); - opterr =0 ;/* Don't complain about unrecognized options here */ while ((opt =getopt_long (argc, argv, short_options, options,0 )) !=-1 ) {switch (opt) { +case '?' :case OPT_HELP :usage ();return 0 ;
Signature · 7 lines
1.6.3.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 39 lines · Matt Evans
Hi,
v2 changes:
- Fixed ARM's multilineKEXEC_ALL_OPTIONS#define
- Removed opterr=0 from main()'sgetopts_long()scan, and handle unknown options inmain()(as it now knows about all allowed opts). Previously it relied on the file_type->load()er parsing & complaining about unknown options; if the loader didn't parse them, no complaint.Tested on x86, ppc and compile-tested on my new crisv32-axis-linux-gnu crosscompiler :-)
Cheers,
Matt
---
The argument parsing is currently a bit broken as main()'sgetopt_long()knows nothing about either the architecture-specific options or, even more specifically, the architecture-and-loader-specific options.This patch introduces new #defines for all architectures,
KEXEC_ALL_OPTIONSandKEXEC_ALL_OPT_STR. These contain all possible options for a given build, and thegetopt_long()passes inmain()andarch_process_options()will now recognise arch- and loader-specific options; these will not be re-ordered in argv[], there is no confusion over which argv[] entry is the kernel filename, and using '--opt=foo' and '--opt foo' both work.All architectures have command line options (and #define
OPT_BLAHs) consolidated into theirinclude/arch/option.hfiles.x86_64builds parts of i386/ as well, so now both share a singleoption.hfile (with a symlink).Signed-off-by Matt Evans <[email protected]>---
[snip]
Quoted 11 lines
kexec/arch/sh/include/arch/options.h +1
-1@@ -7,16 +7,36 @@#define OPT_NBSD_HOWTO (OPT_ARCH_MAX+3)#define OPT_NBSD_MROOT (OPT_ARCH_MAX+4) - +/* Options relevant to the architecture (excluding loader-specific ones): */ #define KEXEC_ARCH_OPTIONS \
kexec/arch/sh/include/arch/options.h line 19
Quoted 10 lines
kexec/arch/sh/include/arch/options.h +3
-2KEXEC_OPTIONS \ {"command-line", 1, 0, OPT_APPEND}, \ {"append", 1, 0, OPT_APPEND}, \ {"empty-zero", 1, 0, OPT_APPEND}, \ {"howto", 1, 0, OPT_NBSD_HOWTO}, \ - {"miniroot", 1, 0, OPT_NBSD_MROOT}, \ - + {"miniroot", 1, 0, OPT_NBSD_MROOT}, +/* These options seem to be loader-specific rather than cris-specific, so +* ought to be moved to KEXEC_ALL_OPTIONS below and parsed in the relevant
The line above has a trailing space.
Quoted 23 lines
kexec/arch/sh/include/arch/options.h +19
-0+* loader, e.g. kexec-netbsd-sh.c +*/ #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" +/* The following two #defines list ALL of the options added by all of the +* architecture's loaders. +* o main() uses this complete list to scan for its options, ignoring +* arch-specific/loader-specific ones. +* o Then, arch_process_options() uses this complete list to scan for its +* options, ignoring general/loader-specific ones. +* o Then, the file_type[n].load re-scans for options, using +* KEXEC_ARCH_OPTIONS plus its loader-specific options subset. +* Any unrecognised options cause an error here. +* +* This is done so that main()'s/arch_process_options()'s getopt_long() calls +* don't choose a kernel filename from random arguments to options they don't +* recognise -- as they now recognise (if not act upon) all possible options. +*/ +#define KEXEC_ALL_OPTIONS KEXEC_ARCH_OPTIONS +#define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR +#endif /* KEXEC_ARCH_SH_OPTIONS_H */
[snip]
Quoted 34 lines
kexec/arch/x86_64/include/arch/options.h deleted +0
-22@@ -1,22 +0,0 @@ -#ifndef KEXEC_ARCH_X86_64_OPTIONS_H -#define KEXEC_ARCH_X86_64_OPTIONS_H - -#define OPT_RESET_VGA (OPT_MAX+0) -#define OPT_SERIAL (OPT_MAX+1) -#define OPT_SERIAL_BAUD (OPT_MAX+2) -#define OPT_CONSOLE_VGA (OPT_MAX+3) -#define OPT_CONSOLE_SERIAL (OPT_MAX+4) -#define OPT_ARCH_MAX (OPT_MAX+5) - -#define KEXEC_ARCH_OPTIONS \ - KEXEC_OPTIONS \ - { "reset-vga", 0, 0, OPT_RESET_VGA }, \ - { "serial", 1, 0, OPT_SERIAL }, \ - { "serial-baud", 1, 0, OPT_SERIAL_BAUD }, \ - { "console-vga", 0, 0, OPT_CONSOLE_VGA }, \ - { "console-serial", 0, 0, OPT_CONSOLE_SERIAL }, \ - -#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" - -#endif /* KEXEC_ARCH_X86_64_OPTIONS_H */ -kexec/arch/x86_64/include/arch/options.h new file +0
-0
kexec/arch/x86_64/include/arch/options.h line 1
Quoted 2 lines
kexec/arch/x86_64/include/arch/options.h new file +1
-0@@ -0,0 +1 @@ +../../../i386/include/arch/options.h
The fragment above seems to a) belong in the previous fragment and
b) be bogus. In any case x86_64 fails to build.
kexec/kexec.c: In function 'main':kexec/kexec.c:1061: error: 'KEXEC_ALL_OPTIONS' undeclared (first use in this function)
...
[snip]
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Howdy Simon,
Quoted 44 lines · Simon Horman
On Fri, May 14, 2010 at 02:15:09PM +1000, Matt Evans wrote:
[snip]
Quoted 34 lines
kexec/arch/x86_64/include/arch/options.h deleted +0
-22@@ -1,22 +0,0 @@ -#ifndef KEXEC_ARCH_X86_64_OPTIONS_H -#define KEXEC_ARCH_X86_64_OPTIONS_H - -#define OPT_RESET_VGA (OPT_MAX+0) -#define OPT_SERIAL (OPT_MAX+1) -#define OPT_SERIAL_BAUD (OPT_MAX+2) -#define OPT_CONSOLE_VGA (OPT_MAX+3) -#define OPT_CONSOLE_SERIAL (OPT_MAX+4) -#define OPT_ARCH_MAX (OPT_MAX+5) - -#define KEXEC_ARCH_OPTIONS \ - KEXEC_OPTIONS \ - { "reset-vga", 0, 0, OPT_RESET_VGA }, \ - { "serial", 1, 0, OPT_SERIAL }, \ - { "serial-baud", 1, 0, OPT_SERIAL_BAUD }, \ - { "console-vga", 0, 0, OPT_CONSOLE_VGA }, \ - { "console-serial", 0, 0, OPT_CONSOLE_SERIAL }, \ - -#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" - -#endif /* KEXEC_ARCH_X86_64_OPTIONS_H */ -kexec/arch/x86_64/include/arch/options.h new file +0
-0kexec/arch/x86_64/include/arch/options.h line 1
Quoted 2 lines
kexec/arch/x86_64/include/arch/options.h new file +1
-0@@ -0,0 +1 @@ +../../../i386/include/arch/options.hThe fragment above seems to a) belong in the previous fragment and
b) be bogus. In any casex86_64fails to build.
Quoted 2 lines
kexec/kexec.c: In function 'main':kexec/kexec.c:1061: error: 'KEXEC_ALL_OPTIONS' undeclared (first use in this function)
Well, a bit weird but not bogus: It's a type change chunk (see 'new file mode'), replacing kexec/arch/x86_64/include/arch/options.h with a symlink to kexec/arch/i386/include/arch/options.h.
I've tested it applies cleanly with git-apply, and builds on x86-64 -- are you applying it with patch?
I used a symlink, though grotty, as many places look to include <arch/options.h> and the x86-64/i386 builds essentially have the same set of options.
I'll repost the patch without the trailing whitespace (oops) but if there's a better way to do this let me know & I'll include that instead.
Cheers,
Matt
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 48 lines · Matt Evans
Howdy Simon,
Quoted 44 lines · Simon Horman
On Fri, May 14, 2010 at 02:15:09PM +1000, Matt Evans wrote:
[snip]
Quoted 34 lines
kexec/arch/x86_64/include/arch/options.h deleted +0
-22@@ -1,22 +0,0 @@ -#ifndef KEXEC_ARCH_X86_64_OPTIONS_H -#define KEXEC_ARCH_X86_64_OPTIONS_H - -#define OPT_RESET_VGA (OPT_MAX+0) -#define OPT_SERIAL (OPT_MAX+1) -#define OPT_SERIAL_BAUD (OPT_MAX+2) -#define OPT_CONSOLE_VGA (OPT_MAX+3) -#define OPT_CONSOLE_SERIAL (OPT_MAX+4) -#define OPT_ARCH_MAX (OPT_MAX+5) - -#define KEXEC_ARCH_OPTIONS \ - KEXEC_OPTIONS \ - { "reset-vga", 0, 0, OPT_RESET_VGA }, \ - { "serial", 1, 0, OPT_SERIAL }, \ - { "serial-baud", 1, 0, OPT_SERIAL_BAUD }, \ - { "console-vga", 0, 0, OPT_CONSOLE_VGA }, \ - { "console-serial", 0, 0, OPT_CONSOLE_SERIAL }, \ - -#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" - -#endif /* KEXEC_ARCH_X86_64_OPTIONS_H */ -kexec/arch/x86_64/include/arch/options.h new file +0
-0kexec/arch/x86_64/include/arch/options.h line 1
Quoted 2 lines
kexec/arch/x86_64/include/arch/options.h new file +1
-0@@ -0,0 +1 @@ +../../../i386/include/arch/options.hThe fragment above seems to a) belong in the previous fragment and
b) be bogus. In any casex86_64fails to build.
Quoted 6 lines
Quoted 2 lines
kexec/kexec.c: In function 'main':kexec/kexec.c:1061: error: 'KEXEC_ALL_OPTIONS' undeclared (first use in this function)Well, a bit weird but not bogus: It's a type change chunk (see 'new file mode'), replacing
kexec/arch/x86_64/include/arch/options.hwith a symlink tokexec/arch/i386/include/arch/options.h.I've tested it applies cleanly with git-apply, and builds on x86-64 -- are you applying it with patch?
Yes, I thats was the cause of my problems :-)
I'm using git-apply now and everything seems fine and dandy. I'll apply the change if the current builds succeed.
Quoted 3 lines
I used a symlink, though grotty, as many places look to include <
arch/options.h> and the x86-64/i386 builds essentially have the same set of options.I'll repost the patch without the trailing whitespace (oops) but if there's a better way to do this let me know & I'll include that instead.
I can fix the white-space, no need to repost at this stage.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 52 lines · Simon Horman
Quoted 51 lines · Matt Evans
Howdy Simon,
Quoted 46 lines · Simon Horman
On Fri, May 14, 2010 at 02:15:09PM +1000, Matt Evans wrote:
[snip]
Quoted 34 lines
kexec/arch/x86_64/include/arch/options.h deleted +0
-22@@ -1,22 +0,0 @@ -#ifndef KEXEC_ARCH_X86_64_OPTIONS_H -#define KEXEC_ARCH_X86_64_OPTIONS_H - -#define OPT_RESET_VGA (OPT_MAX+0) -#define OPT_SERIAL (OPT_MAX+1) -#define OPT_SERIAL_BAUD (OPT_MAX+2) -#define OPT_CONSOLE_VGA (OPT_MAX+3) -#define OPT_CONSOLE_SERIAL (OPT_MAX+4) -#define OPT_ARCH_MAX (OPT_MAX+5) - -#define KEXEC_ARCH_OPTIONS \ - KEXEC_OPTIONS \ - { "reset-vga", 0, 0, OPT_RESET_VGA }, \ - { "serial", 1, 0, OPT_SERIAL }, \ - { "serial-baud", 1, 0, OPT_SERIAL_BAUD }, \ - { "console-vga", 0, 0, OPT_CONSOLE_VGA }, \ - { "console-serial", 0, 0, OPT_CONSOLE_SERIAL }, \ - -#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR "" - -#endif /* KEXEC_ARCH_X86_64_OPTIONS_H */ -kexec/arch/x86_64/include/arch/options.h new file +0
-0kexec/arch/x86_64/include/arch/options.h line 1
Quoted 2 lines
kexec/arch/x86_64/include/arch/options.h new file +1
-0@@ -0,0 +1 @@ +../../../i386/include/arch/options.hThe fragment above seems to a) belong in the previous fragment and
b) be bogus. In any casex86_64fails to build.
kexec/kexec.c: In function 'main':kexec/kexec.c:1061: error: 'KEXEC_ALL_OPTIONS' undeclared (first use in this function)
Quoted 7 lines
Quoted 3 lines
Well, a bit weird but not bogus: It's a type change chunk (see 'new file mode'), replacing
kexec/arch/x86_64/include/arch/options.hwith a symlink tokexec/arch/i386/include/arch/options.h.I've tested it applies cleanly with git-apply, and builds on x86-64 -- are you applying it with patch?
Yes, I thats was the cause of my problems :-)
I'm using git-apply now and everything seems fine and dandy. I'll apply the change if the current builds succeed.
They did succeed and I've pushed the change.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec