
Circling back to day 20's "oh, THAT'S why flash size matters" moment — today I got to see the practical, day-to-day version of that problem, and it wasn't what I expected. I assumed firmware engineering time skews heavily toward adding things. Wei showed me a build log and a linker map file, and it turned out a meaningful chunk of his recent time went the other direction.
"Flash budget" is the constraint that a compiled firmware image has to fit inside a fixed-size OTA slot — the slot size doesn't change; it was decided back when the memory layout was designed, tied to the physical flash size on the chip and however the partitioning splits it between bootloader, slot A, slot B, and anything else reserved (settings storage, for instance). The firmware image is everything that got compiled and linked in: your application code, whatever RTOS or scheduler you're using, the radio and mesh stack, crypto libraries, logging, and any bundled assets. All of that has to add up to less than the slot size — with margin left over, ideally, not just barely squeezing in.
That margin is the part I hadn't thought about. If an image is sitting at, say, 95% of slot capacity, there's almost no room to add a bug fix, let alone a feature, without first doing something to shrink the existing image. And shrinking an already-tight image is a lot more annoying than writing new code, because you're often fighting things you didn't put there directly — a library you use for one small piece of functionality that happens to pull in a lot more than you need, or debug/logging strings that quietly accumulate in flash as text, or compiler settings that favor speed over size.
The actual toolbox for this, from what I saw today, includes: reading the linker's map file to see which symbols are actually taking up space (Wei pulled up a build and sorted sections by size, which I didn't know was a normal thing to do); stripping unused code paths and disabling features that aren't needed for a given build variant; trimming verbose log strings or moving them out of the default build; and sometimes swapping a heavier library for a leaner one that does less but covers what's actually needed. None of this is glamorous, and none of it shows up as a new feature in release notes, but apparently it's what keeps future OTA updates possible at all — if the image ever actually hits the ceiling, the fix isn't "optimize a bit more," it's a much bigger, more invasive change to the memory layout itself, which is its own project.
I asked whether Siliqs' mesh firmware is currently comfortable on flash budget or getting tight — Wei was noncommittal in a way that made me think the honest answer is "it depends on which build variant, ask me again after the next release," so I'm not going to guess at numbers here. For today, the real lesson was just recalibrating my mental model of what firmware work actually looks like day to day — a lot less "add," a lot more "does this actually need to be in here."

回頭接一下 day 20 那個「喔,原來這就是為什麼 flash 大小很重要」的頓悟——今天終於看到這個問題在日常工作裡實際長什麼樣子,跟我想的不太一樣。我原本以為韌體工程的時間大多偏向「加東西」。Wei 給我看了一份 build log 跟 linker 產生的 map file,結果發現他最近有滿大一部分時間,其實是花在相反的方向。
「flash budget」指的是:編譯出來的韌體 image,必須塞進一個容量固定的 OTA slot 裡——slot 大小不會變,是在當初設計記憶體佈局時就決定好的,跟晶片實際的 flash 容量、以及怎麼把它切給 bootloader、slot A、slot B,還有其他保留區塊(例如設定值儲存)綁在一起。韌體 image 包含所有被編譯、link 進去的東西:應用層 code、用的 RTOS 或排程器、radio 跟 mesh stack、加密函式庫、log 功能,還有任何附帶的資源檔。這一切加起來,必須小於 slot 的容量——理想上還要留有餘裕,而不是剛好卡著邊塞進去而已。
那個「餘裕」是我之前完全沒想過的部分。如果一份 image 已經佔到 slot 容量的,比方說 95%,那要加一個 bug fix,更別說加新功能,幾乎沒有空間可以動,除非先想辦法把現有 image 縮小。而縮小一個已經很緊的 image,比寫新 code 麻煩很多,因為你常常在對付一些不是你直接放進去的東西——比如某個 library 你只用了裡面一小塊功能,結果它把一堆你用不到的東西也一起拉進來;或是 debug/log 用的字串默默地以純文字的形式在 flash 裡越堆越多;或是編譯器設定偏向優化速度而不是體積。
照我今天看到的,實際會用到的工具箱包括:讀 linker 產生的 map file,看看到底是哪些 symbol 在佔空間(Wei 直接拉出一份 build,把各個 section 按大小排序,我原本不知道這是件很日常的事);砍掉用不到的程式路徑,把某個 build variant 不需要的功能關掉;把太囉唆的 log 字串精簡,或是移出預設的 build;有時候把比較肥的 library 換成功能較少、但剛好夠用的精簡版本。這些事情都不光鮮亮麗,release notes 裡也不會寫成一項新功能,但這似乎就是讓未來的 OTA 更新還能繼續進行下去的關鍵——如果 image 真的撞到容量天花板,那就不是「再優化一點」能解決的了,而是要動到記憶體佈局本身,一個更大、更侵入性的改動,本身就是另一個獨立的專案。
我問 Wei Siliqs 的 mesh 韌體目前 flash budget 是餘裕還是偏緊,他的回答有點含糊,感覺誠實的答案應該是「看是哪個 build variant,下次發版後再問我」,所以我今天不打算在這裡亂猜任何數字。今天真正學到的,是重新校正了自己對「韌體工作日常長怎樣」的想像——比想像中少很多「加東西」,多很多「這東西真的有必要留在裡面嗎」。