node-raspberrypi-usbboot
Advanced tools
Comparing version 0.1.0 to 0.2.0-use-usb-types-c38d2b6689484d90994bd5b14d1bac387392ce1b
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
export declare const isUsbBootCapableUSBDevice: (idVendor: number, idProduct: number) => boolean; | ||
export declare class UsbbootDevice extends EventEmitter { | ||
portId: string; | ||
static LAST_STEP: number; | ||
static readonly LAST_STEP: number; | ||
private _step; | ||
@@ -7,0 +8,0 @@ constructor(portId: string); |
"use strict"; | ||
/* | ||
* This work is heavily based on https://github.com/raspberrypi/usbboot | ||
* Copyright 2016 Raspberry Pi Foundation | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,6 +15,3 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* | ||
* This work is heavily based on https://github.com/raspberrypi/usbboot | ||
* Copyright 2016 Raspberry Pi Foundation | ||
*/ | ||
// tslint:disable:no-bitwise | ||
const bluebird_1 = require("bluebird"); | ||
@@ -148,7 +149,10 @@ const _debug = require("debug"); | ||
}); | ||
const isUsbBootCapableUSBDevice = (device) => { | ||
return (device.deviceDescriptor.idVendor === USB_VENDOR_ID_BROADCOM_CORPORATION && | ||
(device.deviceDescriptor.idProduct === USB_PRODUCT_ID_BCM2708_BOOT || | ||
device.deviceDescriptor.idProduct === USB_PRODUCT_ID_BCM2710_BOOT)); | ||
exports.isUsbBootCapableUSBDevice = (idVendor, idProduct) => { | ||
return (idVendor === USB_VENDOR_ID_BROADCOM_CORPORATION && | ||
(idProduct === USB_PRODUCT_ID_BCM2708_BOOT || | ||
idProduct === USB_PRODUCT_ID_BCM2710_BOOT)); | ||
}; | ||
const isUsbBootCapableUSBDevice$ = (device) => { | ||
return exports.isUsbBootCapableUSBDevice(device.deviceDescriptor.idVendor, device.deviceDescriptor.idProduct); | ||
}; | ||
const isRaspberryPiInMassStorageMode = (device) => { | ||
@@ -165,3 +169,3 @@ return (device.deviceDescriptor.idVendor === USB_VENDOR_ID_NETCHIP_TECHNOLOGY && | ||
let endpointNumber; | ||
if (device._configDescriptor.bNumInterfaces === | ||
if (device.configDescriptor.bNumInterfaces === | ||
USB_ENDPOINT_INTERFACES_SOC_BCM2835) { | ||
@@ -178,3 +182,6 @@ interfaceNumber = 0; | ||
const endpoint = iface.endpoint(endpointNumber); | ||
debug('Initialized device correctly', portId(device)); | ||
if (!(endpoint instanceof usb.OutEndpoint)) { | ||
throw new Error('endpoint is not an usb.OutEndpoint'); | ||
} | ||
debug('Initialized device correctly', devicePortId(device)); | ||
return { iface, endpoint }; | ||
@@ -210,3 +217,5 @@ }; | ||
} | ||
catch (e) { } | ||
catch (e) { | ||
// no data | ||
} | ||
}); | ||
@@ -256,3 +265,3 @@ const getFileBuffer = (filename) => __awaiter(this, void 0, void 0, function* () { | ||
yield epWrite(bootMessage, device, endpoint); | ||
debug(`Writing ${bootMessage.length} bytes`, portId(device)); | ||
debug(`Writing ${bootMessage.length} bytes`, devicePortId(device)); | ||
yield epWrite(bootcodeBuffer, device, endpoint); | ||
@@ -324,7 +333,7 @@ // raspberrypi's sample code has a sleep(1) here, but it looks like it isn't required. | ||
get(device) { | ||
const key = portId(device); | ||
const key = devicePortId(device); | ||
return this.usbbootDevices.get(key); | ||
} | ||
getOrCreate(device) { | ||
const key = portId(device); | ||
const key = devicePortId(device); | ||
let usbbootDevice = this.usbbootDevices.get(key); | ||
@@ -339,3 +348,3 @@ if (usbbootDevice === undefined) { | ||
remove(device) { | ||
const key = portId(device); | ||
const key = devicePortId(device); | ||
const usbbootDevice = this.usbbootDevices.get(key); | ||
@@ -350,15 +359,15 @@ if (usbbootDevice !== undefined) { | ||
if (isRaspberryPiInMassStorageMode(device) && | ||
this.usbbootDevices.has(portId(device))) { | ||
this.usbbootDevices.has(devicePortId(device))) { | ||
this.step(device, 41); | ||
return; | ||
} | ||
if (!isUsbBootCapableUSBDevice(device)) { | ||
if (!isUsbBootCapableUSBDevice$(device)) { | ||
return; | ||
} | ||
debug('Found serial number', device.deviceDescriptor.iSerialNumber); | ||
debug('port id', portId(device)); | ||
debug('port id', devicePortId(device)); | ||
try { | ||
const { iface, endpoint } = initializeDevice(device); | ||
if (device.deviceDescriptor.iSerialNumber === 0) { | ||
debug('Sending bootcode.bin', portId(device)); | ||
debug('Sending bootcode.bin', devicePortId(device)); | ||
this.step(device, 0); | ||
@@ -370,3 +379,3 @@ yield secondStageBoot(device, endpoint); | ||
else { | ||
debug('Second stage boot server', portId(device)); | ||
debug('Second stage boot server', devicePortId(device)); | ||
yield this.fileServer(device, endpoint, 2); | ||
@@ -377,3 +386,3 @@ } | ||
catch (error) { | ||
debug('error', error, portId(device)); | ||
debug('error', error, devicePortId(device)); | ||
this.remove(device); | ||
@@ -384,7 +393,7 @@ } | ||
detachDevice(device) { | ||
if (!isUsbBootCapableUSBDevice(device)) { | ||
if (!isUsbBootCapableUSBDevice$(device)) { | ||
return; | ||
} | ||
const step = device.deviceDescriptor.iSerialNumber === 0 ? 1 : 40; | ||
debug('detach', portId(device), step); | ||
debug('detach', devicePortId(device), step); | ||
this.step(device, step); | ||
@@ -396,3 +405,3 @@ // This timeout is here to differentiate between the device resetting and the device being unplugged | ||
if (usbbootDevice !== undefined && usbbootDevice.step === step) { | ||
debug('device', portId(device), 'did not reattached after', DEVICE_UNPLUG_TIMEOUT, 'ms.'); | ||
debug('device', devicePortId(device), 'did not reattached after', DEVICE_UNPLUG_TIMEOUT, 'ms.'); | ||
this.remove(device); | ||
@@ -421,3 +430,3 @@ } | ||
const message = parseFileMessageBuffer(data); | ||
debug('Received message', FileMessageCommand[message.command], message.filename, portId(device)); | ||
debug('Received message', FileMessageCommand[message.command], message.filename, devicePortId(device)); | ||
if (message.command === FileMessageCommand.GetFileSize || | ||
@@ -427,3 +436,3 @@ message.command === FileMessageCommand.ReadFile) { | ||
if (buffer === undefined) { | ||
debug(`Couldn't find ${message.filename}`, portId(device)); | ||
debug(`Couldn't find ${message.filename}`, devicePortId(device)); | ||
yield sendSize(device, 0); | ||
@@ -444,3 +453,3 @@ } | ||
} | ||
debug('File server done', portId(device)); | ||
debug('File server done', devicePortId(device)); | ||
}); | ||
@@ -450,5 +459,5 @@ } | ||
exports.UsbbootScanner = UsbbootScanner; | ||
const portId = (device) => { | ||
const devicePortId = (device) => { | ||
return `${device.busNumber}-${device.portNumbers.join('.')}`; | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -7,2 +7,8 @@ # Change Log | ||
## 0.2.0 - 2019-03-18 | ||
* Export isUsbBootCapableUSBDevice [Alexis Svinartchouk] | ||
* Update resin-lint to ^3.0.1 [Alexis Svinartchouk] | ||
* Use @types/usb instead of our own typings [Alexis Svinartchouk] | ||
## 0.1.0 - 2019-02-07 | ||
@@ -9,0 +15,0 @@ |
{ | ||
"name": "node-raspberrypi-usbboot", | ||
"version": "0.1.0", | ||
"version": "0.2.0-use-usb-types-c38d2b6689484d90994bd5b14d1bac387392ce1b", | ||
"description": "Transforms Raspberry Pi Compute Modules and Zeros to mass storage devices.", | ||
@@ -8,4 +8,4 @@ "main": "build/index.js", | ||
"scripts": { | ||
"prettier": "prettier --config ./node_modules/resin-lint/config/.prettierrc --write \"lib/**/*.ts\" \"typings/**/*.ts\"", | ||
"lint": "resin-lint --typescript lib/*.ts typings/**/*.d.ts", | ||
"prettier": "prettier --config ./node_modules/resin-lint/config/.prettierrc --write \"lib/**/*.ts\"", | ||
"lint": "resin-lint --typescript lib/*.ts", | ||
"build": "npm run lint && rimraf build && tsc", | ||
@@ -30,2 +30,3 @@ "prepublish": "npm run build" | ||
"@types/node": "^6.0.112", | ||
"@types/usb": "^1.5.1", | ||
"debug": "^3.1.0", | ||
@@ -37,3 +38,3 @@ "usb": "github:resin-io/node-usb#1.3.5" | ||
"@types/debug": "0.0.30", | ||
"resin-lint": "^2.0.1", | ||
"resin-lint": "^3.0.1", | ||
"rimraf": "^2.6.2", | ||
@@ -40,0 +41,0 @@ "ts-node": "^6.0.3", |
Sorry, the diff of this file is not supported yet
27824865
471
4
+ Added@types/usb@^1.5.1
+ Added@types/usb@1.5.4(transitive)