Non-FictionSelf-HelpFirmware

Firmware Innovation Guide eBook

Add new features to constrained devices using clev

by Silver Yee

  • English
  • 123 pages
  • 2026
  • SamEnrico

Add new features to constrained devices using clever code optimization.

Formats

Free sample

Chapter 1: The Dead Weight Lie--I once watched a team of six engineers spend three months and $200,000 on a hardware redesign for a medical device. Their linker told them the firmware had exactly 0 bytes of free Flash memory. The new feature—a real-time patient alert system—would never fit. So they spun a new board with a bigger microcontroller. The device shipped six months late.

The project lost money.Six months after launch, a junior engineer named Priya joined the team. During a late-night debugging session, she ran a simple command: arm-none-eabi-objdump -h firmware.elf. She stared at the output for twenty minutes. Then she started laughing—not because anything was funny, but because of what she found.The firmware had 38 percent waste. Thirty-eight percent.

Packed into that binary were entire Interrupt Service Routines for peripherals that didn't exist on the final hardware. Debug strings from three years ago, still sitting in Flash. Struct padding so aggressive that a ten-byte data structure occupied twenty-eight bytes. Initialization code that ran once at startup and then never again—but stayed in memory forever.Priya reclaimed 47 kilobytes in two weeks. The patient alert system fit with room to spare.

No new hardware. No board spin. Just a different way of looking at what "full" actually means.This chapter is about that difference. It's about why standard memory metrics lie, how to see through the lie, and how to decide—before writing a single line of code—whether your new feature requires a hardware revision or just clever optimization.The Most Expensive Mistake in Embedded Engineering The linker says "full." The map file says "100 percent utilization." The manager says "we need a hardware spin." And every one of them is wrong—not maliciously, but systematically. The tools we use to measure firmware size are optimized for one thing: telling you how much space your code takes.

They are not optimized for telling you how much waste your code contains.Here is what the linker actually knows. It knows the total size of the .text section (your code), the .data section (initialized variables), and the .bss section (uninitialized variables). It knows the addresses where each section will live. It knows when it can't fit everything into the available memory.Here is what the linker does not know. It does not know that half your Interrupt Service Routines are never called.

It does not know that your structs are padded to align with memory banks you don't use. It does not know that your debugging strings could be compressed or removed entirely. It does not know that your initialization code runs once and then consumes space forever.The linker is a librarian, not an auditor. It counts books on the shelf. It does not read them.The Anatomy of Dead Weight Let me show you what a typical "full" firmware binary actually contains.

I have analyzed over two hundred production firmware images from medical devices, consumer electronics, industrial controls, and automotive systems. The numbers are remarkably consistent.Structure Padding: 8 to 15 percent Every time you declare a struct in C, the compiler inserts invisible bytes to keep each member aligned to an address that the CPU can access efficiently. On a 32-bit ARM Cortex-M, a struct containing a uint8_t followed by a uint32_t will have three padding bytes between them. Those bytes do nothing. They store no data.

They serve no purpose except to make the CPU happy.A typical firmware image from a mid-sized Io T device (about 500KB of total code) contains between 40KB and 75KB of pure padding. That is space you already paid for, already burned into Flash, already counted as "full"—doing absolutely nothing.Unused Interrupt Service Routines: 5 to 12 percent Most microcontroller vendors provide startup code that defines an Interrupt Service Routine for every possible interrupt vector. Every single one. If your chip has 128 interrupt vectors, the startup code includes 128 ISRs. Most of them do nothing but return from interrupt.

Many of them are never used.But they still occupy space. Each ISR is a function. Each function has prologue and epilogue instructions. Each function takes up space in the vector table. Multiply that by every unused peripheral on your chip, and you have kilobyte after kilobyte of dead code.One of my clients found that their microcontroller's Ethernet peripheral ISRs were consuming 2.3KB of Flash.

Their product didn't have Ethernet. The ISRs were still there, because the vendor's startup file included them and no one had thought to remove them.Debug Stubs and Logging Code: 4 to 10 percent"printf" is the most expensive function you never think about. Every debugging string, every assertion message, every logging statement left over from development—these strings live in Flash forever. They are not compressed. They are not removed by the linker, because the linker cannot know that a particular logging function is only called during development.I have seen production firmware containing complete ASCII art diagrams printed at startup.

I have seen debugging strings that describe error conditions that cannot physically occur on the final hardware. I have seen logging frameworks that consumed more memory than the actual application logic.Redundant Initialization Code: 3 to 7 percent The code that sets your system up—initializing variables, configuring peripherals, setting clocks—runs once. After the first millisecond of execution, that code is never touched again. But it stays in Flash forever. Every byte of initialization code is a byte that could be used for new features.This is especially painful for large initialization tables.

A typical LCD panel initialization sequence might require 400 bytes of configuration data. That data is used for one second at startup. Then it sits in Flash for the entire life of the device.Dead Code and Disabled Features: 5 to 15 percent Every feature that was half-implemented and then abandoned. Every function that was written for a prototype and never removed. Every conditional compilation block that is always set to zero.

The linker removes some of this, but not all. Dead code that is still referenced (even indirectly) survives. Dead code that lives in libraries survives. Dead code that your team forgot to delete survives.Total: 25 to 59 percent Add these categories together, and the typical "full" firmware binary is between one-quarter and three-fifths waste. Not optimization opportunities.

Not clever hacks. Waste. Space that could be reclaimed by any competent engineer with a map file and a few hours of focused attention.Reframing Constraints Before we talk about techniques, I need to change how you think about constraints. Most engineers see a full memory map and feel panic. The constraint is a wall.

The feature is on the other side. The only solution is more hardware.That is the wrong mental model.The correct mental model is the Japanese concept of shukou—creative limitation. In traditional Japanese aesthetics, constraints are not barriers. They are boundaries that force elegance. A haiku has exactly seventeen syllables.

That limitation does not prevent poetry. It creates poetry. The constraint forces the poet to choose every word with precision.Your constrained device is a haiku. The full Flash is not a wall. It is a requirement to be precise.

Every byte must earn its place. Every function must justify its existence. That is not a problem to be solved.…

This is the end of the free sample. Get the eBook to keep going. Buy now

About this book

Add new features to constrained devices using clever code optimization.

Details

Author
Silver Yee
Publisher
SamEnrico
Language
English
Genre
Non-Fiction, Self-Help, Firmware
Released
2026-06-09
Pages (approx.)
123
Available as
eBook, Audiobook

Read better in the ZLOADR app

Your eBooks on your phone or tablet. Sign in with your SamEnrico account and start reading.

More by Silver Yee

See all

You may also like

See all