Search code examples
assemblyarmstm32firmwaremcu

What is this arm assembly init code doing?


This is part of the init code of a downloaded firmware of some stm32f030 microcontroller. It was disassembled using radare2. It is called after the clock has been initialized but before the heap is.

0x0800335c      00f00bf8       bl fcn.08003376
0x08003360      0028           cmp r0, 0       
0x08003362      01d0           beq 0x8003368   
0x08003364      fff7d4ff       bl INIT2        
0x08003368      0020           movs r0, 0
[...]
0x08003376      0120           movs r0, 1      
0x08003378      7047           bx lr           

As far as I can tell r0 gets always set to 1 so INIT2 is never skipped. I don't get the point. What am I missing?


Solution

  • I agree with ElderBug's interpretation in the comments that the first block of code is from a unit that supports multiple builds, and the second function is from a unit that has been configured for a particular build.

    Unless you edit the question to provide more detail, we can only guess at the purpose, but here is one plausible interpretation that is similar to code I have worked on:

    You want to skip heap initialization in INIT2 on a warm-boot, where RAM has been retained through a low-power mode. The particular binary you have doesn't support low-power modes so its function is hard-coded to return non-zero, but in another build it might read the power registers and can return zero if the RAM was retained.