@@ -405,7 +405,6 @@ static bool parse_options(int argc, char *argv[])
case 'b':
if (strcmp(optarg, "fsi") == 0) {
backend = FSI;
- device_node = "p9w";
} else if (strcmp(optarg, "i2c") == 0) {
backend = I2C;
} else if (strcmp(optarg, "kernel") == 0) {
@@ -418,6 +417,7 @@ static bool parse_options(int argc, char *argv[])
backend = HOST;
} else {
fprintf(stderr, "Invalid backend '%s'\n", optarg);
+ print_backends(stderr);
opt_error = true;
}
break;
@@ -630,7 +630,7 @@ static int target_selection(void)
case KERNEL:
if (device_node == NULL) {
PR_ERROR("kernel backend requires a device type\n");
- return -1;
+ return -1;
}
if (!strcmp(device_node, "p8"))
pdbg_targets_init(&_binary_p8_kernel_dtb_o_start);
@@ -662,7 +662,9 @@ static int target_selection(void)
break;
default:
- PR_ERROR("Invalid backend specified\n");
+ /* parse_options deals with parsing user input, so it should be
+ * impossible to get here */
+ assert(0);
return -1;
}
@@ -797,29 +799,18 @@ int main(int argc, char *argv[])
optcmd_cmd_t *cmd;
backend = default_backend();
- device_node = default_target(backend);
if (!parse_options(argc, argv))
return 1;
- if (!backend_is_possible(backend)) {
- fprintf(stderr, "Backend not possible\nUse: ");
- print_backends(stderr);
- return 1;
- }
-
- if (!target_is_possible(backend, device_node)) {
- fprintf(stderr, "Target %s not possible\n",
- device_node ? device_node : "(none)");
- print_targets(stderr);
- return 1;
- }
-
if (optind >= argc) {
print_usage(basename(argv[0]));
return 1;
}
+ if (!device_node)
+ device_node = default_target(backend);
+
/* Disable unselected targets */
if (target_selection())
return 1;
@@ -20,17 +20,8 @@ enum backend default_backend(void);
/* Print all possible backends on this platform */
void print_backends(FILE *stream);
-/* Is this backend possible on this platform */
-bool backend_is_possible(enum backend backend);
-
/* The default (perhaps only) target for this backend */
const char *default_target(enum backend backend);
/* Print all possible targets on this platform */
void print_targets(FILE *stream);
-
-/*
- * Does this platform backend support this target,
- * there is an implied check of is_backend_possible()
- */
-bool target_is_possible(enum backend backend, const char *target);
@@ -22,11 +22,6 @@
#define AMI_BMC "/proc/ractrends/Helper/FwInfo"
#define OPENFSI_BMC "/sys/bus/platform/devices/gpio-fsi/fsi0/"
-static const char witherspoon[] = "p9w";
-static const char romulus[] = "p9r";
-static const char zaius[] = "p9z";
-static const char p8[] = "p8";
-
enum backend default_backend(void)
{
int rc;
@@ -43,17 +38,7 @@ enum backend default_backend(void)
void print_backends(FILE *stream)
{
- fprintf(stream, "Valid backends: i2c kernel fsi\n");
-}
-
-bool backend_is_possible(enum backend backend)
-{
- if (backend == I2C)
- return true;
- if (backend == KERNEL && access(OPENFSI_BMC, F_OK) == 0)
- return true;
-
- return backend == FSI;
+ fprintf(stream, "Valid backends: i2c kernel fsi fake\n");
}
void print_targets(FILE *stream)
@@ -63,15 +48,12 @@ void print_targets(FILE *stream)
fprintf(stream, "fsi: p8 p9w p9r p9z\n");
}
-const char *default_target(enum backend backend)
+static const char *default_fsi_target(void)
{
FILE *dt_compatible;
char line[256];
char *p;
- if (backend == I2C || backend == KERNEL) /* No target nessesary */
- return NULL;
-
dt_compatible = fopen("/proc/device-tree/compatible", "r");
if (!dt_compatible)
return NULL;
@@ -82,33 +64,39 @@ const char *default_target(enum backend backend)
return NULL;
if (strstr(line, "witherspoon"))
- return witherspoon;
+ return "p9w";
if (strstr(line, "romulus"))
- return romulus;
+ return "p9r";
if (strstr(line, "zaius"))
- return zaius;
+ return "p9z";
if (strstr(line, "palmetto"))
- return p8;
+ return "p8";
return NULL;
}
-bool target_is_possible(enum backend backend, const char *target)
+const char *default_target(enum backend backend)
{
- const char *def;
+ switch(backend) {
+ case I2C:
+ return NULL;
+ break;
- if (!backend_is_possible(backend))
- return false;
+ case KERNEL:
+ return NULL;
+ break;
- if (backend == I2C || backend == KERNEL) /* No target is nessesary */
- return true;
+ case FSI:
+ return default_fsi_target();
+ break;
- def = default_target(backend);
- if (!def || !target)
- return false;
+ default:
+ return NULL;
+ break;
+ }
- return strcmp(def, target) == 0;
+ return NULL;
}
@@ -22,11 +22,6 @@ enum backend default_backend(void)
return FAKE;
}
-bool backend_is_possible(enum backend backend)
-{
- return backend == FAKE;
-}
-
void print_backends(FILE *stream)
{
fprintf(stream, "Valid backends: fake\n");
@@ -42,9 +37,3 @@ void print_targets(FILE *stream)
{
fprintf(stream, "fake: No target is necessary\n");
}
-
-/* Theres no device for FAKE backend */
-bool target_is_possible(enum backend backend, const char *target)
-{
- return target == NULL;
-}
@@ -26,15 +26,9 @@ enum backend default_backend(void)
return HOST;
}
-bool backend_is_possible(enum backend backend)
-{
- /* TODO */
- return backend == HOST;
-}
-
void print_backends(FILE *stream)
{
- fprintf(stream, "Valid backends: host\n");
+ fprintf(stream, "Valid backends: host fake\n");
}
const char *default_target(enum backend backend)
@@ -76,17 +70,3 @@ void print_targets(FILE *stream)
{
fprintf(stream, "host: p8 p9\n");
}
-
-bool target_is_possible(enum backend backend, const char *target)
-{
- const char *def;
-
- if (!backend_is_possible(backend))
- return false;
-
- def = default_target(backend);
- if (!def || !target)
- return false;
-
- return strcmp(def, target) == 0;
-}
If a user explicitly specifies a backend assume they know what they're doing and use it. If no backend is specified pick some sane defaults based on the detected platform. Fixes the following bug when specifying a backend is incorrectly determined to be invalid: Target p8 not possible kernel: No target is necessary i2c: No target is necessary fsi: p8 p9w p9r p9z Signed-off-by: Alistair Popple <alistair@popple.id.au> --- src/main.c | 25 ++++++++----------------- src/options.h | 9 --------- src/options_arm.c | 56 ++++++++++++++++++++++--------------------------------- src/options_def.c | 11 ----------- src/options_ppc.c | 22 +--------------------- 5 files changed, 31 insertions(+), 92 deletions(-)