Skip to content

Commit

Permalink
increase firmware flashing packet size
Browse files Browse the repository at this point in the history
  • Loading branch information
dlech committed Jul 3, 2020
1 parent c3037a5 commit 0944a27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/protocols/lwp3-bootloader.ts
Expand Up @@ -63,8 +63,19 @@ export enum Result {

/**
* The largest allowable size for the payload of the ProgramFlash command.
*
* Theoretically, this is MTU - 9. However, City hub and Control+ hub report
* MTU of 158 but don't seem to be able to handle receiving that much data.
* Anything larger than 32 causes the bootloader to lock up.
*/
export const MaxProgramFlashSize = 14;
export const MaxProgramFlashSize: ReadonlyMap<HubType, number> = new Map<
HubType,
number
>([
[HubType.MoveHub, 14],
[HubType.CityHub, 32],
[HubType.CPlusHub, 32],
]);

/**
* Flash memory protection level.
Expand Down Expand Up @@ -111,7 +122,6 @@ export function createProgramFlashRequest(
payload: ArrayBuffer,
): Uint8Array {
const size = payload.byteLength;
assert(size <= MaxProgramFlashSize, 'payload is bigger than MaxProgramFlashSize');
const msg = new Uint8Array(size + 6);
const view = new DataView(msg.buffer);
view.setUint8(0, Command.ProgramFlash);
Expand Down
9 changes: 7 additions & 2 deletions src/sagas/flash-firmware.ts
Expand Up @@ -303,9 +303,14 @@ function* flashFirmware(action: FlashFirmwareFlashAction): Generator {
}

let count = 0;
const maxDataSize = MaxProgramFlashSize.get(info[0].hubType);
if (maxDataSize === undefined) {
// istanbul ignore next: indicates programmer error if reached
throw Error('Missing hub type in MaxProgramFlashSize');
}

for (let offset = 0; offset < firmware.length; offset += MaxProgramFlashSize) {
const payload = firmware.slice(offset, offset + MaxProgramFlashSize);
for (let offset = 0; offset < firmware.length; offset += maxDataSize) {
const payload = firmware.slice(offset, offset + maxDataSize);
const programAction = (yield put(
programRequest(info[0].startAddress + offset, payload.buffer),
)) as BootloaderProgramRequestAction;
Expand Down

0 comments on commit 0944a27

Please sign in to comment.