Email or username:

Password:

Forgot your password?
niconiconi

Embedded programmers routinely do serious hacks in the firmware. One technique is token passing, every time before calling and returning from a function, one sets one (or multiple) global variable to an unique value and double checks it for consistency. Other tricks include saving multiple copies of critical data, or repeating if-else checks multiple times.

The idea is to make code safer to run on general-purpose, non-fault-tolerate CPU. If CPU malfunctions and goes out of control due to external electrical interference like EMI and ESD, the code has a chance to catch it, recover, or at least reset the system.

Software developers who see computers as a platonic machine approximation of pure logic would find it's just madness. Meanwhile, for hardware designers, software is just programmable hardware. If adding more logic gates for redundancy is reasonable, adding more code is also reasonable, and not necessary a "hack."

The real problem is that it's 2022 and most compilers and other devtools still don't have any built-in support to automate this task. Often, everyone still has to do it manually by hand.
​:blobcatfacepalm:​ Software security experts (on Control-Flow Integrity, Stack Canaries, Address Sanitizer, or other compiler-level mitigations) should seriously help saving embedded system developers by applying their expertise in the hardware field and making them standard features in software toolchains. #electronics

/* token passing with global function ID */
char gFunctionID = 0;
void FunktionA(void);

void main() {
    gFunktionId = 'A';
    FunktionA();
    if (gFunctionId != 'M') { Print("Invalid IP"); }
}

void FunktionA(void) {
    if (gFunctionID != 'A') Print("Invalid IP");
    DoSomething();
    gFunctionId = 'M';
}
1 comment
:umu: :umu:
@niconiconi I had to store backup state in my RAM tester just in case the RAM it's testing is really faulty.

That time I learned that computers are not always ideal and there is a lot of work done on testing before the exact sample goes to end consumer.
Go Up