Skip to content

Commit

Permalink
Update firmware to v3.0.0a11
Browse files Browse the repository at this point in the history
Also take advantage of new helper functions in firmware package.
  • Loading branch information
dlech committed Nov 21, 2020
1 parent 71ad9c1 commit 4ee5007
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 41 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@blueprintjs/core": "^3.30.1",
"@pybricks/firmware": "3.1.0",
"@pybricks/firmware": "4.1.0",
"@pybricks/mpy-cross-v5": "^1.1.0",
"@shopify/react-i18n": "^5.0.0",
"@testing-library/jest-dom": "^5.8.0",
Expand All @@ -22,7 +22,6 @@
"@types/zen-push": "^0.1.1",
"ace-builds": "^1.4.11",
"file-saver": "^2.0.2",
"jszip": "^3.5.0",
"node-sass": "^4.14.1",
"react": "^16.13.1",
"react-ace": "^9.1.3",
Expand Down
41 changes: 6 additions & 35 deletions src/sagas/flash-firmware.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors

import { FirmwareMetadata, FirmwareReader, HubType } from '@pybricks/firmware';
import cityHubZip from '@pybricks/firmware/build/cityhub.zip';
import moveHubZip from '@pybricks/firmware/build/movehub.zip';
import technicHubZip from '@pybricks/firmware/build/technichub.zip';
import JSZip from 'jszip';
import {
Effect,
all,
Expand Down Expand Up @@ -58,7 +58,7 @@ import {
compile,
} from '../actions/mpy';
import * as notification from '../actions/notification';
import { HubType, MaxProgramFlashSize } from '../protocols/lwp3-bootloader';
import { MaxProgramFlashSize } from '../protocols/lwp3-bootloader';
import { fmod, sumComplement32 } from '../utils/math';

const firmwareZipMap = new Map<HubType, string>([
Expand Down Expand Up @@ -98,17 +98,6 @@ function waitForResponse(type: BootloaderResponseActionType, timeout = 500): Eff
return race([take(type), take(BootloaderResponseActionType.Error), delay(timeout)]);
}

interface FirmwareMetadata {
'metadata-version': string;
'firmware-version': string;
'device-id': HubType;
'checksum-type': 'sum' | 'crc32';
'mpy-abi-version': number;
'mpy-cross-options': string[];
'user-mpy-offset': number;
'max-firmware-size': number;
}

function* firmwareIterator(data: DataView, maxSize: number): Generator<number> {
// read each 32-bit word of the firmware
for (let i = 0; i < data.byteLength; i += 4) {
Expand All @@ -127,29 +116,11 @@ function* firmwareIterator(data: DataView, maxSize: number): Generator<number> {
function* loadFirmware(
data: ArrayBuffer,
): Generator<unknown, { firmware: Uint8Array; deviceId: HubType }> {
const zip = (yield call(() => JSZip.loadAsync(data))) as JSZip;

const firmwareBaseFile = zip.file('firmware-base.bin');
if (firmwareBaseFile === null) {
throw Error('Missing firmware-base.bin');
}
const firmwareBase = (yield call(() =>
firmwareBaseFile.async('uint8array'),
)) as Uint8Array;
const reader = (yield call(() => FirmwareReader.load(data))) as FirmwareReader;

const metadataFile = zip.file('firmware.metadata.json');
if (metadataFile === null) {
throw Error('Missing firmware.metadata.json');
}
const metadata = JSON.parse(
(yield call(() => metadataFile.async('text'))) as string,
) as FirmwareMetadata;

const mainFile = zip.file('main.py');
if (mainFile === null) {
throw Error('Missing main.py');
}
const main = (yield call(() => mainFile.async('text'))) as string;
const firmwareBase = (yield call(() => reader.readFirmwareBase())) as Uint8Array;
const metadata = (yield call(() => reader.readMetadata())) as FirmwareMetadata;
const main = (yield call(() => reader.readMainPy())) as string;

if (metadata['mpy-abi-version'] !== 5) {
throw Error(
Expand Down
10 changes: 6 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1458,10 +1458,12 @@
schema-utils "^2.6.5"
source-map "^0.7.3"

"@pybricks/firmware@3.1.0":
version "3.1.0"
resolved "https://npm.pkg.github.com/download/@pybricks/firmware/3.1.0/9b3abdac044428108bed6d1acf1fe2e95266181026b8e28a3e4ffc8a5f4fa2e2#35abf937a7dc2d88cc73857da363a298a17453c6"
integrity sha512-aST/+8KZtejAhy2t/oGG16QaajT8RziHUDy3Li67dlIRuYA43xlKcTbTJAegCGJm3rpXlkcCEms5+yxP5+Krag==
"@pybricks/firmware@4.1.0":
version "4.1.0"
resolved "https://npm.pkg.github.com/download/@pybricks/firmware/4.1.0/a4c0914750afa8aee656dd3a771b22e4da75607f0201ded148fb6bbf3f017ed1#3deb1772c469c48944c4fc022f7322b0fb3102f9"
integrity sha512-aQ46+X86J7GHqO2wwgq02lDhvV4WZJWGOrfuOZJfH3ss4bdErhBJaIwZ7zjVxI2DrWlrbMwjGEA6H/b9NholFQ==
dependencies:
jszip "^3.5.0"

"@pybricks/mpy-cross-v5@^1.1.0":
version "1.1.0"
Expand Down

0 comments on commit 4ee5007

Please sign in to comment.