DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Is Podman a Drop-In Replacement for Docker?
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Effective Java Collection Framework: Best Practices and Tips
  • Microservices With Apache Camel and Quarkus

Trending

  • Is Podman a Drop-In Replacement for Docker?
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Effective Java Collection Framework: Best Practices and Tips
  • Microservices With Apache Camel and Quarkus
  1. DZone
  2. Coding
  3. Frameworks
  4. Linking Bootloader Applications with Eclipse and FreeMarker Scripts

Linking Bootloader Applications with Eclipse and FreeMarker Scripts

Learn more about linking BOOTloader applications with Eclipse and FreeMarker scripts.

Erich Styger user avatar by
Erich Styger
·
Oct. 09, 19 · Tutorial
Like (2)
Save
Tweet
Share
9.07K Views

Join the DZone community and get the full member experience.

Join For Free

linking BOOTloader apps

Learn more about linking BOOTloader applications with Eclipse and FreeMarker scripts.

Bootloaders are a fine thing. With them, I can load any applications I like. Power comes with some complexity, and a bootloader alone is a complex thing already. But this applies to the application part too. I need to link the application to a certain offset in the memory space so it can be loaded by the bootloader, plus the application typically needs to add some extra information to be used by the bootloader.

This article describes how to build a bootloader application with Eclipse (MCUXpresso IDE) using the MCUXpresso SDK. Let's get started.

You may also like: Flash Resident USB-HID Bootloader With the NXP Kinetis K22 Microcontroller

Build Configuration for Bootloader Application

Build Configuration for Bootloader Application

Outline

I’m using the Eclipse-based MCUXpresso IDE V11.0.1. Instead of ‘hacking’ the linker file, I’m using the built-in managed linker script way to automatically relocate the application to an address. In this tutorial: Porting BLE+NRF Kinetis Design Studio Project to MCUXpresso IDE, I already used the FreeMarker mechanism, but here, I show how it can be used on a higher level.

The needed files are available on GitHub.

Build Configuration

The idea is to switch between ‘no bootloader’ and ‘bootloader application at address’ using Eclipse Build Configurations. Create a new build configuration. Name it like “BL_<application offset>”, e.g. “BL_0xA000”:

Enabling Bootloader Configuration

The naming is important, because I’m going to recognize in a script if it is a bootloader application (starting with “BL_”) and at which address the application shall get linked too (Hexadecimal number).

Bootloader Configuration

The Bootloader needs configuration data. I have put it into a 'bootloader_config.c' and 'bootloader_config.h'. Add them to the project:

Bootloader Configuration

Bootloader Configuration

The bootloader configuration is only used in bootloader applications, so just turn it on with the following define in the project settings:

BL_HAS_BOOTLOADER_CONFIG

Enabling Bootloader configuration

Enabling Bootloader Configuration

FreeMarker Scripts

The IDE is using FreeMarker scripts, which is a powerful way to generate linker script files. We are now going to extend and overwrite some of the default files. Create a folder named ‘linkscripts’ (Naming is important!) inside the project and create three files (you can copy them from GitHub):

  • user.ldt: This contains user variables used in the other scripts
  • crp.ldt: This contains placement of the bootloader configuration data
  • memory.ldt: This defines the linker memory ranges

The user.ldt uses the build configuration name to generate linker variables for the application offset and the configuration offset:

user.ldt

user.ldt

This is how it looks in the generated linker file:

Genearated Linker Variables

Generated Linker Variables

The crp.ldt is used to place the bootloader configuration data at the expected offset (0x340) inside the application memory after the vector table.

Inspecting the template files in <MCUXpresso IDE Installation Path>\ide\Wizards\linker, I see I could ‘misuse’ the ‘crp.ldt’ to place my bootloader descriptor after the vectors. Ideally, the IDE would provide a dedicated template or hook. Instead, I’m just making a copy of the existing crp.ldt and have it extended.

after vectors placement

After-Vectors Placement

Below, we have the result in the linker file:

Bootloader Configuration Data

Bootloader Configuration Data

The correct placement can be verified, e.g. with EHEP:

Bootloader Configuration Data in Binary

Bootloader Configuration Data in Binary

Finally, the memory.ldt is building the memory map in the linker file with the application offset:

Memory Map with Bootloader

Memory Map with Bootloader

So, based on the Build Configuration name, it automatically links the application to the correct memory area!

Build Configuration for Bootloader Application

Summary

Using FreeMarker custom scripts and Eclipse Build Configurations, I can automatically build and link an application to be used with a bootloader. And I can use a ‘normal’ debug configuration to build and debug the application without the need for a bootloader.

Happy FreeMarking!

References

  • FreeMarker homepage
  • FreeMarker tutorial
  • Tutorial: Porting BLE+NRF Kinetis Design Studio Project to MCUXpresso IDE
  • Bootloader with KL03Z: Getting Started: ROM Bootloader on the NXP FRDM-KL03Z Board
application FreeMarker Eclipse Build (game engine)

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Is Podman a Drop-In Replacement for Docker?
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Effective Java Collection Framework: Best Practices and Tips
  • Microservices With Apache Camel and Quarkus

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: