node-raspberrypi-usbboot
Advanced tools
Comparing version 1.0.8 to 1.1.0-build-aethernet-allow-custom-sb-assets-1e632df4508ee97fcc25fa5ebdea8bf10a440aa9-1
@@ -26,3 +26,4 @@ /// <reference types="node" /> | ||
private attachedDeviceIds; | ||
constructor(); | ||
private extraFolder; | ||
constructor(extraFolder?: string); | ||
start(): void; | ||
@@ -29,0 +30,0 @@ stop(): void; |
@@ -251,5 +251,19 @@ "use strict"; | ||
}; | ||
const safeReadFile = async (filename) => { | ||
const getFileBuffer = async (device, filename, extraFolder) => { | ||
try { | ||
return await (0, promises_1.readFile)(Path.join(__dirname, '..', 'blobs', filename)); | ||
if (extraFolder) { | ||
const extraBuffer = await (0, promises_1.readFile)(Path.join(extraFolder, filename)); | ||
if (extraBuffer !== undefined) { | ||
debug(`Sending buffer from ${extraFolder}/${filename}`); | ||
return extraBuffer; | ||
} | ||
} | ||
const folder = device.deviceDescriptor.idProduct === USB_PRODUCT_ID_BCM2711_BOOT | ||
? 'cm4' | ||
: 'raspberrypi'; | ||
const buffer = await (0, promises_1.readFile)(Path.join(__dirname, '..', 'blobs', folder, filename)); | ||
if (buffer === undefined) { | ||
debug("Can't read file", filename); | ||
} | ||
return buffer; | ||
} | ||
@@ -260,12 +274,2 @@ catch (e) { | ||
}; | ||
const getFileBuffer = async (device, filename) => { | ||
const folder = device.deviceDescriptor.idProduct === USB_PRODUCT_ID_BCM2711_BOOT | ||
? 'cm4' | ||
: 'raspberrypi'; | ||
const buffer = await safeReadFile(Path.join(folder, filename)); | ||
if (buffer === undefined) { | ||
debug("Can't read file", filename); | ||
} | ||
return buffer; | ||
}; | ||
/** | ||
@@ -361,3 +365,3 @@ * @summary Create a boot message buffer | ||
class UsbbootScanner extends events_1.EventEmitter { | ||
constructor() { | ||
constructor(extraFolder) { | ||
super(); | ||
@@ -369,2 +373,4 @@ this.usbbootDevices = new Map(); | ||
this.attachedDeviceIds = new Set(); | ||
this.extraFolder = extraFolder; | ||
debug(`Extra folder: ${extraFolder}`); | ||
this.boundAttachDevice = this.attachDevice.bind(this); | ||
@@ -376,2 +382,3 @@ this.boundDetachDevice = this.detachDevice.bind(this); | ||
// Prepare already connected devices | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
usb_1.usb.getDeviceList().map(this.boundAttachDevice); | ||
@@ -385,4 +392,3 @@ // At this point all devices from `usg.getDeviceList()` above | ||
usb_1.usb.on('detach', this.boundDetachDevice); | ||
// ts-ignore because of a confusion between NodeJS.Timer and number | ||
// @ts-ignore | ||
// @ts-expect-error because of a confusion between NodeJS.Timer and number | ||
this.interval = setInterval(() => { | ||
@@ -438,3 +444,3 @@ // usb.getDeviceList().forEach(this.boundAttachDevice); | ||
let forceSecondstage = false; | ||
if (device.deviceDescriptor.iSerialNumber == (usbbootDevice === null || usbbootDevice === void 0 ? void 0 : usbbootDevice.last_serial)) { | ||
if (device.deviceDescriptor.iSerialNumber === (usbbootDevice === null || usbbootDevice === void 0 ? void 0 : usbbootDevice.last_serial)) { | ||
if (usbbootDevice.step > 0) { | ||
@@ -453,3 +459,3 @@ forceSecondstage = true; | ||
} | ||
debug('Found serial number', device.deviceDescriptor.iSerialNumber, `${forceSecondstage ? " => Forced second stage" : ""}`); | ||
debug('Found serial number', device.deviceDescriptor.iSerialNumber, `${forceSecondstage ? ' => Forced second stage' : ''}`); | ||
debug('port id', devicePortId(device)); | ||
@@ -460,3 +466,4 @@ try { | ||
if ((device.deviceDescriptor.iSerialNumber === 0 || | ||
device.deviceDescriptor.iSerialNumber === 3) && !forceSecondstage) { | ||
device.deviceDescriptor.iSerialNumber === 3) && | ||
!forceSecondstage) { | ||
debug('Sending bootcode.bin', devicePortId(device)); | ||
@@ -469,4 +476,5 @@ this.step(device, 0); | ||
else { | ||
const extraFolder = this.extraFolder; | ||
debug('Second stage boot server', devicePortId(device)); | ||
await this.fileServer(device, endpoint, 2); | ||
await this.fileServer(device, endpoint, 2, extraFolder); | ||
} | ||
@@ -501,3 +509,4 @@ device.close(); | ||
} | ||
async fileServer(device, endpoint, step) { | ||
async fileServer(device, endpoint, step, extraFolder) { | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -523,3 +532,3 @@ let data; | ||
message.command === FileMessageCommand.ReadFile) { | ||
const buffer = await getFileBuffer(device, message.filename); | ||
const buffer = await getFileBuffer(device, message.filename, extraFolder); | ||
if (buffer === undefined) { | ||
@@ -526,0 +535,0 @@ debug(`Couldn't find ${message.filename}`, devicePortId(device)); |
@@ -7,2 +7,8 @@ # Change Log | ||
# v1.1.0 | ||
## (2024-06-07) | ||
* minor: allow passing custom assets to start SB protected CM4 [Edwin Joassart] | ||
* patch: fix linter, formatting and old errors [Edwin Joassart] | ||
# v1.0.8 | ||
@@ -9,0 +15,0 @@ ## (2024-04-12) |
{ | ||
"name": "node-raspberrypi-usbboot", | ||
"version": "1.0.8", | ||
"version": "1.1.0-build-aethernet-allow-custom-sb-assets-1e632df4508ee97fcc25fa5ebdea8bf10a440aa9-1", | ||
"description": "Transforms Raspberry Pi Compute Modules and Zeros to mass storage devices.", | ||
@@ -8,3 +8,3 @@ "main": "build/index.js", | ||
"scripts": { | ||
"prettier": "balena-lint --fix --typescript lib/*.ts", | ||
"prettier": "balena-lint --fix --typescript typings lib", | ||
"lint": "balena-lint --typescript lib/*.ts", | ||
@@ -34,7 +34,7 @@ "build": "npm run lint && rimraf build && tsc", | ||
"devDependencies": { | ||
"@balena/lint": "8.0.1", | ||
"@balena/lint": "8.0.2", | ||
"@types/debug": "^4.1.12", | ||
"@types/node": "^20.12.7", | ||
"node-gyp-build": "^4.8.0", | ||
"rimraf": "^5.0.5", | ||
"@types/node": "^20.12.12", | ||
"node-gyp-build": "^4.8.1", | ||
"rimraf": "^5.0.7", | ||
"ts-node": "^10.9.2", | ||
@@ -44,4 +44,4 @@ "typescript": "^5.4.5" | ||
"versionist": { | ||
"publishedAt": "2024-04-12T10:09:10.968Z" | ||
"publishedAt": "2024-06-07T09:42:38.723Z" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28087755
595
2