Skip to content

Instantly share code, notes, and snippets.

@towynlin
Last active September 30, 2015 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save towynlin/c8a0c8ea6c246f4413ab to your computer and use it in GitHub Desktop.
Save towynlin/c8a0c8ea6c246f4413ab to your computer and use it in GitHub Desktop.
Getting Particle Devices to have Identical Firmware
1482c1482
< 0005c90: 0b50 686f 746f 6e2d 4342 4558 ffff ffff .Photon-CBEX....
---
> 0005c90: 0b50 686f 746f 6e2d 4433 3235 ffff ffff .Photon-D325....
1499,1537c1499,1537
< 0005da0: 025f 0201 0002 8181 00c2 b20a 811d 8590 ._..............
< 0005db0: e3da cdc5 3295 4159 76e2 4b56 6a49 4489 ....2.AYv.KVjID.
< 0005dc0: 1c70 3fb1 5690 bf14 a3be 80b8 cd2b dcfd .p?.V........+..
< 0005dd0: d36d 8b65 382a baec c664 a7ea d47c 6e01 .m.e8*...d...|n.
< 0005de0: 205e 7816 af6b 8d3a 4ea9 59cc ca96 e932 ^x..k.:N.Y....2
< 0005df0: d78a de45 3844 81bf 3ef4 821d 8df2 4111 ...E8D..>.....A.
< 0005e00: b54e 5e35 5aae 23cf d78c 31a4 6ba6 71ed .N^5Z.#...1.k.q.
< 0005e10: 0c7c a865 0e2a 3c0b 7b11 d3fa 1a7c 0795 .|.e.*<.{....|..
< 0005e20: 752c 1a3a 8b61 d5cd 6f02 0301 0001 0281 u,.:.a..o.......
< 0005e30: 8100 8a6b 8e70 518e de7e 40d7 bef5 c18b ...k.pQ..~@.....
< 0005e40: de91 593d fac8 4223 09e0 4025 e86d 0527 ..Y=..B#..@%.m.'
< 0005e50: f502 9db4 62ae ec1a 8813 c374 3198 8738 ....b......t1..8
< 0005e60: b292 3289 f7b8 ee66 3f42 c627 56e9 8ceb ..2....f?B.'V...
< 0005e70: b1a1 719f 1810 32df dfef fc98 9055 21b0 ..q...2......U!.
< 0005e80: 6392 a093 d233 37bc d48c 7d82 4caf b189 c....37...}.L...
< 0005e90: c8aa 3620 a307 9f8b cd94 ca66 d8e5 e151 ..6 .......f...Q
< 0005ea0: a554 88ee 612d 603b e113 ab07 d066 e169 .T..a-`;.....f.i
< 0005eb0: 8fa1 0241 00e9 4ff4 1424 6554 aafd 53c4 ...A..O..$eT..S.
< 0005ec0: d270 e5cc 47c3 b0f7 5f2c 1ec9 5e07 6255 .p..G..._,..^.bU
< 0005ed0: 2e1e 3bb1 de72 44d1 9f2d a636 5b03 ea4f ..;..rD..-.6[..O
< 0005ee0: f8d4 c114 b3a6 0770 3906 3bf9 cc5d aaca .......p9.;..]..
< 0005ef0: c622 5254 2702 4100 d5a0 c3ce 2d6b 3483 ."RT'.A.....-k4.
< 0005f00: 01fe 99f2 a235 1414 57ab 8526 a48d 7c35 .....5..W..&..|5
< 0005f10: e79e fa3d 2a22 3bfe 6785 80b9 50cf c5f1 ...=*";.g...P...
< 0005f20: 2c1c 44db 85a2 7c76 edb8 f208 0b4c 6b63 ,.D...|v.....Lkc
< 0005f30: a4d8 b5bd e035 2179 0241 000a 5c10 7c6c .....5!y.A..\.|l
< 0005f40: 794b 5f24 4c79 ead6 347d f399 cedb cd10 yK_$Ly..4}......
< 0005f50: 0a75 ea84 ed6a d6d7 64d3 2b0b 6bde daf0 .u...j..d.+.k...
< 0005f60: 8df6 cfe7 c699 b274 cff5 f95c 1fec 6dbb .......t...\..m.
< 0005f70: c721 fa5f 165c 569b e387 f502 4100 bd7f .!._.\V.....A...
< 0005f80: 2bf1 7a0c 7cba 314c bd16 a398 5dc5 65b7 +.z.|.1L....].e.
< 0005f90: 3a17 7b24 1e28 5adb 84b2 38eb c137 fc70 :.{$.(Z...8..7.p
< 0005fa0: 4a2d 1868 15f7 c6df 149d 7dbf 1295 146e J-.h......}....n
< 0005fb0: 5813 96a2 2528 7093 e333 18ed 4851 0241 X...%(p..3..HQ.A
< 0005fc0: 00de fd9a 45a3 5b26 2288 80bc 96e6 d876 ....E.[&"......v
< 0005fd0: df83 e207 d36d cdab da86 f81d 1826 20f5 .....m.......& .
< 0005fe0: 195c 0f56 54af a1db e25f 8a89 3074 55a3 .\.VT...._..0tU.
< 0005ff0: 04e8 ce4c 8ca9 53d7 32cf ab85 4837 862c ...L..S.2...H7.,
< 0006000: c5ff ffff ffff ffff ffff ffff ffff ffff ................
---
> 0005da0: 025f 0201 0002 8181 0080 c2df 0e45 900c ._...........E..
> 0005db0: 145e 7133 cdeb 2ee2 9cbe 9e40 c791 c965 .^q3.......@...e
> 0005dc0: fc07 1f21 fa4f c84d f264 1211 20f7 4305 ...!.O.M.d.. .C.
> 0005dd0: d77d e0e7 f884 2d02 ca8f 30ba f8d5 f4b6 .}....-...0.....
> 0005de0: 0233 8293 12d2 0a4b 1427 5e33 7db8 c9dd .3.....K.'^3}...
> 0005df0: a2ff fc0c d4fd e665 5bca 93a7 9d2b d02b .......e[....+.+
> 0005e00: 3b80 94ab 90c5 a6cf f47a 7af2 cef6 1b0a ;........zz.....
> 0005e10: 2db6 95c3 428b d35f c533 e9d3 efd0 ab59 -...B.._.3.....Y
> 0005e20: 9c2a 6bed f9db f4bf cb02 0301 0001 0281 .*k.............
> 0005e30: 8100 0190 dd1f 924e ff26 9c43 6a2a ddea .......N.&.Cj*..
> 0005e40: 530d 2ef0 43bf 6991 7671 0b31 20bb a78e S...C.i.vq.1 ...
> 0005e50: bb0b f095 9ba9 b7f8 13b1 1c31 c900 67b3 ...........1..g.
> 0005e60: 186e 9831 3284 e62d 34ad 702c ed56 f440 .n.12..-4.p,.V.@
> 0005e70: f5ca c34c bd5d 7717 1b02 4f4f d0af ff07 ...L.]w...OO....
> 0005e80: c8d5 c3e0 a39a 654c f8ad 2729 ae40 99ff ......eL..').@..
> 0005e90: 1f15 2b80 eddf 698a d7d7 21eb 578c 52af ..+...i...!.W.R.
> 0005ea0: 9d2d cd4c 7fa1 bf43 ef24 c887 726e 98b0 .-.L...C.$..rn..
> 0005eb0: 43d1 0241 00fb 84d9 46dc 9781 f331 bd30 C..A....F....1.0
> 0005ec0: 4d06 fa01 fe72 d2b1 0058 b57c 41e6 a477 M....r...X.|A..w
> 0005ed0: 61dd 8189 886a d3aa d445 1d12 55df 3a09 a....j...E..U.:.
> 0005ee0: 23da 2550 ce8c 4ddc f79e d06a 6159 a277 #.%P..M....jaY.w
> 0005ef0: 98f9 7d75 4902 4100 830e 2338 f65a 27d6 ..}uI.A...#8.Z'.
> 0005f00: e3b9 e20d 5ae3 7009 4790 4e9c 88c9 bf51 ....Z.p.G.N....Q
> 0005f10: 0546 273e 90dd f135 96d9 44a8 5467 3346 .F'>...5..D.Tg3F
> 0005f20: 1772 61e5 71c7 cc57 2f0f 9ee1 6c18 7970 .ra.q..W/...l.yp
> 0005f30: 3d99 efc7 a1a0 9073 0241 0055 c188 f781 =......s.A.U....
> 0005f40: 34e3 28d1 17a9 454a 10a9 e760 acf7 8e9f 4.(...EJ...`....
> 0005f50: b059 4a7a e22e 961e 9911 1483 1fe2 49f7 .YJz..........I.
> 0005f60: ba9e caca 8e96 1934 42ae d78d bcea 8f3f .......4B......?
> 0005f70: 05de 8f8c a939 4fde 18e9 8902 4100 2854 .....9O.....A.(T
> 0005f80: 0664 b5f2 4246 2f27 7937 50db a213 48f1 .d..BF/'y7P...H.
> 0005f90: 502f 7d2c 4ff2 17a4 61d9 2fed 0c17 c886 P/},O...a./.....
> 0005fa0: ad48 fb48 1290 2410 efad 1259 4039 27e3 .H.H..$....Y@9'.
> 0005fb0: 2faa 0080 7b86 1d7e ac39 8b34 049f 0241 /...{..~.9.4...A
> 0005fc0: 00de 9992 b42c 8f33 0d50 11f9 f583 4eef .....,.3.P....N.
> 0005fd0: 37e9 9523 2487 9657 35bc fa99 8ddc 4012 7..#$..W5.....@.
> 0005fe0: 20e3 8b1e acb7 a286 a5b3 c670 9f31 16b7 ..........p.1..
> 0005ff0: d8a1 a0b4 a769 cd39 1bdc 5ab8 870b bf17 .....i.9..Z.....
> 0006000: aaff ffff ffff ffff ffff ffff ffff ffff ................
1576,1584c1576,1584
< 0006270: 0381 8d00 3081 8902 8181 00c2 b20a 811d ....0...........
< 0006280: 8590 e3da cdc5 3295 4159 76e2 4b56 6a49 ......2.AYv.KVjI
< 0006290: 4489 1c70 3fb1 5690 bf14 a3be 80b8 cd2b D..p?.V........+
< 00062a0: dcfd d36d 8b65 382a baec c664 a7ea d47c ...m.e8*...d...|
< 00062b0: 6e01 205e 7816 af6b 8d3a 4ea9 59cc ca96 n. ^x..k.:N.Y...
< 00062c0: e932 d78a de45 3844 81bf 3ef4 821d 8df2 .2...E8D..>.....
< 00062d0: 4111 b54e 5e35 5aae 23cf d78c 31a4 6ba6 A..N^5Z.#...1.k.
< 00062e0: 71ed 0c7c a865 0e2a 3c0b 7b11 d3fa 1a7c q..|.e.*<.{....|
< 00062f0: 0795 752c 1a3a 8b61 d5cd 6f02 0301 0001 ..u,.:.a..o.....
---
> 0006270: 0381 8d00 3081 8902 8181 0080 c2df 0e45 ....0..........E
> 0006280: 900c 145e 7133 cdeb 2ee2 9cbe 9e40 c791 ...^q3.......@..
> 0006290: c965 fc07 1f21 fa4f c84d f264 1211 20f7 .e...!.O.M.d.. .
> 00062a0: 4305 d77d e0e7 f884 2d02 ca8f 30ba f8d5 C..}....-...0...
> 00062b0: f4b6 0233 8293 12d2 0a4b 1427 5e33 7db8 ...3.....K.'^3}.
> 00062c0: c9dd a2ff fc0c d4fd e665 5bca 93a7 9d2b .........e[....+
> 00062d0: d02b 3b80 94ab 90c5 a6cf f47a 7af2 cef6 .+;........zz...
> 00062e0: 1b0a 2db6 95c3 428b d35f c533 e9d3 efd0 ..-...B.._.3....
> 00062f0: ab59 9c2a 6bed f9db f4bf cb02 0301 0001 .Y.*k...........
1612c1612
< 00064b0: ffff ffff ffff ffff 4342 4558 ffff ffff ........CBEX....
---
> 00064b0: ffff ffff ffff ffff 4433 3235 ffff ffff ........D325....

How to Verify 2 Particle Devices Have Identical Firmware

I just built all of the included binaries on the release/v0.4.5 branch, at commit 72b855bc7c158c893c1166b57f5437e9032ddb32.


Unlock Flash

First, make sure the bootloader flash pages are unlocked by installing the unlocker application as well as the v0.4.5 system modules it requires. Run each of the commands below, one at a time, making sure the device is in DFU mode before running each command.

Photon:

dfu-util -d 2b04:d006 -a 0 -s 0x08020000 -D system-part1-v0.4.5-photon.bin

dfu-util -d 2b04:d006 -a 0 -s 0x08060000 -D system-part2-v0.4.5-photon.bin

dfu-util -d 2b04:d006 -a 0 -s 0x080a0000 -D unlocker-v0.4.5-photon.bin

P1:

dfu-util -d 2b04:d008 -a 0 -s 0x08020000 -D system-part1-v0.4.5-p1.bin

dfu-util -d 2b04:d008 -a 0 -s 0x08060000 -D system-part2-v0.4.5-p1.bin

dfu-util -d 2b04:d008 -a 0 -s 0x080a0000 -D unlocker-v0.4.5-p1.bin

After flashing the unlocker, be sure to wait for the RGB LED to turn solid green. It may be yellow at first. This only takes a second or two.


Erase Flash

Second, erase the entire flash memory of the device. Be sure the device is attached to the STLINK programmer and in DFU mode before running this command. The command is the same for Photon and P1.

st-flash erase

The RGB LED should be unresponsive after erasure as no code is running.


Write Bootloader

Third, write the bootloader. After every st-flash write command, make sure you see the "jolly good" response from the command line. If you don't, perform the write again.

Example "jolly good" response:

2015-09-29T18:07:22 INFO src/stlink-common.c: Starting verification of write complete
2015-09-29T18:07:22 INFO src/stlink-common.c: Flash written and verified! jolly good!

Photon:

st-flash write bootloader-v0.4.5-photon.bin 0x08000000

P1:

st-flash write bootloader-v0.4.5-p1.bin 0x08000000

After flashing the bootloader, the RGB LED should flash yellow, indicating DFU mode.


Write System Modules

Fourth, flash the system modules. Before running each command make sure the device is in DFU mode, and after each command ensure your receive a "jolly good" response.

Photon:

st-flash write system-part1-v0.4.5-photon.bin 0x08020000

st-flash write system-part2-v0.4.5-photon.bin 0x08060000

P1:

st-flash write system-part1-v0.4.5-p1.bin 0x08020000

st-flash write system-part2-v0.4.5-p1.bin 0x08060000

After both modules are written, you should see the RGB LED go white for several seconds. During this period the device is generating an RSA key and a random SSID suffix.


Write Tinker

Fifth, write the tinker application to two places, the application firmware location and the factory reset location. Before running each command make sure the device is in DFU mode, and after each command ensure your receive a "jolly good" response.

Photon:

st-flash write tinker-v0.4.5-photon.bin 0x080a0000

st-flash write tinker-v0.4.5-photon.bin 0x080e0000

P1:

st-flash write tinker-v0.4.5-p1.bin 0x080a0000

st-flash write tinker-v0.4.5-p1.bin 0x080e0000

Save Flash Dumps

Sixth, read the entire contents of flash off of two devices and save to disk. Be sure each device is in DFU mode before running each command. These commands are the same for Photon and P1.

st-flash read device-a.bin 0x08000000

st-flash read device-b.bin 0x08000000

In my case, with Photons, both files were 922424 bytes.


Convert Binaries to Hex

Seventh, convert the binary dumps to xxd format so that we can compare them with diff.

xxd device-a.bin > device-a.xxd

xxd device-b.bin > device-b.xxd

See What's Different

Eighth, save a difference file to compare the flash contents of the two devices.

diff device-a.xxd device-b.xxd > a-b.diff

The file a-b.diff should be exactly 6976 bytes long, where the only differences are at the following locations, in diff section header format:

  • 1482c1482
  • 1499,1537c1499,1537
  • 1576,1584c1576,1584
  • 1612c1612

If that is true, then the devices should behave identically firmware-wise. Any differences in behavior at this point are most likely due to hardware differences.


Doctor the Keys

Last, in order to connect to the Particle cloud, the devices will need the server's public key, and their newly generated private keys will need to be reprovisioned. Before each of the following commands, be sure the devices are in DFU mode.

Photon:

dfu-util -d 2b04:d006 -a 1 -s 2082 -D cloud_public.der

P1:

dfu-util -d 2b04:d008 -a 1 -s 2082 -D cloud_public.der

Then run particle keys doctor with your device's ID, which you can obtain over serial when the device is in setup mode.

This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment