From deae75dd41e4f9b87478c9d4d5b1044e08d2eb8b Mon Sep 17 00:00:00 2001 From: blogic Date: Wed, 22 Aug 2012 09:22:38 +0000 Subject: [PATCH] [tools] tools/firmware-utils/ptgen option to use MB rounding git-svn-id: svn://svn.openwrt.org/openwrt/trunk@33218 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- .../brcm2708/image/gen_rpi_sdcard_img.sh | 2 +- tools/firmware-utils/src/ptgen.c | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/target/linux/brcm2708/image/gen_rpi_sdcard_img.sh b/target/linux/brcm2708/image/gen_rpi_sdcard_img.sh index c3287d28d..1b7e65ea5 100755 --- a/target/linux/brcm2708/image/gen_rpi_sdcard_img.sh +++ b/target/linux/brcm2708/image/gen_rpi_sdcard_img.sh @@ -15,7 +15,7 @@ ROOTFSSIZE="$5" head=4 sect=63 -set `ptgen -o $OUTPUT -h $head -s $sect -t c -p ${BOOTFSSIZE}M -t 83 -p ${ROOTFSSIZE}M` +set `ptgen -o $OUTPUT -h $head -s $sect -l 4096 -t c -p ${BOOTFSSIZE}M -t 83 -p ${ROOTFSSIZE}M` BOOTOFFSET="$(($1 / 512))" BOOTSIZE="$(($2 / 512))" diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c index d94aabb5f..0247fd013 100644 --- a/tools/firmware-utils/src/ptgen.c +++ b/tools/firmware-utils/src/ptgen.c @@ -56,6 +56,7 @@ int verbose = 0; int active = 1; int heads = -1; int sectors = -1; +int kb_align = 0; struct partinfo parts[4]; char *filename = NULL; @@ -117,6 +118,11 @@ static inline unsigned long round_to_cyl(long sect) { return sect + cyl_size - (sect % cyl_size); } +/* round the sector number up to the kb_align boundary */ +static inline unsigned long round_to_kb(long sect) { + return ((sect - 1) / kb_align + 1) * kb_align; +} + /* check the partition sizes and write the partition table */ static int gen_ptable(int nr) { @@ -132,8 +138,13 @@ static int gen_ptable(int nr) } pte[i].active = ((i + 1) == active) ? 0x80 : 0; pte[i].type = parts[i].type; - pte[i].start = cpu_to_le16(start = sect + sectors); - sect = round_to_cyl(start + parts[i].size * 2); + start = sect + sectors; + if (kb_align != 0) + start = round_to_kb(start); + pte[i].start = cpu_to_le16(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); to_chs(start, pte[i].chs_start); to_chs(start + len - 1, pte[i].chs_end); @@ -167,7 +178,7 @@ fail: static void usage(char *prog) { - fprintf(stderr, "Usage: %s [-v] -h -s -o [-a 0..4] [[-t ] -p ...] \n", prog); + fprintf(stderr, "Usage: %s [-v] -h -s -o [-a 0..4] [-l ] [[-t ] -p ...] \n", prog); exit(1); } @@ -177,7 +188,7 @@ int main (int argc, char **argv) int ch; int part = 0; - while ((ch = getopt(argc, argv, "h:s:p:a:t:o:v")) != -1) { + while ((ch = getopt(argc, argv, "h:s:p:a:t:o:vl:")) != -1) { switch (ch) { case 'o': filename = optarg; @@ -207,6 +218,9 @@ int main (int argc, char **argv) if ((active < 0) || (active > 4)) active = 0; break; + case 'l': + kb_align = (int) strtoul(optarg, NULL, 0) * 2; + break; case '?': default: usage(argv[0]);