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
已解决! 转到解答。
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
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
Hi @ywjack
You can refer to below picture.
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
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
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