Skip to content

BLDC_Test_Bench and BLDC_Host_Bootloader: static analysis notes

Method: Ghidra (mcghidra, port 8193, read only) for BLDC_Test_Bench, llvm-objdump for BLDC_Host_Bootloader, plus a read-only look at /lib/firmware/BLDC.cyacd in the extracted rootfs. Nothing executed. Ghidra did not auto-create a function for main (0x116c0 to 0x128d4); that region was read with llvm-objdump. All Ghidra decompiles are PIC code, so DAT_xxxx + const expressions are pc-relative literal-pool address computations; I resolved them by reading the pool words.

Labels: EVIDENCE = address plus decompile/disassembly/string. INFERENCE = my reading, not directly shown.

Function naming (Ghidra shows FUN_xxxx; names below come from the __func__/assert strings that each function references via xrefs):

Address Name Source of name
0x1b3dc I2C_open (NativeI2C.c) string “I2C_open” xref
0x1b3f0 I2C_read (plain read(2)) asserts line 0xc9/0x78, calls read()
0x1b434 I2C_write (plain write(2)) calls write()
0x1b478 BLDC_comm_write_read wrapper (asserts both sizes <= 255) xref to “BLDC_comm_write_read”
0x1c49c I2C_write_read (ioctl I2C_RDWR) xrefs to “I2C_write_read”
0x1b514 write then usleep(ms*1000) decompile
0x17c60 MTB_BLDC_stop_motors xref 0x1f458
0x17d0c MTB_BLDC_get_assert xref 0x1f470
0x17e04 MTB_BLDC_play_sound xref 0x1f484
0x17eb8 MTB_BLDC_set_i2c_timeout xref 0x1f498
0x13e9c MTB_BLDC_clear_EEPROM xref 0x1f4b4
0x1802c MTB_BLDC_clear_error xref 0x1f4cc
0x180dc MTB_BLDC_reverse_spin_direction xref 0x1f4e4
0x18178 MTB_BLDC_get_info xref 0x1f508
0x182b4 MTB_BLDC_set_ref_speed xref 0x1f51c
0x1891c MTB_BLDC_simple_get_obs_speed (cmd 0x20) xref 0x1f534, “CRC error” string at 0x18ad4
0x18880 MTB_BLDC_gpio_control xref 0x1f7f0
0x194ac / 0x1955c MTB_BLDC_start_motors (no arg / with arg) xref 0x1fce4
0x18ccc / 0x18e40 settings read / write cmd 0xC0 (see below)
0x1346c observed-data log dump cmd 0xE0 loop
0x19610 / 0x19704 / 0x197ac MTB_BLDC_check_ramping / check_nominal / check_braking state tests
0x190dc, 0x19050, 0x1907c, 0x190ac error printer, errno name, status name, assert-file name tables below

EVIDENCE, I2C_open at 0x1b3dc (decompiled):

iVar2 = open(pcVar1, 2); // pcVar1 = "/dev/i2c-1" (string 0x21ed8), O_RDWR
...
iVar2 = ioctl(iVar2, 0x706, 8); // 0x706 = I2C_SLAVE_FORCE, arg = 8

0x706 is I2C_SLAVE_FORCE and 0x707 is I2C_RDWR in linux/i2c-dev.h (my recollection of the header, not from the binary). The only two movw #0x706 / #0x707 immediates in the whole binary are at 0x1c1b0 (open) and 0x1c518 (write_read). No I2C_TIMEOUT (0x702) or I2C_RETRIES (0x701) ioctl exists anywhere, so no kernel-level timeout is configured by this tool.

Slave address: 7-bit 0x08 (8-bit write byte 0x10, read byte 0x11). Confirmed twice: ioctl(fd, 0x706, 8) and FUN_0001c49c(8, ...) called from the wrapper at 0x1b478 (FUN_0001c49c(8,param_1,param_2 & 0xff,param_3,param_4 & 0xff)). The bootloader uses the same 8 (disassembly at 0x13690 mov r0,#8, ioctl 0x706 at 0x137bc).

Two transfer styles exist.

(a) Plain write(fd, buf, n) for commands with no response, FUN_0001b434 at 0x1b434 (returns 1 only if write returned n; asserts n <= 255, n != 0).

(b) Combined write+read in one transaction (repeated start) via I2C_RDWR, FUN_0001c49c, EVIDENCE:

local_2c = param_3; // tx len
local_2e = 0; // msg[0].flags = 0 (write)
local_30 = param_1; // msg[0].addr = 8
local_28 = param_2; // msg[0].buf
local_24 = param_1; // msg[1].addr = 8
local_22 = 1; // msg[1].flags = 1 (I2C_M_RD)
local_20 = param_5; // msg[1].len
local_1c = param_4; // msg[1].buf
local_38 = &local_30; local_34 = 2; // struct i2c_rdwr_ioctl_data { msgs, nmsgs = 2 }
iVar1 = ioctl(fd, 0x707, &local_38);
if (iVar1 == local_34) { // both messages done
iVar1 = 0; pbVar2 = param_4 + uVar4;
do { pbVar2--; iVar1 += *pbVar2; } while (pbVar2 != param_4);
if (iVar1 == 0 || iVar1 == uVar4 * 0xff) { // all-zero or all-0xFF reply
fwrite("I2C_write_read() Frame Error. BLDC returned an empty message\n");
return 0;
}
return 1;
}
fwrite("I2C_write_read() ioctl Error. Unable to send data\n"); return 0;

So the only “link validation” in the transport layer is: sum of reply bytes == 0 or == 0xFF*len is rejected as “empty message” (INFERENCE: bus-idle or no-slave reads). Not a checksum.

Plain read: FUN_0001b3f0 is read(fd, buf, n) == n, blocking, no timeout of its own.

Delays: FUN_0001b514 = write then usleep(ms*1000). Used with 1 ms after a settings write (0xC0 ‘W’), 10 ms after a log page request (0xE0). Start motors waits MTB.field_0x4c * 1000 us (default 5000, stored at 0x11814) after the 0x40 command.

Every command is one leading byte, no length byte, no address byte, no trailing terminator. Multi-byte integers are big-endian (high byte first) in every case seen. The call sites of the two write primitives are exhaustive (bl list: 17c88, 17d48, 17e30, 17ef4, 17fa4, 18054, 18104, 181a8, 18438, 18820, 18968, 18d24, 18d48, 18ea4, 18eec, 194ec, 195a0, 13528), so the table below is the complete command set used by this tool.

Cmd Name Tx Rx Method Evidence
0x02 set_ref_speed [02] n*{hi,lo} [00] [xor8], len 2n+3 none write 0x182b4
0x06 reverse_spin_direction [06] none write 0x180dc local_11[0]=6
0x20 get_obs_speed [20] 2n+7 bytes (layout in section 4) write_read 0x1891c local_19[0]=0x20, read len 2*n+7
0x2B get_assert [2B] 4 bytes write_read 0x17d0c
0x40 start_motors [40] or [40][dir] none write 0x194ac, 0x1955c
0x4D gpio_control [4D][bits] none write 0x18880
0x60 stop_motors [60] none write 0x17c60
0x80 clear_error [80] none write 0x1802c
0x82 play_sound [82][n] none write 0x17e04
0x8D set_i2c_timeout [8D][hi][lo] (ms) none write 0x17eb8
0xA0 get_info [A0] 14 bytes write_read 0x18178 mov r3,#0xe
0xC0 settings access [C0]['R'=0x52][id][00][00] or [C0]['W'=0x57][id][hi][lo] 4 bytes R: write_read; W: write+1ms+read 0x18ccc, 0x18e40
0xE0 log page [E0][page] 32 bytes write, 10 ms, plain read 0x1346c
0xFA clear_EEPROM [FA] none write 0x13e9c

Details per command, each EVIDENCE unless marked.

0x02 set_ref_speed (0x182b4, disassembly checked, buffer base 0x33b80). buf[0]=2 (strb r1,[r3,#4] with r1=2 at 0x182f0). For each motor k, buf[1+2k]=value>>8, buf[2+2k]=value&0xFF (strb at [r6+5]/[r6+6]). buf[2n+1]=0 (strb r3,[r6,#5] with r3=0). buf[2n+2] = XOR of buf[0..2n+1] (see section 3). Length passed to write = 2n+3, asserted < 32. Value is a u16 per motor; in open-loop mode the tool rejects values above 255 (string 0x1d22c: “Incompatible reference speed with BLDC in open loop regulation mode. Max value: 255”), so open loop = PWM 0..255, closed loop = speed (RPM per the “Minimal speed … RPM” settings entries; INFERENCE for the unit of the raw word).

0x20 get_obs_speed and 0x40/0x4D/0x60/… see below. Motor count n comes from get_info byte 3 (range 1..8 enforced at 0x11920: sub r3,r1,#1; cmp r3,#7; bhi).

0x2B get_assert (0x17d0c, only called when errno == 13). Rx 4 bytes b0..b3: b0 must equal 0x0D (if (local_14 == '\r')), b1 = source file id, b2:b3 = line number big-endian (local_11 + local_12*0x100). File id table (0x190ac, pointers at 0x3322c): 0 “*** Wrong file **”, 1 BLDC_main.c, 2 BLDC_drivers.c, 3 BLDC_comm.c, 4 BLDC_maths.c, 5 BLDC_routines.c. These are PSoC firmware source names; the BLDC_.c strings are the labels the PSoC reports in assertion failures, they are not host code.

0x40 start_motors: [40] when no direction given (*(ushort*)(ctx+4) == 0xffff), else [40][ctx_u16 & 0xFF]. The tool prints “Start motors with direction: %u” and the option text says the arg is an 8-bit boolean field, one bit per motor, valid 0..31 (string 0x1d5d4). Before sending, 0x192bc reads state (via 0x20) and refuses unless status is idle (assert E_BLDC_STATUS_IDLE == BLDC->bldcstatus, string 0x1fcbc).

0x4D gpio_control (0x18880): bits = (p1 ? 2 : 0) + (p0 ? 1 : 0) + (p2 ? 4 : 0) + (nbMotors==4 && p3 ? 0x10 : 0). User text: “Toggle GPIO. Red LED: %u Green LED: %u GPIO: %u”. Which parameter maps to which named bit is not resolved (UNKNOWN); bit 3 (0x08) is never set by this tool.

0x82 play_sound: one byte sound number (“Play sound #%d”). 0x8D set_i2c_timeout: buf[1]=param>>8, buf[2]=param&0xFF, units ms (“I2C Timeout %d ms”); this is the PSoC-side watchdog, matching settings entry “Security Timeout I2C lost” (that entry’s unit is “cycles x 1 ms”).

0xA0 get_info (0x18178, offsets from disassembly 0x181fc to 0x1826c). Rx 14 bytes r[0..13]:

Byte Meaning
r0 version major (must be >= 1; main checks r-1 <= 0xfd)
r1 version minor
r2 version letter (ASCII). main accepts ‘R’(0x52), ‘A’(0x41), ‘D’/‘T’(0x44/0x54, via &0xEF == 0x44)
r3 number of motors, 1..8
r4,r5 u16 BE: number of flights
r6,r7 u16 BE: previous flight time in seconds
r8..r11 u32 BE: total flight time in seconds
r12 last error code (index into the errno table, section 4)
r13 not read by the host

Names for r4..r12 come from the print routine at 0x140d8 (“Number of flights”, “Previous flight time: %6u seconds”, “Total flight time”, “Last error: ‘%s’”; the last uses FUN_00019050, the errno name table). The version print is '%u.%u.%c.%u' with r0,r1,r2,r3. The mapping of r3 to motor count is by the 0x1191c range check and the strb r1,[r5,#6] copy into the motor-count field; the 4th version component being the same byte is consistent with the format string, and the bootloader prints “new BLDC firmware %u:%u:%c:%u” and “not tagged ‘Released for 4 motors’” (INFERENCE that the last field is the motor count).

0xC0 settings (0x18ccc read, 0x18e40 write). Read: tx C0 52 id 00 00 (5 bytes, write_read), rx 4 bytes b0..b3. Success iff b0 != 0xFF and b1 != 0xFF; value = b2<<8 | b3 (u16 BE). Write: tx C0 57 id hi lo, 1 ms later plain read of 4 bytes, success iff b0 != 0xFF, b1 != 0xFF and (b2<<8|b3) == value written (read-back echo). On failure of the first transfer the read path issues a 0x20 read and tests rx[2n+1] == 1, returning 0x2A “not allowed when motors are spinning” style failure (the string at 0x1f960 says “accessing to settings is forbidden when motors are spinning”); I could not resolve why byte 2n+1 is tested, UNKNOWN. The parameter ids are most likely the index into the settings name table at 0x33058 (stride 8, name pointer plus unit pointer); INFERENCE, I did not confirm that the id sent equals the table index. Table (45 entries, from the .data pointers):

Index Name Unit
0 Motor rated speed RPM
1 LIPO number of cells (none)
2 Min LIPO cell voltage deciVolt
3 Max LIPO cell voltage deciVolt
4 Vbat resistor1 bridge Kilo ohm (scaled x10)
5 Vbat resistor2 bridge Kilo ohm (scaled x10)
6 Rotor number of pole pairs (none)
7 Gear reductor motor (none)
8 Gear reductor propeller (none)
9 PWM frequency 2^x-1
10 PWM complementary boolean
11 Propeller [1..4] push/pull boolean field
12 Motor timing degrees
13 Rotor alignement volt demand deciVolt
14 Rotor alignement duration ms
15 Ramp start voltage deciVolt
16 Ramp end voltage deciVolt
17 Ramp start propeller speed RPM
18 Ramp end propeller speed RPM
19 Ramp duration ms
20 Ramp speed locking duration ms
21 Speed regulator enable boolean
22 Speed PID regulator KP (none)
23 Speed PID regulator KI (none)
24 Speed PID regulator KD (none)
25 Speed PID integral saturation x1000
26 Speed PID regulator scaler (none)
27 Feedforward A1V (none)
28 Feedforward A2V (none)
29 Minimal speed RPM
30 Max propeller acceleration RPM/ms
31 Threshold satured PWM percent
32 Threshold security cutout RPM
33 Security min propeller speed RPM
34 Security max additional prop speed RPM
35 Security Timeout I2C lost cycles x 1 ms
36 ADC max voltage centiVolt
37 Max overspeed errors cycles x 1 ms
38 Power saturation delay cycles x 1 ms
39 Max low Vbat errors cycles x 1 ms
40 Cypress Die min temperature abs(degC)
41 Cypress Die max temperature abs(degC)
42 RC filter for BEMF: Resistor 1 Kilo ohm (scaled x10)
43 RC filter for BEMF: Resistor 2 Kilo ohm (scaled x10)
44 RC filter for BEMF: Capacitor Nano Farad (scaled x10)

(The PSoC default values, the 120 C style limits, ramp numbers etc. are NOT in these binaries, only names and units.)

0xE0 log page (0x1346c): for page = 0..0x4A (75 pages) send E0 page, usleep(10 ms), read 32 bytes. Record layout is in section 4.

Section titled “3. Integrity check on the I2C link: there is no CRC”

EVIDENCE: the entire BLDC_Test_Bench .text contains exactly two eor instructions (grep eor of the full llvm-objdump: lines at 0x18424 and 0x189f0). No constant 0x1021, 0x8408, 0xA001, 0x8005, 0xEDB88320 appears as an immediate, and there is no 256-entry table consumer. Both eors are 8-bit XOR accumulators seeded with 0. The string “CRC error: Obtained: %u Computed:%u” (0x1f864) is printed only by the second one, so the tool’s own message calls it a CRC but it is an XOR8.

Checksum 1, in set_ref_speed (host to PSoC), EVIDENCE disassembly 0x1840c to 0x18438:

mov r2,#0 ; mov r3,#0
loop: ldrb r12,[buf+r3] ; add r3,r3,#1 ; uxtb ; cmp r3,r4 ; eor r2,r2,r12 ; bcc loop
strb r2,[buf+r4] ; r4 = 2n+2

Equivalent C: x=0; for (i=0;i<2n+2;i++) x^=buf[i]; buf[2n+2]=x; The checksum covers the command byte, all motor bytes and the zero pad byte; it is the last byte of the frame.

Checksum 2, in get_obs_speed (PSoC to host), decompile 0x1891c:

uVar5 = n; bVar7 = 0; uVar6 = 0; uVar9 = (n + 3) * 2; // = 2n+6
do { bVar7 = bVar7 ^ rx[uVar6]; uVar6++; } while (uVar6 < uVar9);
if (rx[uVar9] == bVar7) { ...accept... }
else { fprintf(stderr, "\nlibMTB's MTB_BLDC_get_obs_speed(): CRC error: Obtained: %u Computed:%u\n"); return 0; }

XOR of rx[0..2n+5], compared with rx[2n+6], the last byte of the 2n+7 byte reply. Covers response bytes only (the 0x20 request has no checksum).

Commands with NO integrity byte at all: 0x06, 0x2B reply, 0x40, 0x4D, 0x60, 0x80, 0x82, 0x8D, 0xA0 reply (r13 ignored), 0xC0 (only the echo compare for ‘W’), 0xE0 pages, 0xFA.

How identified: grep of all eor, search for polynomial immediates, then xref from the “CRC error” string to 0x1891c. BLDC_maths.c is not a host source file: it is just one of the five PSoC file names in the assertion-file table (index 4). Nothing in the host decompile corresponds to it.

4. Status, error and observed-data encodings

Section titled “4. Status, error and observed-data encodings”

get_obs_speed reply (cmd 0x20), n = motor count, 2n+7 bytes; EVIDENCE disassembly 0x189e8 to 0x18ab4

Section titled “get_obs_speed reply (cmd 0x20), n = motor count, 2n+7 bytes; EVIDENCE disassembly 0x189e8 to 0x18ab4”

I resolved the two pc-relative bases: RX buffer starts at 0x33ba4 and the tail fields are read relative to the same 0x33b80 base.

Rx index Meaning
2i, 2i+1 (i = 0..n-1) motor i speed word. byte0 bit7 = flag (stored per motor, cleared when value is 0), value = (byte0 & 0x7F) << 8 | byte1 (15 bit)
2n, 2n+1 u16 BE battery voltage. Host stores raw/100 as a byte (umull by 0x51eb851f then >>5), printed “%u.%u Volt”, so raw is millivolts and the host keeps 0.1 V resolution (INFERENCE on unit)
2n+2 low nibble = current status (host +0x6f), high nibble = status at time of error (host +0x70)
2n+3 errno (host +0x6d). If it equals 0x0D the host immediately issues get_assert (0x2B)
2n+4 MotFault byte (host +0x71)
2n+5 signed byte temperature, degrees C (ldrsb into a short at +0x7c; printed “Temp: %3dC”)
2n+6 XOR8 checksum of bytes 0..2n+5

The log row printer 0x18b58 prints Vbat Status Errno MotFault TempCel (string 0x1f7cc) using exactly host fields +0x6c, +0x6f, +0x6d, +0x71, +0x7c, which confirms the mapping.

Status nibble values (name table 0x19050/0x1907c, pointer array at 0x3320c, 7 entries; the “unknown” fallback pointer 0x1f9e8 sits right after): 0 “init”, 1 “idle”, 2 “ramping”, 3 “opened loop spinning”, 4 “closed loop spinning”, 5 “stopping”, 6 “suicided”. The state-machine tests agree: 0x192bc treats 1 as startable and 6 as fatal, 0x19610 (check_ramping) waits while status is 1 or 2 and succeeds on 3 or 4, 0x197ac (check_braking) succeeds on 1. The error printer 0x190dc uses the low nibble when errno is 0 and the high nibble otherwise (EVIDENCE), which is why I call the high nibble “status at the time of error” (INFERENCE for the wording).

Errno values (pointer array at 0x331d0, 14 entries, “Unknown error” fallback at 0x1f9d0): 0 No error detected; 1 EEPROM access failure; 2 Motor stalled or low speed; 3 Shock on propeller detected; 4 Communication with motor failed by timeout; 5 H-bridge fault (over current or voltage drop or over temperature); 6 Battery shut-down unexpectedly; 7 Incorrect motor setting value; 8 BLDC temperature out of bounds; 9 Battery voltage out of bounds; 10 Incorrect number of LIPO cells detected during selftest; 11 Defectuous H-bridge or broken motor phases detected during selftest; 12 Motor firmware flash update failed; 13 Code assertion failed.

MotFault byte (0x190dc): errno 7 prints it as the offending setting number, errno 10 prints it as the cell count, errno 13 triggers the 0x2B assert query, any other errno with a non-zero byte is printed as a bitmask, one bit per motor (loop shifts the byte right and prints the index of each set bit). EVIDENCE for the three branches; the “bit per motor” reading follows the loop.

Log records (cmd 0xE0, 32-byte pages, 0x4B pages = 2400 bytes), decompile 0x1346c

Section titled “Log records (cmd 0xE0, 32-byte pages, 0x4B pages = 2400 bytes), decompile 0x1346c”

Mode flag at ctx+0x38: zero takes the 4-byte record path, nonzero the 16-byte path (which flag value means open or closed loop I did not trace; INFERENCE from the two header strings).

Open-loop record, 4 bytes, 8 per page, header “Message PWM ObsSpeed Vbat” (0x1e904): b0 = Vbat (raw byte), b1 = PWM, b2:b3 = ObsSpeed u16 BE. The decompile prints page.offset, b1, (b3 + b2*256), b0 against the format “%u.%u %u %u %u”. Column order matches the header only if the printed order PWM, ObsSpeed, Vbat is read as the header order, so treat the b0/b1 naming as INFERENCE; the byte positions are EVIDENCE.

Closed-loop record, 16 bytes, 2 per page, header “Message Vbat TicksSpeed RefSpeed ObsSpeed SatSpeed Feedforward IntegralPID PIDres PWM” (0x1e8ac), printed with “%u.%u %u %u %u %u %d %d %d %d %u\n”:

Bytes Decoded as Header column (INFERENCE by order, 9 values for 9 columns)
b0 u8 Vbat
b1:b2 u16 BE TicksSpeed
b3:b4 u16 BE RefSpeed
b5:b6 (b5 & 0x7F) << 8 | b6, 15 bit ObsSpeed
b5 bit7 flag SatSpeed
b7:b8 s16 BE Feedforward
b9..b12 u32 BE IntegralPID
b13:b14 s16 BE PIDres
b15 u8 times sign(s16(b7:b8) + s16(b13:b14)) (-1, 0 or +1) PWM

The 15-bit value with a top flag bit is the same encoding as the per-motor words in the 0x20 reply, which supports reading the flag as a saturation marker.

Units of Vbat in the log byte, and “Errno”/“MotFault” in the CSV (written as Vbat Status Errno MotFault TempCel rows, 0x1f7cc) are not given by the binary beyond what is above.

This is the Cypress PSoC 3/5 bootloader host protocol over the same I2C address 8. Build id 3be23a40…, source files BLDC_host_bootloader.c, BLDC_host_bootloader_routines.c, BLDC_tools_comm.c, NativeI2C.c. Static only (llvm-objdump 0x1109c to 0x13e4c); no Ghidra instance started.

Transport: same as test bench: open(“/dev/i2c-1”, O_RDWR) (0x13798 mov r1,#2), ioctl 0x706 with address 8 (0x137bc). Send path 0x13700: write the frame, then usleep(arg * 125 * 8 = arg*1000) microseconds (0x1370c to 0x13720), so the numbers passed at call sites are post-write delays in ms. Read path 0x133d8 polls reads of the frame length, discards reads that are all 0xFF, sleeps 10 ms (movw r0,#0x2710) between retries, and fails with a 43-byte timeout message once more than one second (tv_sec delta > 0) has passed. After each exchange 0x11354 does usleep(100).

Frame layout (EVIDENCE, build sites at 0x11734, 0x11650, 0x11a70, 0x11b5c, 0x11c80, 0x11d70, 0x11988)

Section titled “Frame layout (EVIDENCE, build sites at 0x11734, 0x11650, 0x11a70, 0x11b5c, 0x11c80, 0x11d70, 0x11988)”
[0x01] [cmd] [len_lo] [len_hi] [data ... len bytes] [chk_lo] [chk_hi] [0x17]

Start byte 0x01, end byte 0x17 (mov r12,#23), length is u16 little-endian counting data bytes only, checksum is u16 little-endian over start..data (everything before the checksum), then 0x17. Response frame is the same shape: [01][status][len_lo][len_hi][data][chk][chk][17]. Receive parsers (0x11220 and the checks after each 0x11354 call) test byte0 == 0x01, byte1 == 0 (else return byte1 | 0x40), the expected length, and the final byte == 0x17. I found no code that recomputes the checksum of a received frame (INFERENCE: response checksums are ignored; every parse path I read compares start, status, length and end byte only). The ASCII-hex line parser (0x111d0) and ‘:’ check (0x114e8, cmp r12,#58) are for the .cyacd file.

Checksum routine at 0x1127c (arguments: buffer, length, type), disassembly verbatim, trimmed

Section titled “Checksum routine at 0x1127c (arguments: buffer, length, type), disassembly verbatim, trimmed”
1127c: cmp r2,#1 ; bhi assert(line 220 "(0x00 == chksumType) || (0x01 == chksumType)") ; beq 0x112c8
; type 0 : 16-bit two's complement byte sum
1128c: sub r3,r1,#1 ; ... movne r3,#0
112a8: ldrb r2,[r0,#1]! ; cmp r0,r1 ; add r3,r3,r2 ; uxth r3,r3 ; bne 112a8
112bc: rsb r1,r3,#0 ; uxth r0,r1 ; pop {r4,pc}
; type 1 : CRC-16, reflected poly 0x8408, seed 0xFFFF
112dc: movw r3,#0xffff
112e0: ldrb r0,[lr,#1]! ; mov r2,#8
112e8: eor r12,r0,r3 ; lsr r3,r3,#1 ; tst r12,#1 ; lsr r0,r0,#1
112f8: eorne r3,r3,#33792 ; 0x8400
112fc: eorne r3,r3,#8 ; 0x0008 -> xor 0x8408
11300: subs r2,r2,#1 ; bne 112e8
11308: cmp lr,r1 ; bne 112e0
11310: mvn r3,r3 ; rev16 r1,r3 ; uxth r0,r1 ; invert, then swap bytes

C equivalent (my transcription): type 0: return (uint16_t)(0 - sum16); type 1: crc=0xFFFF; for each byte, 8 times: if ((crc^b)&1) crc=(crc>>1)^0x8408 else crc>>=1; b>>=1; return bswap16(~crc);. This is the CRC-16/Cypress variant (reflected 0x1021, init 0xFFFF, final invert then byte swap). The result is stored low byte first in the frame (strb r2,[sp,#0xc] then lsr #8 high byte at +0xd).

Which type is used: it is the cyacd header’s checksum type, parsed as an ASCII-hex byte with asserts that it is 0 or 1. EVIDENCE from the shipped firmware: /lib/firmware/BLDC.cyacd header line is 1E0680690300 = silicon id 0x1E068069, silicon rev 0x03, checksum type 0x00. Of its 89 data rows all 89 have a valid two’s complement row checksum (checked with a script). So for the firmware that ships on this drone the packet checksum is the type 0 two’s complement sum, not the CRC-16. The CRC-16 branch exists in the code but would only run for a type 1 cyacd file.

Commands used (byte after the start byte), EVIDENCE sites above

Section titled “Commands used (byte after the start byte), EVIDENCE sites above”
Cmd Name Frame (data) Response data Site
0x38 Enter bootloader len 0, 7 byte frame 8 bytes: silicon id u32 LE, silicon rev u8, bootloader version 3 bytes 0x11734, 0x117ec; parse at 0x1185c
0x32 Get flash size len 1: array id 4 bytes: first row u16 LE, last row u16 LE 0x11650
0x37 Send data len 121 (0x79): up to 121 data bytes, repeated while a row has more than 121 bytes left none checked beyond status 0x11a70
0x39 Program row len = n+3: array id u8, row u16 LE, then remaining row bytes status only 0x11b5c
0x3A Verify row len 3: array id, row u16 LE 1 byte: row checksum, compared against the .cyacd row checksum, mismatch returns error 6 0x11c80, compare at 0x11d34
0x31 Verify (application) checksum len 0 1 byte, zero means invalid (returns 6) 0x11d70, test at 0x11e3c
0x3B Exit bootloader len 1, data byte 0x00 none read (written then 500 ms wait) 0x11988

I did not find uses of 0x33, 0x34, 0x35 or 0x36 (immediates 51/52/53/54 do not appear as command bytes in the packet builders; mov r2,#51 at 0x129b8 and the other 50 to 67 immediates outside this list are unrelated string lengths or loop constants). The bootloader enter check requires silicon id equal to the cyacd header’s, silicon rev equal, and (version & 0xFF0000) == 0x010000 (0x11910), then prints “[BLDC Card Bootloader] Version: 0x%x, Silicon Id: 0x%x, Silicon Rev: 0x%x”. Strings state the minimum bootloader version is v3.30.

Comparison with Cypress’s published bootloader host protocol (from my memory of Cypress application notes AN68272 and the CyBtldr host source; NOT verified against a document in this session, so treat as a pointer): start 0x01, end 0x17, little-endian length and checksum, commands 0x31 verify checksum, 0x32 get flash size, 0x38 enter bootloader, 0x37 send data, 0x39 program row, 0x3A verify row, 0x3B exit bootloader; checksum type 0 = 16-bit two’s complement sum and type 1 = CRC-16 with byte swap; status byte 0 = success, error codes OR 0x40. Everything observed here matches that description, so the PSoC runs Cypress’s stock bootloader and the host is a straightforward port of the Cypress host library.

Other behaviours seen in strings and call flow (EVIDENCE: strings): resets the PSoC through /sys/devices/platform/user_gpio/RESET_PSOC/value, keeps an MD5 of the last flashed firmware in /data/.BLDC_flashed.md5 and skips flashing when it matches (“BLDC already up-to-date”), default file /lib/firmware/BLDC.cyacd, and refuses firmware not tagged “Released for 4 motors”.

6. Verdicts on psoc-firmware-DRAFT-unverified.md

Section titled “6. Verdicts on psoc-firmware-DRAFT-unverified.md”
Claim Verdict Basis
Command numbers 0x00 to 0x09 in function-list order REFUTED Real command bytes are 0x02, 0x06, 0x20, 0x2B, 0x40, 0x4D, 0x60, 0x80, 0x82, 0x8D, 0xA0, 0xC0, 0xE0, 0xFA (section 2). Only 0x02 and 0x06 fall in 0x00 to 0x09 and neither matches the draft’s ordering.
Frame is [cmd][params][CRC_LO][CRC_HI] REFUTED No two-byte trailer. Only set_ref_speed (0x02) and the get_obs_speed reply carry a single XOR8 byte; most commands carry no check at all.
CRC-16-CCITT, poly 0x1021, seed 0xFFFF on the I2C control link REFUTED Control link has no CRC (only two eor instructions in the binary, both XOR8, seed 0). A reflected 0x1021 CRC-16 with seed 0xFFFF does exist, but only in BLDC_Host_Bootloader, only for cyacd checksum type 1, and the shipped BLDC.cyacd is type 0.
10 kHz PID loop NOT DETERMINABLE FROM THESE BINARIES Host tools contain no loop-rate constant. Strings mention “PWM frequency 2^x-1” as a settings entry and “cycles x 1 ms” units for security counters, which suggests a 1 ms housekeeping tick, but that is not a PID rate (INFERENCE).
120 C limit NOT DETERMINABLE FROM THESE BINARIES Only names exist: “Cypress Die min/max temperature” (unit abs(degC)) and errno 8 “BLDC temperature out of bounds”. Values live in PSoC flash/EEPROM. The BLDC.cyacd image would hold them but was out of scope.
20 percent PWM soft-start over 500 ms NOT DETERMINABLE FROM THESE BINARIES Host only knows setting names “Ramp start/end voltage”, “Ramp start/end propeller speed”, “Ramp duration”, “Ramp speed locking duration” (units deciVolt, RPM, ms). No values. The draft’s numbers are not supported or contradicted here. Note the ramp is configured in volts and RPM, not as a percent PWM, per those names.

Comments

Spotted a mistake, or tried this on your own Bebop? Leave a note. Comments are kept on this site's own server.