summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2015-05-09 12:38:36 -0500
committerBobby Bingham <koorogi@koorogi.info>2015-09-15 22:43:32 -0500
commit35b0f3c11892cbdfc67e484ba2b94c8ffb5d1545 (patch)
tree999c87fc7887d67b057436e0f65527c750ab7d4c /src
parentd6f12cdb4b333af94c9195e51218a9301aa58a7e (diff)
allow specifying master and slave stack addresses
Diffstat (limited to 'src')
-rw-r--r--src/satmkboot.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/satmkboot.c b/src/satmkboot.c
index d3b5958..71232dc 100644
--- a/src/satmkboot.c
+++ b/src/satmkboot.c
@@ -1,3 +1,4 @@
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -130,7 +131,7 @@ static void usage(const char *progname)
const int width = 20;
fprintf(stderr, "usage: %s -h\n", progname);
- fprintf(stderr, " %s -io[pr]\n\n", progname);
+ fprintf(stderr, " %s -io[prms]\n\n", progname);
fprintf(stderr, "\t%-*s%s\n", width, "-h", "Show this help text");
fprintf(stderr, "\t%-*s%s\n", width, "-i ip.bin", "Initial program code file");
fprintf(stderr, "\t%-*s%s\n", width, "-o output", "Output file");
@@ -138,6 +139,8 @@ static void usage(const char *progname)
print_symbols(stderr, width, peripheraldefs);
fprintf(stderr, "\t%-*s%s\n", width, "-r regions", "Geographical regions (default: all):");
print_symbols(stderr, width, regiondefs);
+ fprintf(stderr, "\t%-*s%s\n", width, "-m master_stack", "Master stack address (default 0x06002000)");
+ fprintf(stderr, "\t%-*s%s\n", width, "-s slave_stack", "Slave stack address (default 0x06001000)");
}
#define ERR_UNKNOWN_OPTION 0
@@ -146,6 +149,10 @@ static void usage(const char *progname)
#define ERR_DUPLICATE_OUTPUT 3
#define ERR_REGION_OVERFLOW 4
#define ERR_PERIPHERAL_OVERFLOW 5
+#define ERR_DUPLICATE_MASTER 6
+#define ERR_DUPLICATE_SLAVE 7
+#define ERR_INVALID_MASTER 8
+#define ERR_INVALID_SLAVE 9
static const char *errmsgs[] = {
"Unknown extra argument",
@@ -154,6 +161,10 @@ static const char *errmsgs[] = {
"Duplicate -o parameter",
"Too many regions specified (max 10)",
"Too many peripherals specified (max 16)",
+ "Duplicate -m parameter",
+ "Duplicate -s parameter",
+ "Invalid master stack address",
+ "Invalid slave stack address",
};
static int show_arg_error(const char *progname, int prev_errors, int error)
@@ -173,14 +184,31 @@ static void process_symbols(const char *progname, char *list, size_t size, const
}
}
+static int process_address(const char *progname, uint32_t *addr, const char *arg, int *errors, int bad_addr)
+{
+ char *end;
+ errno = 0;
+ unsigned long val = strtoul(arg, &end, 16);
+ if (end == arg || *end || errno || val > (uint32_t)-1) {
+ *errors = show_arg_error(progname, *errors, bad_addr);
+ return 0;
+ }
+
+ *addr = val;
+ return 1;
+}
+
static int process_args(int argc, char **argv)
{
int errors = 0, fail = 0, help = 0;
int opt;
+ int have_master = 0;
+ int have_slave = 0;
+
extern char *optarg;
extern int optind, optopt;
- while ((opt = getopt(argc, argv, "hi:o:r:p:")) != -1) {
+ while ((opt = getopt(argc, argv, "hi:o:p:r:m:s:")) != -1) {
switch (opt) {
case 'h':
help = 1;
@@ -200,6 +228,20 @@ static int process_args(int argc, char **argv)
outfile = optarg;
break;
+ case 'm':
+ if (have_master)
+ errors = show_arg_error(argv[0], errors, ERR_DUPLICATE_MASTER);
+ else
+ have_master = process_address(argv[0], &sysid.stack_master, optarg, &errors, ERR_INVALID_MASTER);
+ break;
+
+ case 's':
+ if (have_slave)
+ errors = show_arg_error(argv[0], errors, ERR_DUPLICATE_SLAVE);
+ else
+ have_slave = process_address(argv[0], &sysid.stack_slave, optarg, &errors, ERR_INVALID_SLAVE);
+ break;
+
case 'p':
process_symbols(argv[0], sysid.peripherals, sizeof sysid.peripherals, optarg, &errors, ERR_PERIPHERAL_OVERFLOW);
break;