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