ath79: use dynamic partitioning for TP-Link CPE series
[project/firmware-utils.git] / src / mkdniimg.c
index 31b321012d3d1bac13e2ce50eaf6ec2df99f23c0..92315f98497846fd740c33bde0e1e986742a67d3 100644 (file)
@@ -27,7 +27,8 @@ static char *ifname;
 static char *progname;
 static char *ofname;
 static char *version = "1.00.00";
-static char *region ="NA";
+static char *region = "";
+static char *hd_id;
 
 static char *board_id;
 /*
@@ -42,14 +43,13 @@ static char *board_id;
 #define ERRS(fmt, ...) do { \
        int save = errno; \
        fflush(0); \
-       fprintf(stderr, "[%s] *** error: " fmt "\n", \
+       fprintf(stderr, "[%s] *** error: " fmt ": %s\n", \
                        progname, ## __VA_ARGS__, strerror(save)); \
 } while (0)
 
 void usage(int status)
 {
        FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
-       struct board_info *board;
 
        fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
        fprintf(stream,
@@ -60,6 +60,7 @@ void usage(int status)
 "  -o <file>       write output to the file <file>\n"
 "  -v <version>    set image version to <version>\n"
 "  -r <region>     set image region to <region>\n"
+"  -H <hd_id>      set image hardware id to <hd_id>\n"
 "  -h              show this screen\n"
        );
 
@@ -73,7 +74,7 @@ int main(int argc, char *argv[])
        int err;
        struct stat st;
        char *buf;
-       int i;
+       int pos, rem, i;
        uint8_t csum;
 
        FILE *outfile, *infile;
@@ -83,7 +84,7 @@ int main(int argc, char *argv[])
        while ( 1 ) {
                int c;
 
-               c = getopt(argc, argv, "B:i:o:v:r:h");
+               c = getopt(argc, argv, "B:i:o:v:r:H:h");
                if (c == -1)
                        break;
 
@@ -103,6 +104,9 @@ int main(int argc, char *argv[])
                case 'r':
                        region = optarg;
                        break;
+               case 'H':
+                       hd_id = optarg;
+                       break;
                case 'h':
                        usage(EXIT_SUCCESS);
                        break;
@@ -141,8 +145,12 @@ int main(int argc, char *argv[])
        }
 
        memset(buf, 0, DNI_HDR_LEN);
-       snprintf(buf, DNI_HDR_LEN, "device:%s\nversion:V%s\nregion:%s\n",
-                board_id, version, region);
+       pos = snprintf(buf, DNI_HDR_LEN, "device:%s\nversion:V%s\nregion:%s\n",
+                      board_id, version, region);
+       rem = DNI_HDR_LEN - pos;
+       if (pos >= 0 && rem > 1 && hd_id) {
+               snprintf(buf + pos, rem, "hd_id:%s\n", hd_id);
+       }
 
        infile = fopen(ifname, "r");
        if (infile == NULL) {
@@ -179,7 +187,6 @@ int main(int argc, char *argv[])
 
        res = EXIT_SUCCESS;
 
- out_flush:
        fflush(outfile);
 
  err_close_out: