Application executable generated by WAF is bigger than chip flash size

I am writing a very basic “Hello, World” application for the ARM/STM32F4 BSP. However, the size of the generated executable is about 1.9MB, whereas the STM32F446RE I have only has 512KB of flash memory. I am also providing the wscript, init.c, and app.c files for reference.

Followed the manual BSP Build instructions on 2.7. Build Your Application — RTEMS User Manual 7.e8e6f12 (8th March 2025) documentation

Init.c file below

/*
 * Simple RTEMS configuration
 */

#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_UNLIMITED_OBJECTS
#define CONFIGURE_UNIFIED_WORK_AREAS

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_INIT

#include <rtems/confdefs.h>

Basic.c file below

#include <rtems.h>
#include <stdio.h>
#include <stdlib.h>
rtems_task Init(rtems_task_argument argument)
{
    printf("Hello from RTEMS on STM32F446RE!\n");
	exit(0);

}

wscript file below.

from __future__ import print_function

rtems_version = "7"

try:
    import rtems_waf.rtems as rtems
except:
    print('error: no rtems_waf git submodule')
    import sys
    sys.exit(1)

def init(ctx):
    rtems.init(ctx, version=rtems_version, long_commands=True)

def bsp_configure(conf, arch_bsp):
    pass

def options(opt):
    rtems.options(opt)

def configure(conf):
    rtems.configure(conf, bsp_configure=bsp_configure)

def build(bld):
    rtems.build(bld)

    
    bld(features='c cprogram',
        target='test.exe',
        cflags='-Os -ffunction-sections -fdata-sections', 
        ldflags='-Wl,--gc-sections',  
        source=['basic.c',
		'init.c'])

The executable produced is in the ELF format and these can be larger. This is the most common format used in operating system. This file has to be processed to get into a format your hardware needs. This depends on a number of factors such as the tools the device vendor provides and the type of bootloader.

RTEMS tools provides a size tool for your architecture and it reports the actual size of the code or text and data. For ARM look for arm-rtems6-size and run it with the ELF executable to see the size.

There is also objcopy and that can be used to copy the code and data from the ELF format to a binary format. For your architecture the tool will be arm-rtems6-objdump

The ELF file is large because it contains the DWARF debug information GDB uses when debugging. The debug data is automatically stripped as you convert the ELF file to a format your device uses.

Thanks, I used arm-rtems6-objcopy -O binary to strip the ELF and make the BIN, came out to be about 54KB.

1 Like

Excellent. That leaves you with plenty of room. :grinning:

1 Like