[LEDE-DEV] [PATCH 6/7] firmware-tools/ptgen: fix start sector calculation

Michael Heimpold mhei at heimpold.de
Thu Dec 21 14:59:33 PST 2017


Consider the following example:

$ ./ptgen -v -a 0 -h 255 -s 63 -l 1024 -o test2.img -p 3M -p 128M -p 128M
Partition 0: start=1048576, end=4194304, size=3145728
1048576
3145728
Partition 1: start=5242880, end=139460608, size=134217728
5242880
134217728
Partition 2: start=140509184, end=274726912, size=134217728
140509184
134217728

Opening the image file with cfdisk shows that there is free space between
the partitions which is not required/intended:

               Size: 1 GiB, 1073741824 bytes, 2097152 sectors
                     Label: dos, identifier: 0x5452574f

    Device        Boot        Start       End   Sectors    Size   Id Type
    test2.img1                 2048      8191      6144      3M   83 Linux
    Free space                 8192     10239      2048      1M
    test2.img2                10240    272383    262144    128M   83 Linux
    Free space               272384    274431      2048      1M
    test2.img3               274432    536575    262144    128M   83 Linux
    Free space               536576   2097151   1560576    762M

With this patch the very same execution of ptgen results in:

$ ./ptgen -v -a 0 -h 255 -s 63 -l 1024 -o test2.img -p 3M -p 128M -p 128M
Partition 0: start=1048576, end=4194304, size=3145728
1048576
3145728
Partition 1: start=4194304, end=138412032, size=134217728
4194304
134217728
Partition 2: start=138412032, end=272629760, size=134217728
138412032
134217728

And the view with cfdisk shows, that there is no free space inserted anymore:

                              Disk: test2.img
               Size: 1 GiB, 1073741824 bytes, 2097152 sectors
                     Label: dos, identifier: 0x5452574f

    Device        Boot        Start       End   Sectors    Size   Id Type
    test2.img1                 2048      8191      6144      3M   83 Linux
    test2.img2                 8192    270335    262144    128M   83 Linux
    test2.img3               270336    532479    262144    128M   83 Linux
    Free space               532480   2097151   1564672    764M

Signed-off-by: Michael Heimpold <mhei at heimpold.de>
---
 tools/firmware-utils/src/ptgen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c
index 3e1b8ba..d549faf 100644
--- a/tools/firmware-utils/src/ptgen.c
+++ b/tools/firmware-utils/src/ptgen.c
@@ -149,7 +149,7 @@ static int gen_ptable(uint32_t signature, int nr)
 		pte[i].active = ((i + 1) == active) ? 0x80 : 0;
 		pte[i].type = parts[i].type;
 
-		start = sect + sectors;
+		start = sect + ((i == 0) ? sectors : 0);
 		if (kb_align != 0)
 			start = round_to_kb(start);
 		pte[i].start = cpu_to_le32(start);
-- 
2.7.4




More information about the Lede-dev mailing list