Make the firmware updater scripts take module slot parameters instead of I2C addresses. Rename scripts from *slave* to *module*.
This commit is contained in:
14
packages/usb/jump-to-module-bootloader.js
Executable file
14
packages/usb/jump-to-module-bootloader.js
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const uhk = require('./uhk');
|
||||||
|
const program = require('commander');
|
||||||
|
|
||||||
|
program
|
||||||
|
.usage(`moduleSlot`)
|
||||||
|
.parse(process.argv)
|
||||||
|
|
||||||
|
const moduleSlot = program.args[0];
|
||||||
|
const moduleSlotId = uhk.checkModuleSlot(moduleSlot, uhk.moduleSlotToId);
|
||||||
|
const device = uhk.getUhkDevice();
|
||||||
|
let transfer = new Buffer([uhk.usbCommands.jumpToModuleBootloader, moduleSlotId]);
|
||||||
|
device.write(uhk.getTransferData(transfer));
|
||||||
|
const response = Buffer.from(device.readSync());
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
const uhk = require('./uhk');
|
|
||||||
|
|
||||||
const device = uhk.getUhkDevice();
|
|
||||||
let transfer = new Buffer([uhk.usbCommands.jumpToSlaveBootloader, 1]);
|
|
||||||
device.write(uhk.getTransferData(transfer));
|
|
||||||
const response = Buffer.from(device.readSync());
|
|
||||||
38
packages/usb/send-kboot-command-to-module.js
Executable file
38
packages/usb/send-kboot-command-to-module.js
Executable file
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const uhk = require('./uhk');
|
||||||
|
const program = require('commander');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
program
|
||||||
|
.usage(`command [moduleSlot]
|
||||||
|
|
||||||
|
command: ${Object.keys(uhk.kbootCommands).join(' | ')}
|
||||||
|
moduleSlot: ${Object.keys(uhk.moduleSlotToI2cAddress).join(' | ')}
|
||||||
|
moduleSlot is always required, except for the idle command.`)
|
||||||
|
.parse(process.argv)
|
||||||
|
|
||||||
|
const kbootCommand = program.args[0];
|
||||||
|
if (!kbootCommand) {
|
||||||
|
console.log(`No command provided.`);
|
||||||
|
console.log(`Valid commands: ${Object.keys(uhk.kbootCommands).join(', ')}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const kbootCommandId = uhk.kbootCommands[kbootCommand];
|
||||||
|
if (kbootCommandId === undefined) {
|
||||||
|
console.log(`Invalid command "${kbootCommand}" provided.`);
|
||||||
|
console.log(`Valid commands: ${Object.keys(uhk.kbootCommands).join(', ')}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const moduleSlot = program.args[1];
|
||||||
|
|
||||||
|
let i2cAddress;
|
||||||
|
if (kbootCommand !== 'idle') {
|
||||||
|
i2cAddress = uhk.checkModuleSlot(moduleSlot, uhk.moduleSlotToI2cAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
const device = uhk.getUhkDevice();
|
||||||
|
let transfer = new Buffer([uhk.usbCommands.sendKbootCommand, kbootCommandId, parseInt(i2cAddress)]);
|
||||||
|
device.write(uhk.getTransferData(transfer));
|
||||||
|
const response = Buffer.from(device.readSync());
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
const uhk = require('./uhk');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
function printUsage() {
|
|
||||||
const scriptFilename = path.basename(process.argv[1]);
|
|
||||||
const commands = Object.keys(uhk.kbootCommands).join(' | ');
|
|
||||||
console.log(
|
|
||||||
`Usage: ${scriptFilename} command i2cAddress
|
|
||||||
command: ${commands}
|
|
||||||
i2cAddress is not needed for the idle command`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const kbootCommand = process.argv[2];
|
|
||||||
if (!kbootCommand) {
|
|
||||||
console.log(`No command provided`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const kbootCommandId = uhk.kbootCommands[kbootCommand];
|
|
||||||
if (!kbootCommandId) {
|
|
||||||
console.log(`Invalid command provided`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const i2cAddress = process.argv[3];
|
|
||||||
if (kbootCommand !== 'idle' && !i2cAddress) {
|
|
||||||
console.log(`No i2cAddress provided`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const device = uhk.getUhkDevice();
|
|
||||||
let transfer = new Buffer([uhk.usbCommands.sendKbootCommand, kbootCommandId, parseInt(i2cAddress)]);
|
|
||||||
device.write(uhk.getTransferData(transfer));
|
|
||||||
const response = Buffer.from(device.readSync());
|
|
||||||
@@ -35,7 +35,7 @@ function getBlhostCmd(pid) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${__dirname}/blhost/${blhostPath} --usb 0x1d50,${pid}`;
|
return `${__dirname}/blhost/${blhostPath} --usb 0x1d50,0x${pid.toString(16)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function execRetry(command) {
|
function execRetry(command) {
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ exports = module.exports = moduleExports = {
|
|||||||
getUhkDevice,
|
getUhkDevice,
|
||||||
getBootloaderDevice,
|
getBootloaderDevice,
|
||||||
getTransferData,
|
getTransferData,
|
||||||
|
checkModuleSlot,
|
||||||
usbCommands: {
|
usbCommands: {
|
||||||
getProperty: 0,
|
getProperty: 0,
|
||||||
reenumerate: 1,
|
reenumerate: 1,
|
||||||
@@ -63,7 +64,7 @@ exports = module.exports = moduleExports = {
|
|||||||
readUserConfig: 15,
|
readUserConfig: 15,
|
||||||
getKeyboardState: 16,
|
getKeyboardState: 16,
|
||||||
readDebugInfo: 17,
|
readDebugInfo: 17,
|
||||||
jumpToSlaveBootloader: 18,
|
jumpToModuleBootloader: 18,
|
||||||
sendKbootCommand: 19,
|
sendKbootCommand: 19,
|
||||||
},
|
},
|
||||||
enumerationModes: {
|
enumerationModes: {
|
||||||
@@ -78,6 +79,12 @@ exports = module.exports = moduleExports = {
|
|||||||
'2': 0x6122,
|
'2': 0x6122,
|
||||||
'3': 0x6123,
|
'3': 0x6123,
|
||||||
},
|
},
|
||||||
|
enumerationNameToProductId: {
|
||||||
|
bootloader: 0x6120,
|
||||||
|
buspal: 0x6121,
|
||||||
|
normalKeyboard: 0x6122,
|
||||||
|
compatibleKeyboard: 0x6123,
|
||||||
|
},
|
||||||
vendorId: 0x1D50,
|
vendorId: 0x1D50,
|
||||||
systemPropertyIds: {
|
systemPropertyIds: {
|
||||||
usbProtocolVersion: 0,
|
usbProtocolVersion: 0,
|
||||||
@@ -99,9 +106,14 @@ exports = module.exports = moduleExports = {
|
|||||||
reset: 2,
|
reset: 2,
|
||||||
},
|
},
|
||||||
moduleSlotToI2cAddress: {
|
moduleSlotToI2cAddress: {
|
||||||
leftHalf: 0x10,
|
leftHalf: '0x10',
|
||||||
leftAddon: 0x20,
|
leftAddon: '0x20',
|
||||||
rightAddon: 0x30,
|
rightAddon: '0x30',
|
||||||
|
},
|
||||||
|
moduleSlotToId: {
|
||||||
|
leftHalf: 1,
|
||||||
|
leftAddon: 2,
|
||||||
|
rightAddon: 3,
|
||||||
},
|
},
|
||||||
leftLedDriverAddress: 0b1110100,
|
leftLedDriverAddress: 0b1110100,
|
||||||
rightLedDriverAddress: 0b1110111,
|
rightLedDriverAddress: 0b1110111,
|
||||||
@@ -144,3 +156,20 @@ function writeLog(prefix, buffer) {
|
|||||||
}
|
}
|
||||||
console.log(prefix + bufferToString(buffer))
|
console.log(prefix + bufferToString(buffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkModuleSlot(moduleSlot, mapping) {
|
||||||
|
const mapped = mapping[moduleSlot];
|
||||||
|
|
||||||
|
if (moduleSlot == undefined) {
|
||||||
|
console.log(`No moduleSlot specified.`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapped == undefined) {
|
||||||
|
console.log(`Invalid moduleSlot "${moduleSlot}" specified.`);
|
||||||
|
console.log(`Valid module slots are: ${Object.keys(mapping).join(', ')}.`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapped;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
const uhk = require('./uhk');
|
||||||
const program = require('commander');
|
const program = require('commander');
|
||||||
require('shelljs/global');
|
require('shelljs/global');
|
||||||
require('./shared')
|
require('./shared')
|
||||||
@@ -7,12 +8,12 @@ const extension = '.hex';
|
|||||||
config.fatal = true;
|
config.fatal = true;
|
||||||
|
|
||||||
program
|
program
|
||||||
.usage(`update-master-firmware <firmware-image${extension}>`)
|
.usage(`firmwareImage${extension}`)
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
|
||||||
const firmwareImage = program.args[0];
|
const firmwareImage = program.args[0];
|
||||||
const usbDir = `${__dirname}`;
|
const usbDir = `${__dirname}`;
|
||||||
const blhost = getBlhostCmd(0x6120);
|
const blhost = getBlhostCmd(uhk.enumerationNameToProductId.bootloader);
|
||||||
|
|
||||||
checkFirmwareImage(firmwareImage, extension);
|
checkFirmwareImage(firmwareImage, extension);
|
||||||
|
|
||||||
@@ -24,4 +25,4 @@ exec(`${blhost} flash-image ${firmwareImage}`);
|
|||||||
exec(`${blhost} reset`);
|
exec(`${blhost} reset`);
|
||||||
config.verbose = false;
|
config.verbose = false;
|
||||||
|
|
||||||
echo('Firmware updated successfully');
|
echo('Firmware updated successfully.');
|
||||||
@@ -2,43 +2,36 @@
|
|||||||
const uhk = require('./uhk');
|
const uhk = require('./uhk');
|
||||||
const program = require('commander');
|
const program = require('commander');
|
||||||
require('shelljs/global');
|
require('shelljs/global');
|
||||||
require('./shared')
|
require('./shared');
|
||||||
|
|
||||||
const extension = '.bin';
|
const extension = '.bin';
|
||||||
config.fatal = true;
|
config.fatal = true;
|
||||||
|
|
||||||
program
|
program
|
||||||
.usage(`update-slave-firmware <module-slot> <firmware-image${extension}>`)
|
.usage(`moduleSlot firmwareImage${extension}`)
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
|
||||||
let moduleSlot = program.args[0];
|
let moduleSlot = program.args[0];
|
||||||
let i2cAddress = uhk.moduleSlotToI2cAddress[moduleSlot];
|
const i2cAddress = uhk.checkModuleSlot(moduleSlot, uhk.moduleSlotToI2cAddress);
|
||||||
|
|
||||||
if (!i2cAddress) {
|
|
||||||
echo(`Invalid module slot specified.`);
|
|
||||||
echo(`Valid slots are: ${Object.keys(uhk.moduleSlotToI2cAddress).join(', ')}.`);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
i2cAddress = `0x${i2cAddress.toString(16)}`;
|
|
||||||
|
|
||||||
const firmwareImage = program.args[1];
|
const firmwareImage = program.args[1];
|
||||||
checkFirmwareImage(firmwareImage, extension);
|
checkFirmwareImage(firmwareImage, extension);
|
||||||
|
|
||||||
const usbDir = `${__dirname}`;
|
const usbDir = `${__dirname}`;
|
||||||
const blhostUsb = getBlhostCmd(0x6121);
|
const blhostUsb = getBlhostCmd(uhk.enumerationNameToProductId.buspal);
|
||||||
const blhostBuspal = `${blhostUsb} --buspal i2c,${i2cAddress},100k`;
|
const blhostBuspal = `${blhostUsb} --buspal i2c,${i2cAddress},100k`;
|
||||||
|
|
||||||
config.verbose = true;
|
config.verbose = true;
|
||||||
exec(`${usbDir}/send-kboot-command-to-slave.js ping ${i2cAddress}`);
|
exec(`${usbDir}/send-kboot-command-to-module.js ping ${moduleSlot}`);
|
||||||
exec(`${usbDir}/jump-to-slave-bootloader.js`);
|
exec(`${usbDir}/jump-to-module-bootloader.js ${moduleSlot}`);
|
||||||
exec(`${usbDir}/reenumerate.js buspal`);
|
exec(`${usbDir}/reenumerate.js buspal`);
|
||||||
execRetry(`${blhostBuspal} get-property 1`);
|
execRetry(`${blhostBuspal} get-property 1`);
|
||||||
exec(`${blhostBuspal} flash-erase-all-unsecure`);
|
exec(`${blhostBuspal} flash-erase-all-unsecure`);
|
||||||
exec(`${blhostBuspal} write-memory 0x0 ${firmwareImage}`);
|
exec(`${blhostBuspal} write-memory 0x0 ${firmwareImage}`);
|
||||||
exec(`${blhostUsb} reset`);
|
exec(`${blhostUsb} reset`);
|
||||||
exec(`${usbDir}/reenumerate.js normalKeyboard`);
|
exec(`${usbDir}/reenumerate.js normalKeyboard`);
|
||||||
execRetry(`${usbDir}/send-kboot-command-to-slave.js reset ${i2cAddress}`);
|
execRetry(`${usbDir}/send-kboot-command-to-module.js reset ${moduleSlot}`);
|
||||||
|
exec(`${usbDir}/send-kboot-command-to-module.js idle`);
|
||||||
config.verbose = false;
|
config.verbose = false;
|
||||||
|
|
||||||
echo('Firmware updated successfully.');
|
echo('Firmware updated successfully.');
|
||||||
Reference in New Issue
Block a user