chore(kboot): add more logging (#1004)
This commit is contained in:
committed by
László Monda
parent
db2e14a852
commit
4d2d6d40fb
@@ -33,13 +33,14 @@ export class UsbPeripheral implements Peripheral {
|
|||||||
logger('Available devices');
|
logger('Available devices');
|
||||||
const device = devices()
|
const device = devices()
|
||||||
.map(x => {
|
.map(x => {
|
||||||
logger('%O', x);
|
logger('%o', x);
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
})
|
})
|
||||||
.find(deviceFinder(this.options));
|
.find(deviceFinder(this.options));
|
||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
|
logger('USB device can not be found %o', this.options);
|
||||||
throw new Error('USB device can not be found');
|
throw new Error('USB device can not be found');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,10 +81,12 @@ export class UsbPeripheral implements Peripheral {
|
|||||||
|
|
||||||
const firsCommandResponse = await this.sendCommand(command);
|
const firsCommandResponse = await this.sendCommand(command);
|
||||||
if (firsCommandResponse.tag !== ResponseTags.Generic) {
|
if (firsCommandResponse.tag !== ResponseTags.Generic) {
|
||||||
|
logger('Invalid write memory response! %o', firsCommandResponse);
|
||||||
return reject(new Error('Invalid write memory response!'));
|
return reject(new Error('Invalid write memory response!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firsCommandResponse.code !== 0) {
|
if (firsCommandResponse.code !== 0) {
|
||||||
|
logger('Non zero write memory response! %o', firsCommandResponse);
|
||||||
return reject(new Error(`Non zero write memory response! Response code: ${firsCommandResponse.code}`));
|
return reject(new Error(`Non zero write memory response! Response code: ${firsCommandResponse.code}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,10 +113,12 @@ export class UsbPeripheral implements Peripheral {
|
|||||||
|
|
||||||
const secondCommandResponse = await this._getNextCommandResponse();
|
const secondCommandResponse = await this._getNextCommandResponse();
|
||||||
if (secondCommandResponse.tag !== ResponseTags.Generic) {
|
if (secondCommandResponse.tag !== ResponseTags.Generic) {
|
||||||
|
logger('Invalid write memory final response %o', secondCommandResponse);
|
||||||
return reject(new Error('Invalid write memory final response!'));
|
return reject(new Error('Invalid write memory final response!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secondCommandResponse.code !== 0) {
|
if (secondCommandResponse.code !== 0) {
|
||||||
|
logger('Non zero write memory final response %o', secondCommandResponse);
|
||||||
const msg = `Non zero write memory final response! Response code: ${secondCommandResponse.code}`;
|
const msg = `Non zero write memory final response! Response code: ${secondCommandResponse.code}`;
|
||||||
return reject(new Error(msg));
|
return reject(new Error(msg));
|
||||||
}
|
}
|
||||||
@@ -142,10 +147,12 @@ export class UsbPeripheral implements Peripheral {
|
|||||||
this._resetResponseBuffer();
|
this._resetResponseBuffer();
|
||||||
const firsCommandResponse = await this.sendCommand(command);
|
const firsCommandResponse = await this.sendCommand(command);
|
||||||
if (firsCommandResponse.tag !== ResponseTags.ReadMemory) {
|
if (firsCommandResponse.tag !== ResponseTags.ReadMemory) {
|
||||||
|
logger('Invalid read memory response %o', firsCommandResponse);
|
||||||
return reject(new Error('Invalid read memory response!'));
|
return reject(new Error('Invalid read memory response!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firsCommandResponse.code !== 0) {
|
if (firsCommandResponse.code !== 0) {
|
||||||
|
logger('Non zero read memory response %o', firsCommandResponse);
|
||||||
return reject(new Error(`Non zero read memory response! Response code: ${firsCommandResponse.code}`));
|
return reject(new Error(`Non zero read memory response! Response code: ${firsCommandResponse.code}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,10 +162,12 @@ export class UsbPeripheral implements Peripheral {
|
|||||||
|
|
||||||
const secondCommandResponse = await this._getNextCommandResponse();
|
const secondCommandResponse = await this._getNextCommandResponse();
|
||||||
if (secondCommandResponse.tag !== ResponseTags.Generic) {
|
if (secondCommandResponse.tag !== ResponseTags.Generic) {
|
||||||
|
logger('Invalid read memory final response %o', secondCommandResponse);
|
||||||
return reject(new Error('Invalid read memory final response!'));
|
return reject(new Error('Invalid read memory final response!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secondCommandResponse.code !== 0) {
|
if (secondCommandResponse.code !== 0) {
|
||||||
|
logger('Non zero read memory final response %o', secondCommandResponse);
|
||||||
const msg = `Non zero read memory final response! Response code: ${secondCommandResponse.code}`;
|
const msg = `Non zero read memory final response! Response code: ${secondCommandResponse.code}`;
|
||||||
return reject(new Error(msg));
|
return reject(new Error(msg));
|
||||||
}
|
}
|
||||||
@@ -243,6 +252,7 @@ export class UsbPeripheral implements Peripheral {
|
|||||||
await snooze(100);
|
await snooze(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger('Timeout while try to read from buffer');
|
||||||
reject(new Error('Timeout while try to read from buffer'));
|
reject(new Error('Timeout while try to read from buffer'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
13
packages/kboot/test/util/usb/decode-command-response.spec.ts
Normal file
13
packages/kboot/test/util/usb/decode-command-response.spec.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { decodeCommandResponse } from '../../../src/util/usb/decode-command-response';
|
||||||
|
|
||||||
|
describe('decodeCommandResponse', () => {
|
||||||
|
it('should parse the command', () => {
|
||||||
|
const arr = '03 00 0c 00 a0 00 00 02 00 00 00 00 c1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
|
||||||
|
.split(' ');
|
||||||
|
const buffer = Buffer.from(arr);
|
||||||
|
const response = decodeCommandResponse(buffer);
|
||||||
|
|
||||||
|
expect(response.code).toEqual(0);
|
||||||
|
expect(response.tag).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user