firmware-utils: add E2100L support to addpattern.c
[lede.git] / tools / firmware-utils / src / ptgen.c
index 6379ed7a5904b7ddc48316ce52549c06f3c50d6e..8466d35bcc3f5364c318594b092ead2aae9e95b9 100644 (file)
@@ -1,6 +1,6 @@
 /* 
  * ptgen - partition table generator
- * Copyright (C) 2006 by Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2006 by Felix Fietkau <nbd@nbd.name>
  *
  * uses parts of afdisk
  * Copyright (C) 2002 by David Roetzel <david@roetzel.de>
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <stdint.h>
 
 #if __BYTE_ORDER == __BIG_ENDIAN
-#define cpu_to_le16(x) bswap_16(x)
+#define cpu_to_le32(x) bswap_32(x)
 #elif __BYTE_ORDER == __LITTLE_ENDIAN
-#define cpu_to_le16(x) (x)
+#define cpu_to_le32(x) (x)
 #else
 #error unknown endianness!
 #endif
 
 /* Partition table entry */
-struct pte { 
-       unsigned char active;
-       unsigned char chs_start[3];
-       unsigned char type;
-       unsigned char chs_end[3];
-       unsigned int start;
-       unsigned int length;
+struct pte {
+       uint8_t active;
+       uint8_t chs_start[3];
+       uint8_t type;
+       uint8_t chs_end[3];
+       uint32_t start;
+       uint32_t length;
 };
 
 struct partinfo {
@@ -92,7 +93,9 @@ static long to_kbytes(const char *string) {
        }
 
        /* result: number + 1024^(exp) */
-       return result * ((2 << ((10 * exp) - 1)) ?: 1);
+       if (exp == 0)
+               return result;
+       return result * (2 << ((10 * exp) - 1));
 }
 
 /* convert the sector number into a CHS value for the partition table */
@@ -142,11 +145,11 @@ static int gen_ptable(uint32_t signature, int nr)
                start = sect + sectors;
                if (kb_align != 0)
                        start = round_to_kb(start);
-               pte[i].start = cpu_to_le16(start);
+               pte[i].start = cpu_to_le32(start);
                sect = start + parts[i].size * 2;
                if (kb_align == 0)
                        sect = round_to_cyl(sect);
-               pte[i].length = cpu_to_le16(len = sect - start);
+               pte[i].length = cpu_to_le32(len = sect - start);
                to_chs(start, pte[i].chs_start);
                to_chs(start + len - 1, pte[i].chs_end);
                if (verbose)