diff mbox series

[LEDE-DEV,2/7] firmware-tools/ptgen: do not truncate the output file

Message ID 1513897174-20803-3-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 image file operated on is always truncated
to 512 bytes. This limits the usage of ptgen somewhat.

This change allows to use ptgen on existing, larger image files.
In this case, only the partition table is written/updated while
the rest of the image file is left alone.

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

Comments

John Crispin Jan. 1, 2018, 11:12 a.m. UTC | #1
On 21/12/17 23:59, Michael Heimpold wrote:
> At the moment, the image file operated on is always truncated
> to 512 bytes. This limits the usage of ptgen somewhat.

O_TRUNC truncates to 0 and not 512 ?!

     John

>
> This change allows to use ptgen on existing, larger image files.
> In this case, only the partition table is written/updated while
> the rest of the image file is left alone.
>
> Signed-off-by: Michael Heimpold <mhei@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 93d66eb..ff97cd5 100644
> --- a/tools/firmware-utils/src/ptgen.c
> +++ b/tools/firmware-utils/src/ptgen.c
> @@ -166,7 +166,7 @@ static int gen_ptable(uint32_t signature, int nr)
>   		printf("%ld\n", (long)len * 512);
>   	}
>   
> -	if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
> +	if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) < 0) {
>   		fprintf(stderr, "Can't open output file '%s'\n",filename);
>   		return -1;
>   	}
Michael Heimpold Jan. 1, 2018, 4:33 p.m. UTC | #2
Hi John,

Am Montag, 1. Januar 2018, 12:12:35 CET schrieb John Crispin:
> 
> On 21/12/17 23:59, Michael Heimpold wrote:
> > At the moment, the image file operated on is always truncated
> > to 512 bytes. This limits the usage of ptgen somewhat.
> 
> O_TRUNC truncates to 0 and not 512 ?!

when the file is opened, it is truncated to 0, but following writes extend
it to 512 byte: last write is the 0x55aa signature which is placed at offset 510 bytes.

Do you think the patch description should be better?

Regards,
mhei

> 
>      John
> 
> >
> > This change allows to use ptgen on existing, larger image files.
> > In this case, only the partition table is written/updated while
> > the rest of the image file is left alone.
> >
> > Signed-off-by: Michael Heimpold <mhei@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 93d66eb..ff97cd5 100644
> > --- a/tools/firmware-utils/src/ptgen.c
> > +++ b/tools/firmware-utils/src/ptgen.c
> > @@ -166,7 +166,7 @@ static int gen_ptable(uint32_t signature, int nr)
> >   		printf("%ld\n", (long)len * 512);
> >   	}
> >   
> > -	if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
> > +	if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) < 0) {
> >   		fprintf(stderr, "Can't open output file '%s'\n",filename);
> >   		return -1;
> >   	}
> 
>
John Crispin Jan. 2, 2018, 5:44 a.m. UTC | #3
On 01/01/18 17:33, Michael Heimpold wrote:
> Hi John,
>
> Am Montag, 1. Januar 2018, 12:12:35 CET schrieb John Crispin:
>> On 21/12/17 23:59, Michael Heimpold wrote:
>>> At the moment, the image file operated on is always truncated
>>> to 512 bytes. This limits the usage of ptgen somewhat.
>> O_TRUNC truncates to 0 and not 512 ?!
> when the file is opened, it is truncated to 0, but following writes extend
> it to 512 byte: last write is the 0x55aa signature which is placed at offset 510 bytes.
>
> Do you think the patch description should be better?

Hi

I certainly failed to understand what the patch tries to achieve :-)

> Regards,
> mhei
>
>>       John
>>
>>> This change allows to use ptgen on existing, larger image files.
>>> In this case, only the partition table is written/updated while
>>> the rest of the image file is left alone.
>>>
>>> Signed-off-by: Michael Heimpold <mhei@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 93d66eb..ff97cd5 100644
>>> --- a/tools/firmware-utils/src/ptgen.c
>>> +++ b/tools/firmware-utils/src/ptgen.c
>>> @@ -166,7 +166,7 @@ static int gen_ptable(uint32_t signature, int nr)
>>>    		printf("%ld\n", (long)len * 512);
>>>    	}
>>>    
>>> -	if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
>>> +	if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) < 0) {
>>>    		fprintf(stderr, "Can't open output file '%s'\n",filename);
>>>    		return -1;
>>>    	}
>>
>
diff mbox series

Patch

diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c
index 93d66eb..ff97cd5 100644
--- a/tools/firmware-utils/src/ptgen.c
+++ b/tools/firmware-utils/src/ptgen.c
@@ -166,7 +166,7 @@  static int gen_ptable(uint32_t signature, int nr)
 		printf("%ld\n", (long)len * 512);
 	}
 
-	if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
+	if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) < 0) {
 		fprintf(stderr, "Can't open output file '%s'\n",filename);
 		return -1;
 	}