Skip to content

Commit 8e2f619

Browse files
committed
Add command to configure section padding
1 parent 3771244 commit 8e2f619

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Argument | Description
2626
```-bz <512K|256K|1M|2M|4M|8M|16M|32M>``` | Set the flash chip size. Default is 512K.
2727
```-bf <40|26|20|80>``` | Set the flash chip frequency, in MHz. Default is 40M.
2828
```-bs <section>``` | Read the specified section from the ELF file and append it to the firmware image. Sections will appear in the firmware image in the exact same order as the -bs commands are executed.
29-
```-bp <size>``` | Pad last written section of firmware image to the given size, in bytes.
29+
```-bp <size>``` | Finalize the firmware image, padding it with `0xaa` value until it is at least `<size>` bytes long. Unlike `-bc`, this doesn't close the file. This option can be used to combine bootloader with the rest of the application
30+
```-br <size>``` | Pad all the following sections to multiples of `<size>`. Default is 4 bytes. This option can be used to place sections on specific boundaries, e.g. 4k or 64k.
3031
```-bc``` | Close the firmware image and save the result as file to disk.
3132
```-v``` | Increase verbosity level of the tool. Add more v's to increase it even more, e.g. -vv, -vvv.
3233
```-q``` | Disable most of the output.

argparse/argparse.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ they are given.\n\
7878
same order as the -bs commands are executed.\n\
7979
\n\
8080
-bp <size>\n\
81-
Pad last written section of firmware image to the given size, in bytes.\n\
81+
Finalize the firmware image, padding it with '0xaa' value until it is at least\n\
82+
<size> bytes long. Unlike -bc, this doesn't close the file.\n\
83+
This option can be used to combine bootloader with the rest of the application\n\
84+
\n\
85+
-br <size>\n\
86+
Pad all the following sections to multiples of <size>. Default is 4 bytes.\n\
87+
This option can be used to place sections on specific boundaries, e.g. 4k or 64k.\n\
8288
\n\
8389
-bc\n\
8490
Close the firmware image and save the result as file to disk.\n\

argparse/argparse_binimagecmd.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "esptool_elf_object.h"
3131
#include "esptool_binimage.h"
3232

33+
static unsigned section_pad_size = 4;
34+
3335
static int argparse_binimagecmd_add_segment(const char *sname, uint32_t padsize)
3436
{
3537
uint32_t snum;
@@ -93,7 +95,7 @@ int argparse_binimagecmd(int num_args, char **arg_ptr)
9395
{
9496
return 0;
9597
}
96-
if(argparse_binimagecmd_add_segment(arg_ptr[0], 4))
98+
if(argparse_binimagecmd_add_segment(arg_ptr[0], section_pad_size))
9799
{
98100
bimage_set_entry(get_elf_entry());
99101
return 2;
@@ -119,6 +121,14 @@ int argparse_binimagecmd(int num_args, char **arg_ptr)
119121
}
120122
break;
121123

124+
case 'r':
125+
if(num_args < 1)
126+
{
127+
return 0;
128+
}
129+
section_pad_size = (unsigned) atoi(arg_ptr[0]);
130+
return 2;
131+
122132
case 'm':
123133
if (num_args < 1)
124134
{

0 commit comments

Comments
 (0)