Lesson 9. Building Embedded Software Part 1: Concepts

Gene Schroeder Tech
5 Jul 202115:11

Summary

TLDRThis lesson delves into the intricacies of building software in embedded systems, focusing on key concepts like sections and symbols in the compilation and linking process. It explains how different data types, such as machine code, global/static variables, and read-only data, are organized into sections like .text, .data, and .bss, and mapped into memory. The video also covers the role of symbols in linking, including how unresolved symbols are handled and resolved during the build process. The content is essential for embedded developers who must understand memory allocation and software construction from the ground up.

Takeaways

  • 😀 Building software is a complex process, especially in embedded systems, where you're responsible for managing everything from memory allocation to interrupts.
  • 😀 Understanding sections in a build system is crucial. Sections organize data types such as machine code instructions, global/static variables, and others into memory.
  • 😀 Key sections in software build include `.text` (machine code), `.data` (initialized global/static variables), `.bss` (uninitialized variables), and `.rodata` (read-only data).
  • 😀 Variables like global/static ones are assigned to different sections based on whether they have initial values or not, which impacts where they are stored in memory.
  • 😀 The stack and heap sections manage memory for automatic variables and dynamic memory allocation, respectively, and are typically stored in RAM.
  • 😀 The linker’s role is to assign memory addresses to functions and variables, resolving symbol names and turning object code into executable code.
  • 😀 Unresolved symbols occur when the compiler encounters external functions or variables (like `printf`), which are later resolved during linking.
  • 😀 Symbols are essentially names with associated values (memory addresses) for functions and global/static variables, which the linker must resolve to create a complete program.
  • 😀 After compiling `.c` files into object files (`.o`), the linker collates sections from multiple object files and maps them to appropriate memory locations.
  • 😀 Expert developers distinguish themselves by understanding how software is built and organized in memory, especially in bare-metal embedded systems where there is no OS to manage resources.
  • 😀 The build process involves assigning code and data to different areas of memory, including flash and RAM, based on the type of data (code, variables, etc.), a crucial step in embedded development.

Q & A

  • What are the four main sections in a compiled .o file?

    -The four main sections in a compiled .o file are: .text (machine code instructions), .data (global/static variables with non-zero initial values), .bss (global/static variables with no initial values, set to zero), and .rodata (read-only data, such as constant values).

  • What does the .text section contain in a compiled file?

    -The .text section contains the machine code instructions, which are the actual executable logic of the program.

  • Why are global and static variables with zero initial values placed in the .bss section?

    -Global and static variables without initial values are placed in the .bss section because they are automatically initialized to zero by the system, and placing them in the .bss section allows for efficient memory management.

  • What is the difference between a global variable and a static variable in C?

    -A global variable is accessible throughout the entire program, while a static variable is only accessible within the file or function in which it is defined, even though it retains its value between function calls.

  • What happens to symbols during the linking process?

    -During the linking process, unresolved symbols (such as external functions or variables) are assigned actual memory addresses, and the object code is modified to reflect these addresses, turning it into executable machine code.

  • What is the role of the linker in the build process?

    -The linker gathers data from multiple object files, organizes it into appropriate sections, assigns memory addresses to functions and variables, and resolves symbols to create the final executable machine code.

  • What is the significance of the .rodata section?

    -The .rodata section contains read-only data, such as global or static variables with constant values. These values cannot be modified during program execution.

  • Why is understanding how software is built important for embedded systems development?

    -Understanding how software is built is crucial for embedded systems because developers must manage memory, hardware initialization, and interrupt handling manually, unlike in environments with an operating system that handles these tasks automatically.

  • What happens when an unresolved external symbol is found during linking?

    -If an unresolved external symbol is found during linking (e.g., a missing function or variable), the linker will fail and generate an error because it cannot find the corresponding memory address for that symbol.

  • How does the compiler handle automatic (stack) variables in relation to sections?

    -The compiler does not assign stack variables (automatic variables) to any section like .data or .bss, because their memory is allocated on the stack at runtime and is not part of the static sections managed by the linker.

Outlines

plate

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。

今すぐアップグレード

Mindmap

plate

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。

今すぐアップグレード

Keywords

plate

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。

今すぐアップグレード

Highlights

plate

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。

今すぐアップグレード

Transcripts

plate

このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。

今すぐアップグレード
Rate This

5.0 / 5 (0 votes)

関連タグ
Embedded SystemsSoftware BuildingCode CompilationLinking ProcessMemory ManagementBare-metal ProgrammingC ProgrammingSections in CodeLinkerObject CodeEmbedded Development
英語で要約が必要ですか?