/** * (c) 2021, Micro:bit Educational Foundation and contributors * * SPDX-License-Identifier: MIT * * This file is made up of a combination of original code, along with code * extracted from the following repositories: * * https://github.com/mmoskal/dapjs/tree/a32f11f54e9e76a9c61896ddd425c1cb1a29c143 * https://github.com/microsoft/pxt-microbit * * The pxt-microbit license is included below. * * PXT - Programming Experience Toolkit * * The MIT License (MIT) * * Copyright (c) Microsoft Corporation * * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * Implementation of partial flashing for the micro:bit. * * Latest Microsoft implementation is here: * https://github.com/microsoft/pxt-microbit/blob/master/editor/flash.ts */ import { Logging } from "../logging.js"; import { BoardVersion, ProgressCallback } from "../device.js"; import MemoryMap from "nrf-intel-hex"; import { USBDeviceWrapper } from "./device-wrapper.js"; /** * Uses a USBDeviceWrapper to flash the micro:bit. * * Intended to be used for a single flash with a pre-connected USBDeviceWrapper. */ export declare class PartialFlashing { private device; private logging; private boardVersion; private pageSize; private numPages; constructor(device: USBDeviceWrapper, logging: Logging, boardVersion: BoardVersion, pageSize: number, numPages: number); private log; private getFlashChecksumsAsync; private runFlash; private partialFlashPageAsync; private partialFlashCoreAsync; private partialFlashAsync; fullFlashAsync(data: string | Uint8Array | MemoryMap, updateProgress: ProgressCallback): Promise; flashAsync(data: string | Uint8Array | MemoryMap, updateProgress: ProgressCallback): Promise; private convertDataToHexString; /** * Parse the flash data into a MemoryMap (if not already one). */ private toMemoryMap; /** * Extract padded flash bytes (main flash only) and UICR entries from a * MemoryMap. Parses the data once for both. */ private extractFlashAndUicr; /** * Check UICR and repair if needed after a partial flash. * * UICR bits can only be cleared (1→0) without erasing. If all mismatched * bits only need 1→0, we can write directly on both V1 and V2. * If any bit needs 0→1, an erase is required first: * - V2: erase via NVMC.ERASEUICR, then write * - V1: no independent UICR erase, fall back to full flash * * Returns true if we stayed on the partial flash path, false if we had * to fall back to full flash. */ private ensureUicr; }