Make the firmware updater scripts take module slot parameters instead of I2C addresses. Rename scripts from *slave* to *module*.

This commit is contained in:
László Monda
2017-11-08 18:27:45 +01:00
parent 9a5862b57c
commit 04b43896c5
8 changed files with 98 additions and 65 deletions

View 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());

View File

@@ -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());

View 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());

View File

@@ -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());

View File

@@ -35,7 +35,7 @@ function getBlhostCmd(pid) {
break;
}
return `${__dirname}/blhost/${blhostPath} --usb 0x1d50,${pid}`;
return `${__dirname}/blhost/${blhostPath} --usb 0x1d50,0x${pid.toString(16)}`;
}
function execRetry(command) {

View File

@@ -49,6 +49,7 @@ exports = module.exports = moduleExports = {
getUhkDevice,
getBootloaderDevice,
getTransferData,
checkModuleSlot,
usbCommands: {
getProperty: 0,
reenumerate: 1,
@@ -63,7 +64,7 @@ exports = module.exports = moduleExports = {
readUserConfig: 15,
getKeyboardState: 16,
readDebugInfo: 17,
jumpToSlaveBootloader: 18,
jumpToModuleBootloader: 18,
sendKbootCommand: 19,
},
enumerationModes: {
@@ -78,6 +79,12 @@ exports = module.exports = moduleExports = {
'2': 0x6122,
'3': 0x6123,
},
enumerationNameToProductId: {
bootloader: 0x6120,
buspal: 0x6121,
normalKeyboard: 0x6122,
compatibleKeyboard: 0x6123,
},
vendorId: 0x1D50,
systemPropertyIds: {
usbProtocolVersion: 0,
@@ -99,9 +106,14 @@ exports = module.exports = moduleExports = {
reset: 2,
},
moduleSlotToI2cAddress: {
leftHalf: 0x10,
leftAddon: 0x20,
rightAddon: 0x30,
leftHalf: '0x10',
leftAddon: '0x20',
rightAddon: '0x30',
},
moduleSlotToId: {
leftHalf: 1,
leftAddon: 2,
rightAddon: 3,
},
leftLedDriverAddress: 0b1110100,
rightLedDriverAddress: 0b1110111,
@@ -144,3 +156,20 @@ function writeLog(prefix, 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;
}

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env node
const uhk = require('./uhk');
const program = require('commander');
require('shelljs/global');
require('./shared')
@@ -7,12 +8,12 @@ const extension = '.hex';
config.fatal = true;
program
.usage(`update-master-firmware <firmware-image${extension}>`)
.usage(`firmwareImage${extension}`)
.parse(process.argv)
const firmwareImage = program.args[0];
const usbDir = `${__dirname}`;
const blhost = getBlhostCmd(0x6120);
const blhost = getBlhostCmd(uhk.enumerationNameToProductId.bootloader);
checkFirmwareImage(firmwareImage, extension);
@@ -24,4 +25,4 @@ exec(`${blhost} flash-image ${firmwareImage}`);
exec(`${blhost} reset`);
config.verbose = false;
echo('Firmware updated successfully');
echo('Firmware updated successfully.');

View File

@@ -2,43 +2,36 @@
const uhk = require('./uhk');
const program = require('commander');
require('shelljs/global');
require('./shared')
require('./shared');
const extension = '.bin';
config.fatal = true;
program
.usage(`update-slave-firmware <module-slot> <firmware-image${extension}>`)
.usage(`moduleSlot firmwareImage${extension}`)
.parse(process.argv)
let moduleSlot = program.args[0];
let i2cAddress = uhk.moduleSlotToI2cAddress[moduleSlot];
if (!i2cAddress) {
echo(`Invalid module slot specified.`);
echo(`Valid slots are: ${Object.keys(uhk.moduleSlotToI2cAddress).join(', ')}.`);
exit(1);
}
i2cAddress = `0x${i2cAddress.toString(16)}`;
const i2cAddress = uhk.checkModuleSlot(moduleSlot, uhk.moduleSlotToI2cAddress);
const firmwareImage = program.args[1];
checkFirmwareImage(firmwareImage, extension);
const usbDir = `${__dirname}`;
const blhostUsb = getBlhostCmd(0x6121);
const blhostUsb = getBlhostCmd(uhk.enumerationNameToProductId.buspal);
const blhostBuspal = `${blhostUsb} --buspal i2c,${i2cAddress},100k`;
config.verbose = true;
exec(`${usbDir}/send-kboot-command-to-slave.js ping ${i2cAddress}`);
exec(`${usbDir}/jump-to-slave-bootloader.js`);
exec(`${usbDir}/send-kboot-command-to-module.js ping ${moduleSlot}`);
exec(`${usbDir}/jump-to-module-bootloader.js ${moduleSlot}`);
exec(`${usbDir}/reenumerate.js buspal`);
execRetry(`${blhostBuspal} get-property 1`);
exec(`${blhostBuspal} flash-erase-all-unsecure`);
exec(`${blhostBuspal} write-memory 0x0 ${firmwareImage}`);
exec(`${blhostUsb} reset`);
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;
echo('Firmware updated successfully.');