Firmware not being built properly

I am having some issues with the firmware that I'm bulding locally not working. I am able to flash my device via the online IDE just fine, and I can even download the .bin from the online IDE and flash it to my device no problem, so it seems there's just an issue with things not being built correctly.

I am compiling my firmware locally. I have installed the toolchain and I've successfuly been able to flash tinker (and my own custom applications) onto a photon with the command

make PLATFORM=photon APP=tinker program-dfu

however when I simply change "PLATFORM=photon" to "PLATFORM=electron" and attempt to flash tinker to my electron, the device enters safe mode and the user application is not executed.

Upon putting the electron into serial mode and sending the "s" command via a terminal I get the following output:

{"p":10,
"imei":"35316xxxxxxxx",
"iccid":"893407650xxxxxxxxx",
"m":[{"s":16384,"l":"m","vc":30,"vv":30,"f":"b","n":"0","v":6,"d":[]},
     {"s":131072,"l":"m","vc":30,"vv":30,"f":"s","n":"1","v":10,"d":[]},
     {"s":131072,"l":"m","vc":30,"vv":30,"f":"s","n":"2","v":10,"d":[{"f":"s","n":"1","v":10,"_":""}]},		    
     {"s":131072,"l":"m","vc":30,"vv":26,"u":"6D39B3A5B3573AC3F330AE1B963BEE6DD72B26EF918F9A257AD90B47A80A3302","f":"u","n":"1","v":4,"d":[{"f":"s","n":"2","v":30,"_":""}]},
     {"s":131072,"l":"f","vc":30,"vv":0,"d":[]}
]
}

I researched this a little and found that the vc != vv is not a good thing, meaning the firmware did not pass all the verification checks. However, when I change the platform to photon and flash tinker to my photon device I have laying around, I get a similar output, but with vc and vv being equal in all instances where they appear. Is there anything else I need to do besides changing the platform to build for the electron?

I have tried re-installing the toolchain, but that did not help. I have tried this on both the develop and latest branch, both with the same results. I have also ran it with the "clean all" command. Anyone have any idea what's going on here?

Build output:

C:\firmware\main>make PLATFORM=electron APP=tinker program-dfu
make -C ../modules/electron/user-part program-dfu
make[1]: Entering directory `/c/firmware/modules/electron/user-part'
make -C ../../../user
make[2]: Entering directory `/c/firmware/user'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/c/firmware/user'
make -C ../../../hal-dynalib
make[2]: Entering directory `/c/firmware/hal-dynalib'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/c/firmware/hal-dynalib'
make -C ../../../services-dynalib
make[2]: Entering directory `/c/firmware/services-dynalib'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/c/firmware/services-dynalib'
make -C ../../../system-dynalib
make[2]: Entering directory `/c/firmware/system-dynalib'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/c/firmware/system-dynalib'
make -C ../../../rt-dynalib
make[2]: Entering directory `/c/firmware/rt-dynalib'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/c/firmware/rt-dynalib'
make -C ../../../wiring
make[2]: Entering directory `/c/firmware/wiring'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/c/firmware/wiring'
make -C ../../../communication-dynalib
make[2]: Entering directory `/c/firmware/communication-dynalib'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/c/firmware/communication-dynalib'
make -C ../../../platform
make[2]: Entering directory `/c/firmware/platform'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/c/firmware/platform'
make -C ../../../wiring_globals
make[2]: Entering directory `/c/firmware/wiring_globals'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/c/firmware/wiring_globals'
Building target: ../../../build/target/user-part/platform-10-m/tinker.elf
Invoking: ARM GCC C++ Linker
mkdir -p ../../../build/target/user-part/platform-10-m/
arm-none-eabi-g++ -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_I
D=10 -DPLATFORM_NAME=electron -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD00A -DUS
BD_PID_CDC=0xC00A -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1
 -fno-builtin -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=
0.5.0 -DRELEASE_BUILD -Werror -I../../../user/inc -I../../../dynalib/inc -I../..
/../services/inc -I../../../hal/inc -I../../../hal/shared -I/rtos/FreeRTOSv8.2.2
/FreeRTOS/Source/include -I/rtos/FreeRTOSv8.2.2/FreeRTOS/Source/portable/GCC/ARM
_CM3 -I../../../hal/src/electron -I../../../hal/src/stm32f2xx -I../../../hal/src
/stm32 -I../../../system/inc -I../../../rt-dynalib/inc -I../../../wiring/inc -I.
./../../modules/electron/system-part1/inc -I../../../modules/shared/stm32f2xx/in
c -I../../../platform/shared/inc -I../../../platform/MCU/STM32F2xx/CMSIS/Include
 -I../../../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../../../platform/M
CU/STM32F2xx/SPARK_Firmware_Driver/inc -I../../../platform/MCU/shared/STM32/inc
-I../../../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../../../platform
/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../../../platform/MCU/STM32F2xx/STM
32_USB_Host_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/in
c -I. -MD -MP -MF ../../../build/target/user-part/platform-10-m/tinker.elf.d -ff
unction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declara
tions -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -DSTART_DFU
_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -fno-built
in-malloc -fno-builtin-free -fno-builtin-realloc -DUSER_FIRMWARE_IMAGE_SIZE=0x20
000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x8080000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSI
ON=4 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,13 ../../../bu
ild/target/user-part/platform-10-m/src/module_info.o ../../../build/target/user-
part/platform-10-m/src/user_export.o ../../../build/target/user-part/platform-10
-m/src/user_module.o ../../../build/target/user-part/platform-10-m/src/newlib_st
ubs.o  --output ../../../build/target/user-part/platform-10-m/tinker.elf -nostar
tfiles -Xlinker --gc-sections -L../../../build/arm/linker/stm32f2xx  -L../../../
build/target/user/platform-10-m/applications/tinker/ -L../../../build/target/ser
vices-dynalib/arm/ -L../../../build/target/hal-dynalib/platform-10-m/ -L../../..
/build/target/system-dynalib/platform-10-m/ -L../../../build/target/rt-dynalib/p
latform-10-m/ -L../../../build/target/wiring/platform-10-m/ -L../../../build/tar
get/communication-dynalib/platform-10-m/ -L../../../build/target/platform/platfo
rm-10-m/ -L../../../build/target/wiring_globals/platform-10-m/ -L../../../build/
arm/linker -Wl,--whole-archive -luser -lhal-dynalib -lservices-dynalib -lsystem-
dynalib -lrt-dynalib -lwiring -lcommunication-dynalib -lplatform -lwiring_global
s -Wl,--no-whole-archive -lnosys --specs=nano.specs -L../../../modules/electron/
system-part2 -L../../../modules/electron/system-part1 -L. -T./linker.ld -Wl,--de
fsym,USER_FIRMWARE_IMAGE_SIZE=0x20000 -Wl,--defsym,USER_FIRMWARE_IMAGE_LOCATION=
0x8080000 -Wl,-Map,../../../build/target/user-part/platform-10-m/tinker.map

Invoking: ARM GNU Create Flash Image
arm-none-eabi-objcopy -O binary ../../../build/target/user-part/platform-10-m/ti
nker.elf ../../../build/target/user-part/platform-10-m/tinker.bin.pre_crc
if [ -s ../../../build/target/user-part/platform-10-m/tinker.bin.pre_crc ]; then
 \
        head -c $((`stat --print %s ../../../build/target/user-part/platform-10-
m/tinker.bin.pre_crc` - 38)) ../../../build/target/user-part/platform-10-m/tinke
r.bin.pre_crc > ../../../build/target/user-part/platform-10-m/tinker.bin.no_crc
&& \
        tail -c 38 ../../../build/target/user-part/platform-10-m/tinker.bin.pre_
crc > ../../../build/target/user-part/platform-10-m/tinker.bin.crc_block && \
        test "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2028
0078563412" = `xxd -p -c 500 ../../../build/target/user-part/platform-10-m/tinke
r.bin.crc_block` && \
        shasum -a 256 ../../../build/target/user-part/platform-10-m/tinker.bin.n
o_crc | cut -c 1-65 | xxd -r -p | dd bs=1 of=../../../build/target/user-part/pla
tform-10-m/tinker.bin.pre_crc seek=$((`stat --print %s ../../../build/target/use
r-part/platform-10-m/tinker.bin.pre_crc` - 38)) conv=notrunc  && \
        head -c $((`stat --print %s ../../../build/target/user-part/platform-10-
m/tinker.bin.pre_crc` - 4)) ../../../build/target/user-part/platform-10-m/tinker
.bin.pre_crc > ../../../build/target/user-part/platform-10-m/tinker.bin.no_crc &
& \
         crc32 ../../../build/target/user-part/platform-10-m/tinker.bin.no_crc |
 cut -c 1-10 | xxd -r -p | dd bs=1 of=../../../build/target/user-part/platform-1
0-m/tinker.bin.pre_crc seek=$((`stat --print %s ../../../build/target/user-part/
platform-10-m/tinker.bin.pre_crc` - 4)) conv=notrunc ;\
        fi
32+0 records in
32+0 records out
32 bytes (32 B) copied, 0.019 seconds, 1.7 kB/s
4+0 records in
4+0 records out
4 bytes (4 B) copied, 0.282 seconds, 0.0 kB/s
[ ! -f ../../../build/target/user-part/platform-10-m/tinker.bin ] || rm ../../..
/build/target/user-part/platform-10-m/tinker.bin
mv ../../../build/target/user-part/platform-10-m/tinker.bin.pre_crc ../../../bui
ld/target/user-part/platform-10-m/tinker.bin

dfu-suffix -v 2B04 -p D00A -a ../../../build/target/user-part/platform-10-m/tink
er.dfu
dfu-suffix (dfu-util) 0.8

Copyright 2011-2012 Stefan Schmidt, 2013-2014 Tormod Volden
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Suffix successfully added to file
Serial device PARTICLE_SERIAL_DEV : not available
Flashing using dfu:
dfu-util -d 0x2B04:0xD00A -a 0 -s 0x8080000:leave -D ../../../build/target/user-
part/platform-10-m/tinker.dfu
dfu-util 0.8

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2014 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Opening DFU capable USB device...
ID 2b04:d00a
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 4096
DfuSe interface name: "Internal Flash   "
Downloading to address = 0x08080000, size = 6272
Download        [=========================] 100%         6272 bytes
Download done.
File downloaded successfully
make[1]: Leaving directory `/c/firmware/modules/electron/user-part'

C:\firmware\main>pause
Press any key to continue . . .

I see this occasionally. I find that deleting the firmware/build/target directory clears up the problem. Sometimes make clean PLATFORM=electron will fix it as well, but deleting the target directory seems more reliable to me, anecdotally. If you build your app using an external directory APPDIR=/path/tosomething, also delete the target directory in your APPDIR.

1 Like

What branch are you building?
If it’s a develop branch, you might need to add PARTICLE_DEVELOP=1

Entering Safe Mode also indicates that the app version you built and the installed system version on the device don’t match.
Have you updated your system firmware too?

What does particle serial inspect tell you about the versions of the installed modules?
The 10s in this line indicate that you are not up to date with the system

     {"s":131072,"l":"m","vc":30,"vv":30,"f":"s","n":"1","v":10,"d":[]},
     {"s":131072,"l":"m","vc":30,"vv":30,"f":"s","n":"2","v":10,"d":[{"f":"s","n":"1","v":10,"_":""}]},		    

0.5.1 should show you 15 for s1 v and s2 v.

I think the same build works on your Photon because Safe Mode Healer (or you previously) has updated your system firmware in the past already, but for the Electron Safe Mode Healer won’t kick in to save your precious data allowance.
So you need to flash either your own system parts or you update to the official 0.5.1 version as shown in the release notes.

You could also perform a particle serial inspect on the Photon and check the differences.

1 Like

What Scruff said. I didn’t see that you were building from firmware/main. Build from the firmware/modules directory, instead, and it will upload the system firmware that matches the tree you checked out using dfu-util. I was thinking you were already doing that.

2 Likes

Updated to system firmware version 0.5.1 and it works! Seems like such a simple fix in hindsight. Thank you guys very much for your help.

1 Like