Living With 11% Margin: The Flash Budget on Our nRF54L15 Mesh Build

a bar chart showing flash storage almost completely used, labeled flash budget

I want to talk about a number that quietly shapes almost every decision I make on our nRF54L15 mesh firmware right now: 684 KiB. That's the size of the OTA update slot the build has to fit into, and as of the current build, we're using roughly 89% of it. Call it ~11% margin. Not zero, not comfortable — tight.

If you haven't lived inside a constrained OTA slot before, it's worth explaining why this number gets tight in the first place, because it's rarely one obvious culprit. It's more like several reasonable things all wanting a slice of the same finite pie.

The mesh and radio stack is the first big claim on space. Meshtastic-derived firmware isn't just "send a packet" — it's routing logic, neighbor tracking, flood/relay behavior, and the LoRa PHY driver underneath all of that. None of these pieces is huge on its own, but they compound.

Protocol buffers are the second. We use protobuf-style serialization for message encoding across the mesh, which is great for maintainability and cross-compatibility, but the generated code and the runtime support for encoding/decoding aren't free — every message type you support is a small tax, paid in flash.

Crypto is the third, and it's non-negotiable. Channel encryption isn't optional in a mesh product that's going out into the field, so whatever crypto library and key-handling code is in the image, it stays in the image.

And then there's the usual RTOS/HAL layer — the scheduler, the peripheral drivers, the SDK glue code that talks to the nRF54L15's peripherals. This is the "cost of doing business" layer that every embedded project pays, and it's easy to forget it's there until you're staring at a linker map wondering where 60 KiB went.

None of these categories is wrong to include. That's what makes flash budget hard — it's not a case of finding one bloated thing to cut, it's four or five legitimate consumers all competing for the same 684 KiB, and each one has a good reason to exist.

What ~11% margin actually feels like day to day

Here's the part I think doesn't get talked about enough: a tight flash budget isn't a one-time problem you solve and move on from. It's a standing constraint that changes how you think about every future change. Want to add a feature? First question isn't "is this a good idea," it's "does this fit, and if not, what do I cut to make room." Want to fix a bug that happens to need a few more bytes of state tracking or an extra log string? Same question. Even routine dependency updates — a newer version of a library that happens to add a few KiB — now carry a flash-budget review that they wouldn't carry if we had 40% headroom instead of 11%.

It changes the shape of code review too. I've started looking at pull requests with an eye toward "what does this cost in flash" the same way I'd look at CPU cycles in a hot loop — not because every few hundred bytes matters existentially, but because at 11% margin, a handful of "small, harmless" additions can eat the remaining headroom faster than you'd expect.

I don't have a specific line-item breakdown of exactly what's consuming the 89% to share here — that's not the kind of number I want to guess at publicly — but the categories above are real and they're the ones I keep coming back to when I'm looking for room to breathe. For now, we fit. The honest framing is that "we fit" and "we have a comfortable amount of room" are two different statements, and right now only the first one is true. Managing that gap is just part of the job on this build for the foreseeable future.

長條圖顯示 flash 空間幾乎用滿,標示 flash budget

有個數字最近默默影響著我在 nRF54L15 mesh 韌體上幾乎每一個決定:684 KiB。這是這個 build 必須塞進去的 OTA update slot 大小,而目前的 build 大約用掉了 89%。換算下來大概剩 ~11% 的餘裕。不是零,但也稱不上寬鬆——很緊。

如果你沒經歷過在有限 OTA slot 裡討生活的日子,值得先解釋一下這個數字為什麼會變這麼緊,因為通常不是單一明顯的元兇,而是好幾個「合理」的東西同時在搶同一塊有限的餅。

Mesh 跟 radio stack 是第一大宗。基於 Meshtastic 的韌體不只是「送個封包」而已——底下還有路由邏輯、鄰居追蹤、flood/relay 行為,以及最底層的 LoRa PHY driver。每一塊單獨看都不算大,但加總起來就很可觀。

Protocol buffers 是第二個。我們在 mesh 上用 protobuf 風格的序列化來做訊息編碼,這對維護性跟跨版本相容性很有幫助,但產生出來的程式碼以及 encode/decode 的 runtime 支援都不是免費的——每多支援一種訊息型別,就是 flash 上一筆小小的稅。

Crypto 是第三項,而且這項沒得商量。對一個要真的部署到現場的 mesh 產品來說,channel encryption 不是選配,所以不管用的是哪套 crypto library 跟金鑰處理程式碼,它就是要留在 image 裡。

再來就是常見的 RTOS/HAL 層——排程器、周邊裝置驅動、跟 nRF54L15 周邊溝通的 SDK 膠水程式碼。這是每個嵌入式專案都要付的「基本開銷」層,容易被忘記,直到你盯著 linker map 想「這 60 KiB 到底去哪了」。

上面這些類別沒有一個是「不該放」的。這正是 flash 預算難搞的地方——不是找出一個肥大的東西砍掉就好,而是四五個都有正當理由存在的消費者,同時在搶同一塊 684 KiB。

~11% 餘裕在日常裡實際是什麼感覺

我覺得這部分比較少被講到:緊繃的 flash 預算不是解決一次就過去的問題,而是一個持續存在的限制,會改變你看待往後每個變更的方式。想加個功能?第一個問題不是「這是不是個好點子」,而是「這塞得進去嗎,塞不進去的話要砍什麼」。想修個 bug,但剛好需要多幾個 byte 的狀態追蹤或多一行 log?一樣的問題。就連例行的相依套件更新——某個 library 出了新版本,剛好多佔了幾 KiB——現在也得經過 flash 預算的審查,如果我們有 40% 餘裕而不是 11%,這一步根本不需要。

這也改變了 code review 的樣子。我開始用看熱路徑裡 CPU cycle 的心態去看 pull request 對 flash 的花費——不是因為每幾百個 byte 都攸關生死,而是在只剩 11% 餘裕的情況下,幾個「小小的、無傷大雅」的追加,吃掉剩餘餘裕的速度會比你想像的快。

我手邊沒有那 89% 具體是哪些項目佔掉的逐條明細可以分享——這種數字我不想公開用猜的——但上面這幾個類別是真實存在的,也是我每次要找空間喘口氣時,腦中會反覆想到的。就目前而言,我們塞得進去。但誠實地說,「塞得進去」跟「有寬裕的空間」是兩句不一樣的話,現在只有前一句是真的。可預見的未來裡,管理這個落差就是這個 build 的日常工作之一。