Skip to content

Commit

Permalink
Use module address from file header for system firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle committed Nov 22, 2016
1 parent 362c6a0 commit ad2b259
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions commands/FlashCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ var utilities = require('../lib/utilities.js');
var ModuleParser = require('binary-version-reader').HalModuleParser;
var deviceSpecs = require('../lib/deviceSpecs');

var MONOLITHIC = 3;
var SYSTEM_MODULE = 4;
var APPLICATION_MODULE = 5;

var FlashCommand = function (cli, options) {
FlashCommand.super_.call(this, cli, options);
this.options = extend({}, this.options, options);
Expand Down Expand Up @@ -150,7 +154,7 @@ FlashCommand.prototype = extend(BaseCommand.prototype, {
var useFactory = this.options.useFactoryAddress;

var self = this;
var specs, destSegment;
var specs, destSegment, destAddress;
var flashingKnownApp = false;
var ready = sequence([
function() {
Expand Down Expand Up @@ -207,15 +211,14 @@ FlashCommand.prototype = extend(BaseCommand.prototype, {
}

switch (info.prefixInfo.moduleFunction) {
case 3:
// monolithic
case MONOLITHIC:
// only override if modular capable
destSegment = specs.systemFirmwareOne ? 'systemFirmwareOne' : destSegment;
break;
case 4:
destSegment = self.systemModuleIndexToString[info.prefixInfo.moduleIndex];
case SYSTEM_MODULE:
destAddress = '0x0' + info.prefixInfo.moduleStartAddy;
break;
case 5:
case APPLICATION_MODULE:
// use existing destSegment for userFirmware/factoryReset
break;
default:
Expand All @@ -229,10 +232,19 @@ FlashCommand.prototype = extend(BaseCommand.prototype, {
});
},
function() {
if (!destSegment) {
if (!destAddress && destSegment) {
var segment = dfu._validateSegmentSpecs(destSegment);
if (segment.error) {
return when.reject('dfu.write: ' + segment.error);
}
destAddress = segment.specs.address;
}
if (!destAddress) {
return when.reject('Unknown destination');
}
return dfu.write(firmware, destSegment, destSegment === 'userFirmware');
var alt = 0;
var leave = destSegment === 'userFirmware';
return dfu.writeDfu(alt, firmware, destAddress, leave);
}
]);

Expand All @@ -242,12 +254,6 @@ FlashCommand.prototype = extend(BaseCommand.prototype, {
console.error('\nError writing firmware...' + err + '\n');
return when.reject();
});
},

systemModuleIndexToString: {
1: 'systemFirmwareOne',
2: 'systemFirmwareTwo',
3: 'systemFirmwareThree'
}
});

Expand Down

0 comments on commit ad2b259

Please sign in to comment.