MCUXpresso IDE How do I fix the compiled generated bin file size

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MCUXpresso IDE How do I fix the compiled generated bin file size

Jump to solution
1,960 Views
ywjack
Contributor III

HI:NXP Technical support

I use NXP RT1172 microcontroller and use MCUXpresso IDE v11.6.1_8255

I have a question to consult, I am doing bootloader. Now my boot code is compiled and the bin file is 100K, the size is generated according to the actual code amount of my code, but I want to make it fixed and the compiled size is fixed, such as 512K, how should I modify it? The reserved boot space is 3M (0x30000000~30300000). The space is definitely enough.

Another problem is: I want to compile the bin file a fixed address inside the value is a constant how to operate, for example, I compile the boot size is 100K I want to 511K which address is a constant 0xAA55AA55

 

0 Kudos
Reply
1 Solution
1,796 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @ywjack 

You should change my_bootloader.bin name to the generated name.

For example, if your project is evkbmimxrt1170_hello_world_demo_cm7

you should change the my_bootloader.bin to the evkbmimxrt1170_hello_world_demo_cm7.bin

Hope this will help you.

BR

Hang

View solution in original post

0 Kudos
Reply
6 Replies
1,922 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @ywjack 

1. Fix the Compiled Size to 512K

You can add a post-build step to pad the binary file. In MCUXpresso IDE, you can specify post-build commands:

1. Open your project properties.
2. Navigate to “C/C++ Build” -> “Settings”.
3. Under “Build Steps”, in the “Post-build steps” section, add a command to pad the binary:

# Replace "my_bootloader.bin" with your actual output binary filename
# Replace "512K" with the fixed size in bytes (524288 bytes)
python -c "with open('my_bootloader.bin', 'ab') as f: f.write(b'\x00' * (524288 - f.tell()))"

This script pads the binary with zeroes up to 512KB.

2. Setting a Fixed Address Value Inside the Binary

To place a constant value at a specific address (e.g., 0x511K), modify your source code and linker script:

Define a Constant in Your Code

Define a variable with the desired constant value:

const uint32_t fixed_value __attribute__((section(".fixed_value"))) = 0xAA55AA55;

Modify the Linker Script

Ensure the .fixed_value section is placed at the specific address within the binary:

MEMORY
{
 /* Adjust your memory layout as necessary */
 FLASH (rx) : ORIGIN = 0x30000000, LENGTH = 0x80000
}

SECTIONS
{
 /* Existing sections */
 .text :
 {
   /* Existing code */
 } > FLASH

 .rodata :
 {
   /* Existing code */
 } > FLASH

 /* Add fixed value section */
 .fixed_value 0x30080000 - 0x80000 + 0x1FFFC :
 {
   KEEP(*(.fixed_value))
 } > FLASH

 .padding :
 {
   . = ALIGN(4);
   KEEP(*(.padding))
   . = 0x30080000; /* End address to ensure 512KB size */
 } > FLASH
}

This will place the constant 0xAA55AA55 at the address 0x30080000 - 0x80000 + 0x1FFFC (511K within the binary).

Hope this will help you.

BR

Hang

0 Kudos
Reply
1,902 Views
ywjack
Contributor III
Can you show me this screenshot Under "Build Steps", in the "Post-build steps" section, add a command to pad the binary。
According to what you said, 515K is all 0x00, which is not what I want. I need the total bin file size to be 512K, and the unused fill 0x00 or 0xFF
0 Kudos
Reply
1,886 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @ywjack 

You can refer to below picture.

HangZhang_0-1719311050256.png

I didn't say 515K is all 0x00, i said that the total bin file size to be 512K, and the unused fill 0x00 or 0xFF.

Hope this will help you.

BR

Hang

0 Kudos
Reply
1,826 Views
ywjack
Contributor III

ywjack_0-1719805374292.png

 

ywjack_1-1719805396852.png

I did it according to your configuration, and still generated 512K bin file is 0x00. Is there something wrong with my other configuration? Can you check it for me

0 Kudos
Reply
1,797 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @ywjack 

You should change my_bootloader.bin name to the generated name.

For example, if your project is evkbmimxrt1170_hello_world_demo_cm7

you should change the my_bootloader.bin to the evkbmimxrt1170_hello_world_demo_cm7.bin

Hope this will help you.

BR

Hang

0 Kudos
Reply
1,957 Views
ErichStyger
Specialist I

Have a look at the SRecord tool (https://srecord.sourceforge.net/) which you can use to manipulate different kind of files, including S19, Intel hex and binary files.

Another hint is that you can use the linker to fill your binary, see https://mcuoneclipse.com/2014/06/23/filling-unused-memory-with-the-gnu-linker/

If you are looking for having the resulting binary at relocatable addresses, see https://mcuoneclipse.com/2021/06/05/position-independent-code-with-gcc-for-arm-cortex-m/

I hope this helps,

Erich

0 Kudos
Reply