inspectBinary: function inspectBinary(binaryFile) { if (!binaryFile || !fs.existsSync(binaryFile)) { console.error('Please specify a binary file'); return when.reject(); } var dfd = when.defer(); var parser = new Parser(); parser.parseFile(binaryFile, function parsed(fileInfo, err) { if (err) { console.error(err); return dfd.reject(); } if (fileInfo.suffixInfo.suffixSize === 65535) { console.error(binaryFile + ' does not contain inspection information'); return dfd.reject(); } console.log(chalk.bold(path.basename(binaryFile))); this._showCrc(fileInfo); this._showPlatform(fileInfo); this._showModuleInfo(fileInfo); dfd.resolve(); }.bind(this)); return dfd.promise; },
return when.promise(function(resolve, reject) { var parser = new ModuleParser(); parser.parseFile(firmware, function(info, err) { if (err) { return reject(err); } if (info.suffixInfo.suffixSize === 65535) { console.log('warn: unable to verify binary info'); return resolve(); } if (!info.crc.ok && !self.options.force) { return reject('CRC is invalid, use --force to override'); } specs = deviceSpecs[dfu.deviceID]; if (info.prefixInfo.platformID !== specs.productId && !self.options.force) { return reject(util.format('Incorrect platform id (expected %d, parsed %d), use --force to override', specs.productId, info.prefixInfo.platformID)); } switch (info.prefixInfo.moduleFunction) { case 3: // monolithic // only override if modular capable destSegment = specs.systemFirmwareOne ? 'systemFirmwareOne' : destSegment; break; case 4: destSegment = info.prefixInfo.moduleIndex === 1 ? 'systemFirmwareOne' : 'systemFirmwareTwo'; break; case 5: // use existing destSegment for userFirmware/factoryReset break; default: if (!self.options.force) { return reject('unknown module function ' + info.prefixInfo.moduleFunction + ', use --force to override'); } break; } resolve(); }); });
it('has a valid crc ', function() { var dfd = when.defer(); var parser = new Parser(); parser.parseFile(updateFile, function parsed(fileInfo, err) { if (err) { return dfd.reject(err); } if (fileInfo.suffixInfo.suffixSize === 65535) { return dfd.reject(binaryFile + ' does not contain inspection information'); } if (!fileInfo.crc.ok) { dfd.reject('CRC failed (should be ' + (fileInfo.crc.storedCrc) + ' but is ' + (fileInfo.crc.actualCrc) + ')'); } dfd.resolve(); }.bind(this)); return dfd.promise; });