Getting Started Writing Portable Firmware

Developers who want to reuse software have several challenges to overcome in order to be successful. These challenges include but are not limited to:

  • Endianness
  • Processor architecture
  • Bus width
  • Ambiguous standards
  • Development time and budget
  • Modularity
  • Code coupling

Getting started can be overwhelming and lead to more stress and confusion than simply writing very functional code that is later discarded. The key to successfully developing portable code is to determine how well your firmware currently meets the portable software characteristics and once that is understood, decide where you want to go. To determine where you are today with developing portable firmware, start by drawing a diagram like that shown below. In the diagram, label each spoke with a portable firmware characteristic that is most important to your organization.

In each identified category, a developer can then evaluate how well their code exhibits these properties. For example, a developer who has been trying to transition into writing more portable code may evaluate themselves with a diagram result like the one below:

A quick look at the figure above can tell a developer a lot of information. First, we have strengths in documentation and modularity. That’s a great step towards developing portable firmware and we are just getting started. The figure also shows us where our weaknesses are such as code coupling and cohesion.
From this glance, we can now determine where we should start to focus our attention. Which characteristic if improved by just a couple points will most drastically improve our code? Let’s choose code coupling as example. If a developer is going to improve code coupling, they need to determine how they are going to go about making that improvement. They might decide that the best way to do this is to:

  • Schedule code reviews
  • Find a tool that can provide a module dependency graph
  • Use the dependency graph tool (just because we have a tool doesn’t mean we have the discipline to use it)
  • Develop a high-level architecture that considers module coupling

A developer may decide that improving in one area is good enough to start or that all need to be done. The point is that we aren’t going to start writing perfect, reusable code overnight. The process is iterative and may take a few years before all the rough edges are smoothed but that is okay. Below is a simple process that developers can use to improve their firmware portability:
1) Analyze their code characteristics
2) Identify strengths and weaknesses
3) Determine which characteristic to improve in the next 3 months
4) Identify what can be done to make the incremental improvement
5) Implement the improvement
6) After the specified period repeat

If you would like to learn more about how to develop reusable code, check-out “Developing Reusable Firmware – A Practical Approach to API’s, HAL’s and Drivers

Share >

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.