OTA on Atmega1284p - new firmware wont boot...

Started by bolteon, June 03, 2018, 07:53:40 PM

bolteon

Hello all,



So we got a bit screwed by our old firmware/software team when they quit and left us without any directions on the 1.2 years worth of firmware/software code they dumped on us. Long story short- managed to get everything except for OTA working and after digging deeper, found this forum since we're using the DualOptiboot bootloader.

The hex file gets put up to Firebase via a python script, and leaves a mailbox that the hardware unit checks for via cellular. Data stored up in cloud looks like such (message 1 of 60):

"{\"ps\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45], \"pd\": \":100000000C943A080C946B430C9496430C94C143A3\\n:100010000C94A9330C94A9330C94A9330C94A933F0\\n:100020000C948A1C0C9464080C9464080C94640866\\n:100030000C9464080C9464080C9464080C94640890\\n:100040000C9464080C9464080C94ED430C946408BC\\n:100050000C9423470C9459470C9464080C9464083E\\n:100060000C9464080C9464080C94BC300C946408E0\\n:100070000C94BA470C94F0470C9464080C946408F0\\n:100080000C9464080C9464080C94640828452B456F\\n:100090001E452245424542452F45334539453D459C\\n:1000A000036EDB363D9A9999993DABAAAA2A3E0088\\n:1000B0000000803F084AD73B3BCE016E84BCBFFDA9\\n:1000C000C12F3D6C74319ABD56833DDA3D00C77F28\\n:1000D00011BED9E4BB4C3E916BAAAABE00000080C1\\n:1000E0003F072C7AA5BA6CC590DA3B9365FC8BBCB4\\n:1000F00053F810FD3C5692834DBD879D3AB63DCBDB\\n:10010000C9BF5BBE73DA0FC93F05A84CCDB2D44E50\\n:10011000B93836A9020C50B9918688083CA6AAAA1B\\n:100120002ABE000000803F00093C2D2D2D20000933\\n:100130002D2D2D3E2000093C2D2D2D2000092D2D8B\\n:100140002D3E2000093C2D2D2D2000092D2D2D3E6A\\n:100150002000093C2D2D2D200041542B43485454A0\\n:1001600050535354415445000920202020204F6E05\\n:100170006C696E6521000920202020204F66666C86\\n:10018000696E650041542B43434C4B3F002B30308C\\n:1001900022002B3030220041542B43434C4B203D56\\n:1001A00020220041542B43434C4B203D2022004150\\n:1001B000542B43434C4B3F0041542B434854505520\\n:1001C00050444154453F0041542B434854505550EE\\n:1001D00044415445004F4B0041542B434854505325\\n:1001E0004552563F004F4B0041542B434854505307\\n:1001F0004552563D22414444222C227777772E6780\\n:100200006F6F676C652E636F6D222C38302C310058\\n:100210004F4B0041542B43485450534552563D22B6\\n:10022000414444222C226E6F7274682D616D657298\\n:100230006963612E706F6F6C2E6E74702E6F7267B3\\n:10024000222C38302C31004F4B0041542B43485462\\n:1002500050534552563D22414444222C2275732E60\\n:10026000706F6F6C2E6E74702E6F7267222C383028\\n:100270002C31004F4B0041542B43434C4B203D202D\\n:100280002238302F31312F31312C31313A31313A5E\\n:1002900031312B303022004F4B290041542B434346\\n:1002A0004C4B3F00202E2E2E2000092D2D2D3E20C0\\n:1002B00041542B434854545053524543563D0041FA\\n:1002C000542B434854545053524543563D00726595\\n:1002D00063656976655F6C656E3A200041542B4317\\n\"}"



And that matches the first lines of the hex file correctly:

:100000000C943A080C946B430C9496430C94C143A3
:100010000C94A9330C94A9330C94A9330C94A933F0
:100020000C948A1C0C9464080C9464080C94640866
:100030000C9464080C9464080C9464080C94640890
:100040000C9464080C9464080C94ED430C946408BC
:100050000C9423470C9459470C9464080C9464083E
:100060000C9464080C9464080C94BC300C946408E0
:100070000C94BA470C94F0470C9464080C946408F0
:100080000C9464080C9464080C94640828452B456F
:100090001E452245424542452F45334539453D459C
:1000A000036EDB363D9A9999993DABAAAA2A3E0088
:1000B0000000803F084AD73B3BCE016E84BCBFFDA9
:1000C000C12F3D6C74319ABD56833DDA3D00C77F28
:1000D00011BED9E4BB4C3E916BAAAABE00000080C1
:1000E0003F072C7AA5BA6CC590DA3B9365FC8BBCB4
:1000F00053F810FD3C5692834DBD879D3AB63DCBDB
:10010000C9BF5BBE73DA0FC93F05A84CCDB2D44E50
:10011000B93836A9020C50B9918688083CA6AAAA1B
:100120002ABE000000803F00093C2D2D2D20000933
:100130002D2D2D3E2000093C2D2D2D2000092D2D8B
:100140002D3E2000093C2D2D2D2000092D2D2D3E6A
:100150002000093C2D2D2D200041542B43485454A0
:1001600050535354415445000920202020204F6E05
:100170006C696E6521000920202020204F66666C86
:10018000696E650041542B43434C4B3F002B30308C
:1001900022002B3030220041542B43434C4B203D56
:1001A00020220041542B43434C4B203D2022004150
:1001B000542B43434C4B3F0041542B434854505520
:1001C00050444154453F0041542B434854505550EE
:1001D00044415445004F4B0041542B434854505325
:1001E0004552563F004F4B0041542B434854505307
:1001F0004552563D22414444222C227777772E6780
:100200006F6F676C652E636F6D222C38302C310058
:100210004F4B0041542B43485450534552563D22B6
:10022000414444222C226E6F7274682D616D657298
:100230006963612E706F6F6C2E6E74702E6F7267B3
:10024000222C38302C31004F4B0041542B43485462
:1002500050534552563D22414444222C2275732E60
:10026000706F6F6C2E6E74702E6F7267222C383028
:100270002C31004F4B0041542B43434C4B203D202D
:100280002238302F31312F31312C31313A31313A5E
:1002900031312B303022004F4B290041542B434346
:1002A0004C4B3F00202E2E2E2000092D2D2D3E20C0
:1002B00041542B434854545053524543563D0041FA
:1002C000542B434854545053524543563D00726595
:1002D00063656976655F6C656E3A200041542B4317


...this all seems fine, until the Arduino sketch starts writing to the external flash:

+CHTTPSRECV: 0
	<--- {"c":0,"d":"p","p":"{\"ps\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45], \"pd\": \":100000000C943A080C946B430C9496430C94C143A3\\n:100010000C94A9330C94A9330C94A9330C94A933F0\\n:100020000C948A1C0C9464080C9464080C94640866\\n:100030000C9464080C9464080C9464080C94640890\\n:100040000C9464080C9464080C94ED430C946408BC\\n:100050000C9423470C9459470C9464080C9464083E\\n:100060000C9464080C9464080C94BC300C946408E0\\n:100070000C94BA470C94F0470C9464080C946408F0\\n:100080000C9464080C9464080C94640828452B456F\\n:100090001E452245424542452F45334539453D459C\\n:1000A000036EDB363D9A9999993DABAAAA2A3E0088\\n:1000B0000000803F084AD73B3BCE016E84BCBFFDA9\\n:1000C000C12F3D6C74319ABD56833DDA3D00C77F28\\n:1000D00011BED9E4BB4C3E916BAAAABE00000080C1\\n:1000E0003F072C7AA5BA6CC590DA3B9365FC8BBCB4\\n:1000F00053F810FD3C5692834DBD879D3AB63DCBDB\\n:10010000C9BF5BBE73DA0FC93F05A84CCDB2D44E50\\n:10011000B93836A9020C50B9918688083CA6AAAA1B\\n:100120002ABE000000803F00093C2D2D2D20000933\\n:100130002D2D2D3E2000093C2D2D2D2000092D2D8B\\n:100140002D3E2000093C2D2D2D2000092D2D2D3E6A\\n:100150002000093C2D2D2D200041542B43485454A0\\n:1001600050535354415445000920202020204F6E05\\n:100170006C696E6521000920202020204F66666C86\\n:10018000696E650041542B43434C4B3F002B30308C\\n:1001900022002B3030220041542B43434C4B203D56\\n:1001A00020220041542B43434C4B203D2022004150\\n:1001B000542B43434C4B3F0041542B434854505520\\n:1001C00050444154453F0041542B434854505550EE\\n:1001D00044415445004F4B0041542B434854505325\\n:1001E0004552563F004F4B0041542B434854505307\\n:1001F0004552563D22414444222C227777772E6780\\n:100200006F6F676C652E636F6D222C38302C310058\\n:100210004F4B0041542B43485450534552563D22B6\\n:10022000414444222C226E6F7274682D616D657298\\n:100230006963612E706F6F6C2E6E74702E6F7267B3\\n:10024000222C38302C31004F4B0041542B43485462\\n:1002500050534552563D22414444222C2275732E60\\n:10026000706F6F6C2E6E74702E6F7267222C383028\\n:100270002C31004F4B0041542B43434C4B203D202D\\n:100280002238302F31312F31312C31313A31313A5E\\n:1002900031312B303022004F4B290041542B434346\\n:1002A0004C4B3F00202E2E2E2000092D2D2D3E20C0\\n:1002B00041542B434854545053524543563D0041FA\\n:1002C000542B434854545053524543563D00726595\\n:1002D00063656976655F6C656E3A200041542B4317\\n\"}","s":1,"t":"q"}
Message: c
type: q
sequence: 1
destination: p
crc: 0
payload: {"ps": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45], "pd": ":100000000C943A080C946B430C9496430C94C143A3\n:100010000C94A9330C94A9330C94A9330C94A933F0\n:100020000C948A1C0C9464080C9464080C94640866\n:100030000C9464080C9464080C9464080C94640890\n:100040000C9464080C9464080C94ED430C946408BC\n:100050000C9423470C9459470C9464080C9464083E\n:100060000C9464080C9464080C94BC300C946408E0\n:100070000C94BA470C94F0470C9464080C946408F0\n:100080000C9464080C9464080C94640828452B456F\n:100090001E452245424542452F45334539453D459C\n:1000A000036EDB363D9A9999993DABAAAA2A3E0088\n:1000B0000000803F084AD73B3BCE016E84BCBFFDA9\n:1000C000C12F3D6C74319ABD56833DDA3D00C77F28\n:1000D00011BED9E4BB4C3E916BAAAABE00000080C1\n:1000E0003F072C7AA5BA6CC590DA3B9365FC8BBCB4\n:1000F00053F810FD3C5692834DBD879D3AB63DCBDB\n:10010000C9BF5BBE73DA0FC93F05A84CCDB2D44E50\n:10011000B93836A9020C50B9918688083CA6AAAA1B\n:100120002ABE000000803F00093C2D2D2D20000933\n:100130002D2D2D3E2000093C2D2D2D2000092D2D8B\n:100140002D3E2000093C2D2D2D2000092D2D2D3E6A\n:100150002000093C2D2D2D200041542B43485454A0\n:1001600050535354415445000920202020204F6E05\n:100170006C696E6521000920202020204F66666C86\n:10018000696E650041542B43434C4B3F002B30308C\n:1001900022002B3030220041542B43434C4B203D56\n:1001A00020220041542B43434C4B203D2022004150\n:1001B000542B43434C4B3F0041542B434854505520\n:1001C00050444154453F0041542B434854505550EE\n:1001D00044415445004F4B0041542B434854505325\n:1001E0004552563F004F4B0041542B434854505307\n:1001F0004552563D22414444222C227777772E6780\n:100200006F6F676C652E636F6D222C38302C310058\n:100210004F4B0041542B43485450534552563D22B6\n:10022000414444222C226E6F7274682D616D657298\n:100230006963612E706F6F6C2E6E74702E6F7267B3\n:10024000222C38302C31004F4B0041542B43485462\n:1002500050534552563D22414444222C2275732E60\n:10026000706F6F6C2E6E74702E6F7267222C383028\n:100270002C31004F4B0041542B43434C4B203D202D\n:100280002238302F31312F31312C31313A31313A5E\n:1002900031312B303022004F4B290041542B434346\n:1002A0004C4B3F00202E2E2E2000092D2D2D3E20C0\n:1002B00041542B434854545053524543563D0041FA\n:1002C000542B434854545053524543563D00726595\n:1002D00063656976655F6C656E3A200041542B4317\n"}
Trying to reprogram now.
length: 2024
Starting Reprogramming
Erasing Flash chip ... Erased!
Hexline:      FLX:0:100000000C943A080C946B430C9496430C94C143A3
Got hex len: 16
Going to write: 0c 43a080c 46b430c 4 6430c 4#143
Writing:        C943A8C946B43C949643C94C143 -> 16 0
FLX:OK
Hexline:      FLX:1:100010000C94A9330C94A9330C94A9330C94A933F0
Got hex len: 16
Going to write: 0c 4!9330c 4!9330c 4!9330c 4!933
Writing:        C94A933C94A933C94A933C94A933 -> 32 16
FLX:OK
Hexline:      FLX:2:100020000C948A1C0C9464080C9464080C94640866
Got hex len: 16
Going to write: 0c 4a1c0c 464080c 464080c 46408
Writing:        C948A1CC94648C94648C94648 -> 48 32
FLX:OK
Hexline:      FLX:3:100030000C9464080C9464080C9464080C94640890
Got hex len: 16
Going to write: 0c 464080c 464080c 464080c 46408
Writing:        C94648C94648C94648C94648 -> 64 48
FLX:OK
Hexline:      FLX:4:100040000C9464080C9464080C94ED430C946408BC
Got hex len: 16
Going to write: 0c 464080c 464080c 4%d430c 46408
Writing:        C94648C94648C94ED43C94648 -> 80 64
FLX:OK
Hexline:      FLX:5:100050000C9423470C9459470C9464080C9464083E
Got hex len: 16
Going to write: 0c 423470c 459470c 464080c 46408
Writing:        C942347C945947C94648C94648 -> 96 80
FLX:OK
Hexline:      FLX:6:100060000C9464080C9464080C94BC300C946408E0
Got hex len: 16
Going to write: 0c 464080c 464080c 4"c300c 46408
Writing:        C94648C94648C94BC30C94648 -> 112 96
FLX:OK
Hexline:      FLX:7:100070000C94BA470C94F0470C9464080C946408F0
Got hex len: 16
Going to write: 0c 4"a470c 4&0470c 464080c 46408
Writing:        C94BA47C94F047C94648C94648 -> 128 112
FLX:OK
Hexline:      FLX:8:100080000C9464080C9464080C94640828452B456F
Got hex len: 16
Going to write: 0c 464080c 464080c 4640828452b45
Writing:        C94648C94648C9464828452B45 -> 144 128
FLX:OK
Hexline:      FLX:9:100090001E452245424542452F45334539453D459C
Got hex len: 16
Going to write: 1e452245424542452f45334539453d45
Writing:        1E452245424542452F45334539453D45 -> 160 144
FLX:OK
Hexline:      FLX:10:1000A000036EDB363D9A9999993DABAAAA2A3E0088
Got hex len: 16
Going to write: 036e$b363d a 9 9 93d!b!a!a2a3e00
Writing:        36EDB363D9A9999993DABAAAA2A3E0 -> 176 160
FLX:OK
Hexline:      FLX:11:1000B0000000803F084AD73B3BCE016E84BCBFFDA9
Got hex len: 16
Going to write: 000003f084a$73b3b#e016e4"c"f&d
Writing:        00803F84AD73B3BCE16E84BCBFFD -> 192 176
FLX:OK
Hexline:      FLX:12:1000C000C12F3D6C74319ABD56833DDA3D00C77F28
Got hex len: 16
Going to write: #12f3d6c7431 a"d5633d$a3d00#77f
Writing:        C12F3D6C74319ABD56833DDA3D0C77F -> 208 192
FLX:OK
Hexline:      FLX:13:1000D00011BED9E4BB4C3E916BAAAABE00000080C1
Got hex len: 16
Going to write: 11"e$9%4"b4c3e 16b!a!a"e0000000
Writing:        11BED9E4BB4C3E916BAAAABE00080 -> 224 208
FLX:OK
Hexline:      FLX:14:1000E0003F072C7AA5BA6CC590DA3B9365FC8BBCB4
Got hex len: 16
Going to write: 3f072c7a!5"a6c#5 0$a3b 365&cb"c
Writing:        3F72C7AA5BA6CC590DA3B9365FC8BBC -> 240 224
FLX:OK
Hexline:      FLX:15:1000F00053F810FD3C5692834DBD879D3AB63DCBDB
Got hex len: 16
Going to write: 53&810&d3c56 234d"d7 d3a"63d#b
Writing:        53F810FD3C5692834DBD879D3AB63DCB -> 256 240
FLX:OK
Hexline:      FLX:16:10010000C9BF5BBE73DA0FC93F05A84CCDB2D44E50
Got hex len: 16
Going to write: #9"f5b"e73$a0f#93f05!84c#d"2$44e
Writing:        C9BF5BBE73DAFC93F5A84CCDB2D44E -> 272 256
FLX:OK
Hexline:      FLX:17:10011000B93836A9020C50B9918688083CA6AAAA1B
Got hex len: 16
Going to write: "93836!9020c50"9 168083c!6!a!a
Writing:        B93836A92C50B991868883CA6AAAA -> 288 272
FLX:OK
Hexline:      FLX:18:100120002ABE000000803F00093C2D2D2D20000933
Got hex len: 16
Going to write: 2a"e00000003f00093c2d2d2d200009
Writing:        2ABE000803F093C2D2D2D2009 -> 304 288
FLX:OK
Hexline:      FLX:19:100130002D2D2D3E2000093C2D2D2D2000092D2D8B
Got hex len: 16
Going to write: 2d2d2d3e2000093c2d2d2d2000092d2d
Writing:        2D2D2D3E20093C2D2D2D20092D2D -> 320 304
FLX:OK
Hexline:      FLX:20:100140002D3E2000093C2D2D2D2000092D2D2D3E6A
Got hex len: 16
Going to write: 2d3e2000093c2d2d2d2000092d2d2d3e
Writing:        2D3E20093C2D2D2D20092D2D2D3E -> 336 320
FLX:OK
Hexline:      FLX:21:100150002000093C2D2D2D200041542B43485454A0
Got hex len: 16
Going to write: 2000093c2d2d2d200041542b43485454
Writing:        20093C2D2D2D20041542B43485454 -> 352 336
FLX:OK
Hexline:      FLX:22:1001600050535354415445000920202020204F6E05
Got hex len: 16
Going to write: 50535354415445000920202020204f6e
Writing:        505353544154450920202020204F6E -> 368 352
FLX:OK
Hexline:      FLX:23:100170006C696E6521000920202020204F66666C86
Got hex len: 16
Going to write: 6c696e6521000920202020204f66666c
Writing:        6C696E65210920202020204F66666C -> 384 368
FLX:OK
Hexline:      FLX:24:10018000696E650041542B43434C4B3F002B30308C
Got hex len: 16
Going to write: 696e650041542b43434c4b3f002b3030
Writing:        696E65041542B43434C4B3F02B3030 -> 400 384
FLX:OK
Hexline:      FLX:25:1001900022002B3030220041542B43434C4B203D56
Got hex len: 16
Going to write: 22002b3030220041542b43434c4b203d
Writing:        2202B303022041542B43434C4B203D -> 416 400
FLX:OK
Hexline:      FLX:26:1001A00020220041542B43434C4B203D2022004150
Got hex len: 16
Going to write: 20220041542b43434c4b203d20220041
Writing:        2022041542B43434C4B203D2022041 -> 432 416
FLX:OK
Hexline:      FLX:27:1001B000542B43434C4B3F0041542B434854505520
Got hex len: 16
Going to write: 542b43434c4b3f0041542b4348545055
Writing:        542B43434C4B3F041542B4348545055 -> 448 432
FLX:OK
Hexline:      FLX:28:1001C00050444154453F0041542B434854505550EE
Got hex len: 16
Going to write: 50444154453f0041542b434854505550
Writing:        50444154453F041542B434854505550 -> 464 448
FLX:OK
Hexline:      FLX:29:1001D00044415445004F4B0041542B434854505325
Got hex len: 16
Going to write: 44415445004f4b0041542b4348545053
Writing:        4441544504F4B041542B4348545053 -> 480 464
FLX:OK
Hexline:      FLX:30:1001E0004552563F004F4B0041542B434854505307
Got hex len: 16
Going to write: 4552563f004f4b0041542b4348545053
Writing:        4552563F04F4B041542B4348545053 -> 496 480
FLX:OK
Hexline:      FLX:31:1001F0004552563D22414444222C227777772E6780
Got hex len: 16
Going to write: 4552563d22414444222c227777772e67
Writing:        4552563D22414444222C227777772E67 -> 512 496
FLX:OK
Hexline:      FLX:32:100200006F6F676C652E636F6D222C38302C310058
Got hex len: 16
Going to write: 6f6f676c652e636f6d222c38302c3100
Writing:        6F6F676C652E636F6D222C38302C310 -> 528 512
FLX:OK
Hexline:      FLX:33:100210004F4B0041542B43485450534552563D22B6
Got hex len: 16
Going to write: 4f4b0041542b43485450534552563d22
Writing:        4F4B041542B43485450534552563D22 -> 544 528
FLX:OK
Hexline:      FLX:34:10022000414444222C226E6F7274682D616D657298
Got hex len: 16
Going to write: 414444222c226e6f7274682d616d6572
Writing:        414444222C226E6F7274682D616D6572 -> 560 544
FLX:OK
Hexline:      FLX:35:100230006963612E706F6F6C2E6E74702E6F7267B3
Got hex len: 16
Going to write: 6963612e706f6f6c2e6e74702e6f7267
Writing:        6963612E706F6F6C2E6E74702E6F7267 -> 576 560
FLX:OK
Hexline:      FLX:36:10024000222C38302C31004F4B0041542B43485462
Got hex len: 16
Going to write: 222c38302c31004f4b0041542b434854
Writing:        222C38302C3104F4B041542B434854 -> 592 576
FLX:OK
Hexline:      FLX:37:1002500050534552563D22414444222C2275732E60
Got hex len: 16
Going to write: 50534552563d22414444222c2275732e
Writing:        50534552563D22414444222C2275732E -> 608 592
FLX:OK
Hexline:      FLX:38:10026000706F6F6C2E6E74702E6F7267222C383028
Got hex len: 16
Going to write: 706f6f6c2e6e74702e6f7267222c3830
Writing:        706F6F6C2E6E74702E6F7267222C3830 -> 624 608
FLX:OK
Hexline:      FLX:39:100270002C31004F4B0041542B43434C4B203D202D
Got hex len: 16
Going to write: 2c31004f4b0041542b43434c4b203d20
Writing:        2C3104F4B041542B43434C4B203D20 -> 640 624
FLX:OK
Hexline:      FLX:40:100280002238302F31312F31312C31313A31313A5E
Got hex len: 16
Going to write: 2238302f31312f31312c31313a31313a
Writing:        2238302F31312F31312C31313A31313A -> 656 640
FLX:OK
Hexline:      FLX:41:1002900031312B303022004F4B290041542B434346
Got hex len: 16
Going to write: 31312b303022004f4b290041542b4343
Writing:        31312B30302204F4B29041542B4343 -> 672 656
FLX:OK
Hexline:      FLX:42:1002A0004C4B3F00202E2E2E2000092D2D2D3E20C0
Got hex len: 16
Going to write: 4c4b3f00202e2e2e2000092d2d2d3e20
Writing:        4C4B3F0202E2E2E20092D2D2D3E20 -> 688 672
FLX:OK
Hexline:      FLX:43:1002B00041542B434854545053524543563D0041FA
Got hex len: 16
Going to write: 41542b434854545053524543563d0041
Writing:        41542B434854545053524543563D041 -> 704 688
FLX:OK
Hexline:      FLX:44:1002C000542B434854545053524543563D00726595
Got hex len: 16
Going to write: 542b434854545053524543563d007265
Writing:        542B434854545053524543563D07265 -> 720 704
FLX:OK
Hexline:      FLX:45:1002D00063656976655F6C656E3A200041542B4317
Got hex len: 16
Going to write: 63656976655f6c656e3a200041542b43
Writing:        63656976655F6C656E3A20041542B43 -> 736 720
FLX:OK
Go to next command!



Having gone back and attempted to read the flash directly via a simple modification to Felix's sketch:

#include <SPIFlash.h>
#include <SPI.h>

#define SERIAL_BAUD      115200
char input = 0;
long lastPeriod = -1;

//////////////////////////////////////////
//flash(SPI_CS, MANUFACTURER_ID)
//SPI_CS          - CS pin attached to SPI flash chip (8 in case of Moteino)
//MANUFACTURER_ID - OPTIONAL, 0x1F44 for adesto(ex atmel) 4mbit flash
//                           0xEF30 for windbond 4mbit flash
//////////////////////////////////////////
SPIFlash flash(A1, 0xEF30);

void setup() {
  Serial.begin(SERIAL_BAUD);
  Serial.print("Start...");

  if (flash.initialize())
    Serial.println("Init OK!");
  else
    Serial.println("Init FAIL!");

  Serial.print("DeviceID: ");
  Serial.println(flash.readDeviceId(), HEX);

  Serial.println("Flash content:");
  int counter = 0;
  int bytecounter = 0;
  int bytecounter2 = 0;

  while (counter <= 745) {
    Serial.print(flash.readByte(counter++), HEX);
    Serial.print('.');
    bytecounter++;
    bytecounter2++;
    if (bytecounter2 == 10) {
      Serial.println("");
      bytecounter = 0;
    }
    if (bytecounter == 16) {
      Serial.println("");
      bytecounter = 0;
    }
  }
}



I seem to get some rather confusing results:

Start...Init OK!
DeviceID: EF30
Flash content:
FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.
C.94.3A.8.C.94.6B.43.C.94.96.43.C.94.C1.43.
C.94.A9.33.C.94.A9.33.C.94.A9.33.C.94.A9.33.
C.94.8A.1C.C.94.64.8.C.94.64.8.C.94.64.8.
C.94.64.8.C.94.64.8.C.94.64.8.C.94.64.8.
C.94.64.8.C.94.64.8.C.94.ED.43.C.94.64.8.
C.94.23.47.C.94.59.47.C.94.64.8.C.94.64.8.
C.94.64.8.C.94.64.8.C.94.BC.30.C.94.64.8.
C.94.BA.47.C.94.F0.47.C.94.64.8.C.94.64.8.
C.94.64.8.C.94.64.8.C.94.64.8.28.45.2B.45.
1E.45.22.45.42.45.42.45.2F.45.33.45.39.45.3D.45.
3.6E.DB.36.3D.9A.99.99.99.3D.AB.AA.AA.2A.3E.0.
0.0.80.3F.8.4A.D7.3B.3B.CE.1.6E.84.BC.BF.FD.
C1.2F.3D.6C.74.31.9A.BD.56.83.3D.DA.3D.0.C7.7F.
11.BE.D9.E4.BB.4C.3E.91.6B.AA.AA.BE.0.0.0.80.
3F.7.2C.7A.A5.BA.6C.C5.90.DA.3B.93.65.FC.8B.BC.
53.F8.10.FD.3C.56.92.83.4D.BD.87.9D.3A.B6.3D.CB.
C9.BF.5B.BE.73.DA.F.C9.3F.5.A8.4C.CD.B2.D4.4E.
B9.38.36.A9.2.C.50.B9.91.86.88.8.3C.A6.AA.AA.
2A.BE.0.0.0.80.3F.0.9.3C.2D.2D.2D.20.0.9.
2D.2D.2D.3E.20.0.9.3C.2D.2D.2D.20.0.9.2D.2D.
2D.3E.20.0.9.3C.2D.2D.2D.20.0.9.2D.2D.2D.3E.
20.0.9.3C.2D.2D.2D.20.0.41.54.2B.43.48.54.54.
50.53.53.54.41.54.45.0.9.20.20.20.20.20.4F.6E.
6C.69.6E.65.21.0.9.20.20.20.20.20.4F.66.66.6C.
69.6E.65.0.41.54.2B.43.43.4C.4B.3F.0.2B.30.30.
22.0.2B.30.30.22.0.41.54.2B.43.43.4C.4B.20.3D.
20.22.0.41.54.2B.43.43.4C.4B.20.3D.20.22.0.41.
54.2B.43.43.4C.4B.3F.0.41.54.2B.43.48.54.50.55.
50.44.41.54.45.3F.0.41.54.2B.43.48.54.50.55.50.
44.41.54.45.0.4F.4B.0.41.54.2B.43.48.54.50.53.
45.52.56.3F.0.4F.4B.0.41.54.2B.43.48.54.50.53.
45.52.56.3D.22.41.44.44.22.2C.22.77.77.77.2E.67.
6F.6F.67.6C.65.2E.63.6F.6D.22.2C.38.30.2C.31.0.
4F.4B.0.41.54.2B.43.48.54.50.53.45.52.56.3D.22.
41.44.44.22.2C.22.6E.6F.72.74.68.2D.61.6D.65.72.
69.63.61.2E.70.6F.6F.6C.2E.6E.74.70.2E.6F.72.67.
22.2C.38.30.2C.31.0.4F.4B.0.41.54.2B.43.48.54.
50.53.45.52.56.3D.22.41.44.44.22.2C.22.75.73.2E.
70.6F.6F.6C.2E.6E.74.70.2E.6F.72.67.22.2C.38.30.
2C.31.0.4F.4B.0.41.54.2B.43.43.4C.4B.20.3D.20.
22.38.30.2F.31.31.2F.31.31.2C.31.31.3A.31.31.3A.
31.31.2B.30.30.22.0.4F.4B.29.0.41.54.2B.43.43.
4C.4B.3F.0.20.2E.2E.2E.20.0.9.2D.2D.2D.3E.20.
41.54.2B.43.48.54.54.50.53.52.45.43.56.3D.0.41.
54.2B.43.48.54.54.50.53.52.45.43.56.3D.0.72.65.
63.65.69.76.65.5F.6C.65.6E.3A.20.0.41.54.2B.43.



Maybe my lack of understanding is showing- but I was expecting the FLX tags to be there and what not... anyway, once the sketch gets to the bottom of the messages, it restarts the unit by exceeding the watchdog timeout of 8 seconds and the new firmware does not take over.

Attached is the file that's responsible for the programming part, of the larger overall sketch.

This is also my MoteinoMEGA section of boards.txt:

MoteinoMEGA.name=MoteinoMEGA
MoteinoMEGA.upload.tool=arduino:avrdude
MoteinoMEGA.upload.maximum_size=130048
MoteinoMEGA.upload.maximum_data_size=16384 
MoteinoMEGA.upload.speed=115200
MoteinoMEGA.upload.protocol=arduino 
# This line added 
MoteinoMEGA.bootloader.tool=arduino:avrdude
MoteinoMEGA.bootloader.low_fuses=0xDE
MoteinoMEGA.bootloader.high_fuses=0xD6
MoteinoMEGA.bootloader.extended_fuses=0xFD
#MoteinoMEGA.bootloader.extended_fuses=0x05  Didn't need this! 
MoteinoMEGA.bootloader.unlock_bits=0x3F
#MoteinoMEGA.bootloader.lock_bits=0xCF   Programmer expects 0x0F
MoteinoMEGA.bootloader.lock_bits=0x0F
MoteinoMEGA.bootloader.file=DualOptiboot_V5.0_atmega1284p_BlinkD15.hex
MoteinoMEGA.build.mcu=atmega1284p
MoteinoMEGA.build.f_cpu=16000000L
#MoteinoMEGA.build.f_cpu=10000000L
MoteinoMEGA.build.core=arduino:arduino
MoteinoMEGA.build.variant=MoteinoMEGA
MoteinoMEGA.build.board=AVR_MOTEINOMEGA




...I'm so close to being able to hand this off to our new firmware guy, any and all help would be very much so appreciated.

Felix

Exactly how you do the transfer is not clear to me, an implementation is given in the RFM69 library.
The signature is written after the transfer is complete (after all bytes are received). Once the FLASH-MEM contains the correct signature with byte count and the HEX content after it, upon a reset the bootloader will rewrite the internal flash with that new HEX image, then remove the first page from the FLASH and restart itself to run the new sketch.

The protocol code has all these details in RFM69_OTA.cpp.

bolteon

#2
The transfer is being done via the FONA network running on a SIMCOM 5320 and Hologram as cellular provider.

The Firebase account stores messages of the paged hex file, and the program.ino is the client with which those messages get pulled down and written to flash.

Thats where I think things are going wrong, after the correct payload is pulled down, during the writting part...

...but if the signature is written to *after* the download- whats missing from that sketch? Its that part I'm more lost with than anything, since seeing the payloads come in from Firebase look fine, just need to write them into flash properly.

Is there an example somewhere of what should the flash mem dump look like?


bolteon

Sorry, I meant a dump of an external flash chip that is loaded with the paged hex file. I'm guessing it doesn't look like my mem dump.

All I'm seeing in that link is a screen grab of serial output between the programmer and receiver.

Felix

The library includes the WDT reset and it works on all AVR Moteinos. There is a separate routine for MoteinoM0 and does a similar thing.
Since that is a tested piece of code and it works, I don't really have any other advice. Since I don't have your hardware in my hand to try it, I can't really guess why it's not working.
BUT the given library does work and it resets the boards so the bootloader can pick up the new firmware from external flash.

The FLASH memory dump sample sketch can help in determining if your hex image looks ok.
44038 = xAC06 which is correct. The bootloader should reflash your MoteinoMEGA upon a reset.
Make sure you have Dualoptiboot on your chip. That's it.

bolteon

#6
Is there a way to confirm it (the dualoptiboot) is getting written properly outside of burning the bootloader through the Arduino IDE or a AVRDude command line?

Felix

Are you running hardware sold by LowPowerLab?
If so, is the bootloader the original?

bolteon

Quote from: Felix on June 05, 2018, 02:17:03 PM
Are you running hardware sold by LowPowerLab?
If so, is the bootloader the original?

Adding a bit more- just want to clarify if our fuse settings will make a difference here. I followed through this thread since they were having similar issues:

https://lowpowerlab.com/forum/moteino/wireless-programming-no-reboot/

...per your recommendations, they adjusted their fuses and stuff seemed to change behaviour. Below is a comparison of ours (left) and the recommended settings (right):




My question is, do we have to have "EESAVE" un-programmed (and turned off) in order for the bootloader to do it's thing?

Felix