Day 2: Infineon’s Embedded Systems Summer Course (2024) Part 2

Tabrez Ahmed
5 min readApr 11, 2024

--

Journey from source to binary

  1. Compile: This step involves converting the human-readable source code (e.g., written in C/C++ or Assembly) into machine-readable binary code. A compiler is used for this task.
  2. Link: The linking step in software development involves combining compiled object files along with necessary libraries and dependencies to create an executable program or binary image. This process is facilitated by a linker, which resolves references between different parts of the program, assigns memory addresses to symbols, and generates the final output. Additionally, the linker script is used to specify the memory layout and organization of the program in the target environment. The outcome of the linking step is an executable file that is ready for deployment onto the target hardware.
  3. Flash: Flashing refers to transferring the compiled and linked executable program onto the memory of the microcontroller. This process is often performed using a specific tool or device designed for programming microcontrollers.
  4. Load: Once the program is flashed onto the microcontroller, it is loaded into the microcontroller’s memory and is ready to be executed. This step may involve initializing variables, setting up peripherals, and preparing the microcontroller to run the program.

We write Linker Scripts to do what the link step does:

A linker script is a configuration file that provides instructions to the linker about how to map sections of compiled code and data onto the target memory space. It specifies the layout of the program in memory, including where code, data, and other sections should be placed.

The linker script defines:

  1. Memory regions: It specifies the memory regions available on the target hardware and how they should be utilized (e.g., RAM, flash memory).
  2. Section placement: It determines where each section of the program (e.g., code, data, heap, stack) should be placed in memory.
  3. Initialization code: It can include instructions for initializing variables, setting up hardware peripherals, and performing other startup tasks.

By using a linker script, developers can control the memory layout of the program, optimize memory usage, and ensure that the program behaves correctly when executed on the target hardware.

Site of Action: This refers to the development environment where the software is created, typically a host PC with a cross-compiler specifically configured for the target CPU architecture, such as ARM Cortex-M0.

Compilation, Linking, and ELF Generation: The software development process involves compiling the source code into machine code, linking it with necessary libraries, and generating an Executable and Linkable Format (ELF) file, which contains the complete executable program along with debugging and linking information.

Debugger Box: This is a hardware device used for programming the ELF sections of the application into the non-volatile memories (such as flash memory) of the microcontroller. It assists in the deployment of the software onto the target hardware.

Startup Software: When the CPU is powered up, the startup software performs several essential tasks:

  1. Copies data sections of the application from flash memory to the microcontroller’s memory.
  2. Clears the Block Started by Symbol (BSS) addresses, which contain uninitialized global and static variables.
  3. Optionally copies time-critical program sections from flash memory to SRAM (Static Random Access Memory) for faster execution.
  4. Passes control to the main() function of the application, initiating its execution.

These steps ensure that the microcontroller is initialized properly, and the application starts executing as intended after power-up.

The instructions and data in these object files are more or less ready for flashing. BUT where must they be stored? What should be their address in memory?

  • .fasttext: This section specifies a custom section name, indicating fast-executing code. It includes the .text section of the Adc.o object file. The .text section typically contains executable code.
  • .data: This section includes initialized data. It collects all .data sections and .bss sections from input files. .data sections contain initialized global and static variables, while .bss sections contain uninitialized variables. These sections are placed in SRAM2, which likely represents a region of RAM.
  • .text: This section includes executable code. It collects all .text sections and .RODATA sections from input files. .text sections contain the program's executable code, while .RODATA sections contain read-only data. These sections are placed in FLASH, which typically represents the flash memory of the microcontroller.
  • > SRAM1, > SRAM2, > FLASH: These directives specify the memory regions where the sections should be placed. SRAM1 and SRAM2 likely represent regions of RAM, while FLASH represents the flash memory.

In this class, we learned about linker scripts and how they control the organization of our program’s sections in memory. For example, we used a linker script to specify where different parts of our program, like code and data, should be stored in the microcontroller’s memory. We defined custom sections like .fasttext for fast-executing code and specified memory regions like SRAM1 and FLASH. By understanding linker scripts, we learned how to optimize memory usage and improve the efficiency of our embedded systems projects which we will take on in the future.

--

--

Tabrez Ahmed
Tabrez Ahmed

Written by Tabrez Ahmed

Electronics & Communication Engineering graduate RV College of Engineering.

No responses yet