diff mbox series

[LEDE-DEV,7/7] firmware-tools/ptgen: allow individual partition alignment

Message ID 1513897174-20803-8-git-send-email-mhei@heimpold.de
State Changes Requested
Delegated to: John Crispin
Headers show
Series firmware-tools/ptgen: minor fixes and improvements | expand

Commit Message

Michael Heimpold Dec. 21, 2017, 10:59 p.m. UTC
At the moment, the alignment parameter can only be given once and affects
all partitions the same way. For example, it's not possible to align the
first partition to 1 MiB start offet, while aligning the next ones to
a 4 MiB boundary.

This can be useful for example when defining a small bootloader partition
within the first erase block on an eMMC, but then aligning the rootfs to
next start of erase block.

This change splits the global alignment parameter to individual ones
which thus allows individual partition alignment.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
---
 tools/firmware-utils/src/ptgen.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c
index d549faf..547b83a 100644
--- a/tools/firmware-utils/src/ptgen.c
+++ b/tools/firmware-utils/src/ptgen.c
@@ -53,17 +53,16 @@  struct pte {
 struct partinfo {
 	unsigned long size;
 	int type;
+	int kb_align;
 };
 
 int verbose = 0;
 int active = 1;
 int heads = -1;
 int sectors = -1;
-int kb_align = 0;
 struct partinfo parts[4];
 char *filename = NULL;
 
-
 /*
  * parse the size argument, which is either
  * a simple number (K assumed) or
@@ -127,7 +126,8 @@  static inline unsigned long round_to_cyl(long sect)
 }
 
 /* round the sector number up to the kb_align boundary */
-static inline unsigned long round_to_kb(long sect) {
+static inline unsigned long round_to_kb(long sect, int kb_align)
+{
         return ((sect - 1) / kb_align + 1) * kb_align;
 }
 
@@ -150,12 +150,12 @@  static int gen_ptable(uint32_t signature, int nr)
 		pte[i].type = parts[i].type;
 
 		start = sect + ((i == 0) ? sectors : 0);
-		if (kb_align != 0)
-			start = round_to_kb(start);
+		if (parts[i].kb_align != 0)
+			start = round_to_kb(start, parts[i].kb_align);
 		pte[i].start = cpu_to_le32(start);
 
 		sect = start + parts[i].size * 2;
-		if (kb_align == 0)
+		if (parts[i].kb_align == 0)
 			sect = round_to_cyl(sect);
 		pte[i].length = cpu_to_le32(len = sect - start);
 
@@ -198,15 +198,17 @@  fail:
 
 static void usage(char *prog)
 {
-	fprintf(stderr, "Usage: %s [-v] -h <heads> -s <sectors> -o <outputfile> [-a 0..4] [-l <align kB>] [[-t <type>] -p <size>...] \n", prog);
+	fprintf(stderr, "Usage: %s [-v] -h <heads> -s <sectors> -o <outputfile> [-a 0..4] [[-l <align kB>] [-t <type>] -p <size>...] \n", prog);
 	exit(EXIT_FAILURE);
 }
 
 int main (int argc, char **argv)
 {
+	int kb_align = 0;
 	char type = 0x83;
 	int ch;
 	int part = 0;
+
 	uint32_t signature = 0x5452574F; /* 'OWRT' */
 
 	while ((ch = getopt(argc, argv, "h:s:p:a:t:o:vl:S:")) != -1) {
@@ -229,6 +231,7 @@  int main (int argc, char **argv)
 				exit(EXIT_FAILURE);
 			}
 			parts[part].size = to_kbytes(optarg);
+			parts[part].kb_align = kb_align;
 			parts[part++].type = type;
 			break;
 		case 't':