Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds support for radio stack modules (e.g. SoftDevice on Gen 3) #24

Merged
merged 5 commits into from Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 2 additions & 10 deletions lib/FirmwareModule.js
@@ -1,5 +1,6 @@
'use strict';
var extend = require('xtend');
const ModuleInfo = require('./ModuleInfo.js');

/**
* Extracts the short names from a module descriptor and turns them into more readable names.
Expand Down Expand Up @@ -32,16 +33,7 @@ var FirmwareModule = function FirmwareModule(describeMessage) {
};

FirmwareModule.prototype = extend(FirmwareModule.prototype, {
moduleFunctions: [
'n',
'r',
'b',
'm',
's',
'u',
'_', // unused
'c'
],
moduleFunctions: ModuleInfo.FunctionToChar,

isValid: function() {
return this.validityValues === this.validityCheck;
Expand Down
10 changes: 8 additions & 2 deletions lib/HalModuleParser.js
Expand Up @@ -270,6 +270,7 @@ HalModuleParser.prototype = {
* {
* moduleStartAddy: string,
* moduleEndAddy: string,
* moduleFlags: number,
* moduleVersion: number,
* platformID: number,
* moduleFunction: number,
Expand All @@ -279,7 +280,7 @@ HalModuleParser.prototype = {
* depModuleVersion: number
* }
* @param fileBuffer
* @returns {{moduleStartAddy: string, moduleEndAddy: string, moduleVersion: number, platformID: number, moduleFunction: number, moduleIndex: number, depModuleFunction: number, depModuleIndex: number, depModuleVersion: number}}
* @returns {{moduleStartAddy: string, moduleEndAddy: string, moduleFlags: number, moduleVersion: number, platformID: number, moduleFunction: number, moduleIndex: number, depModuleFunction: number, depModuleIndex: number, depModuleVersion: number}}
* @private
*/
_readPrefix: function(fileBuffer) {
Expand All @@ -300,7 +301,11 @@ HalModuleParser.prototype = {
//offset 4, 4-bytes: module end address
var moduleEndAddy = r.shiftUInt32(isLittleEndian).toString(16);

r.skip(2);
// reserved (MCU target on Gen 3)
r.skip(1);

// offset 9, 1-byte: module flags (module_info_flags_t)
var moduleFlags = r.shiftUInt8();

// offset 10, 2-bytes: module version (this is not the same as
// product version, it relates to the module export functions)
Expand Down Expand Up @@ -339,6 +344,7 @@ HalModuleParser.prototype = {
return {
moduleStartAddy: moduleStartAddy,
moduleEndAddy: moduleEndAddy,
moduleFlags: moduleFlags,
moduleVersion: moduleVersion,
platformID: platformID,
moduleFunction: moduleFunction,
Expand Down
91 changes: 91 additions & 0 deletions lib/ModuleInfo.js
@@ -0,0 +1,91 @@
/*
* Copyright 2019 Particle ( https://particle.io )
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const ModuleFunction = {
NONE: 0,
RESOURCE: 1,
BOOTLOADER: 2,
MONO_FIRMWARE: 3,
SYSTEM_PART: 4,
USER_PART: 5,
SETTINGS: 6,
NCP_FIRMWARE: 7,
RADIO_STACK: 8
};

const ModuleFunctionChar = {
NONE: 'n',
RESOURCE: 'r',
BOOTLOADER: 'b',
MONO_FIRMWARE: 'm',
SYSTEM_PART: 's',
USER_PART: 'u',
SETTINGS: '_', // unused
NCP_FIRMWARE: 'c',
RADIO_STACK: 'a'
};

const ModuleFunctionToChar = [
ModuleFunctionChar.NONE,
ModuleFunctionChar.RESOURCE,
ModuleFunctionChar.BOOTLOADER,
ModuleFunctionChar.MONO_FIRMWARE,
ModuleFunctionChar.SYSTEM_PART,
ModuleFunctionChar.USER_PART,
ModuleFunctionChar.SETTINGS,
ModuleFunctionChar.NCP_FIRMWARE,
ModuleFunctionChar.RADIO_STACK
];

const ModuleInfoFlags = {
NONE: 0x0,
DROP_MODULE_INFO: 0x01,
};

const ModuleValidationFlags = {
PASSED: 0,
INTEGRITY: (1 << 1),
DEPENDENCIES: (1 << 2),
RANGE: (1 << 3),
PLATFORM: (1 << 4),
PRODUCT: (1 << 5),
DEPENDENCIES_FULL: (1 << 6)
};

const ModuleInfoPlatform = {
CORE: 0,
PHOTON: 6,
P1: 8,
ELECTRON: 10,
ARGON: 12,
BORON: 13,
XENON: 14,
ASOM: 22,
BSOM: 23,
XSOM: 24
};

const HEADER_SIZE = 24;

module.exports = {
FunctionType: ModuleFunction,
FunctionChar: ModuleFunction,
Flags: ModuleInfoFlags,
FunctionToChar: ModuleFunctionToChar,
ValidationFlags: ModuleValidationFlags,
Platform: ModuleInfoPlatform,
HEADER_SIZE: HEADER_SIZE
};
3 changes: 2 additions & 1 deletion main.js
Expand Up @@ -22,5 +22,6 @@ module.exports = {
HalModuleParser: require('./lib/HalModuleParser.js'),
HalDescribeParser: require('./lib/HalDescribeParser.js'),
HalDependencyResolver: require('./lib/HalDependencyResolver.js'),
FirmwareModule: require('./lib/FirmwareModule.js')
FirmwareModule: require('./lib/FirmwareModule.js'),
ModuleInfo: require('./lib/ModuleInfo.js')
};
Binary file added specs/binaries/argon-softdevice-6.1.1.bin
Binary file not shown.
45 changes: 45 additions & 0 deletions specs/lib/HalModuleParser.spec.js
Expand Up @@ -26,6 +26,7 @@ var buffers = require('h5.buffers');
var BufferOffset = require('buffer-offset');

var HalModuleParser = require('../../lib/HalModuleParser.js');
const ModuleInfo = require('../../lib/ModuleInfo.js');

var settings = {
binaries: path.resolve(path.join(__dirname, '../binaries'))
Expand Down Expand Up @@ -87,6 +88,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: '8020000',
moduleEndAddy: '805cba4',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 1,
platformID: 6,
moduleFunction: 4,
Expand Down Expand Up @@ -120,6 +122,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: '8060000',
moduleEndAddy: '807e954',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 1,
platformID: 6,
moduleFunction: 4,
Expand Down Expand Up @@ -153,6 +156,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: '80a0000',
moduleEndAddy: '80a128c',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 2,
platformID: 6,
moduleFunction: 5,
Expand Down Expand Up @@ -186,6 +190,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: '8005000',
moduleEndAddy: '801a8e0',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 0,
platformID: 0,
moduleFunction: 3,
Expand Down Expand Up @@ -303,6 +308,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: '8000000',
moduleEndAddy: '8003f98',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 2,
platformID: 6,
moduleFunction: 2,
Expand Down Expand Up @@ -359,6 +365,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: '18000',
moduleEndAddy: '36768',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 1,
platformID: 103,
moduleFunction: 4,
Expand Down Expand Up @@ -392,6 +399,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: '30000',
moduleEndAddy: 'c7580',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 312,
platformID: 14,
moduleFunction: 4,
Expand Down Expand Up @@ -424,6 +432,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: 'd4000',
moduleEndAddy: 'd4cec',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 5,
platformID: 14,
moduleFunction: 5,
Expand Down Expand Up @@ -456,6 +465,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: 'f4000',
moduleEndAddy: 'fc164',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 211,
platformID: 14,
moduleFunction: 2,
Expand Down Expand Up @@ -488,6 +498,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: '0',
moduleEndAddy: 'ca73c',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 5,
platformID: 12,
moduleFunction: 7,
Expand Down Expand Up @@ -520,6 +531,7 @@ describe('HalModuleParser', function () {
var expectedPrefixInfo = {
moduleStartAddy: '30000',
moduleEndAddy: 'ce668',
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 1100,
platformID: 23,
moduleFunction: 4,
Expand Down Expand Up @@ -547,6 +559,38 @@ describe('HalModuleParser', function () {
}).catch(done);
});

it('should work with argon softdevice (radio stack)', function (done) {
var filename = path.join(settings.binaries, 'argon-softdevice-6.1.1.bin');
var expectedPrefixInfo = {
moduleStartAddy: '1000',
moduleEndAddy: '25e24',
moduleFlags: ModuleInfo.Flags.DROP_MODULE_INFO,
moduleVersion: 182,
platformID: ModuleInfo.Platform.ARGON,
moduleFunction: ModuleInfo.FunctionType.RADIO_STACK,
moduleIndex: 0,
depModuleFunction: ModuleInfo.FunctionType.SYSTEM_PART,
depModuleIndex: 1,
depModuleVersion: 1300,
dep2ModuleFunction: ModuleInfo.FunctionType.BOOTLOADER,
dep2ModuleIndex: 0,
dep2ModuleVersion: 311
};

var parser = new HalModuleParser();
parser.parseFile(filename)
.then(
function (fileInfo) {
should(fileInfo).be.ok;
should(fileInfo.crc.ok).be.ok;
should(fileInfo.prefixInfo).eql(expectedPrefixInfo);

done();
},
function (err) {
done(err)
}).catch(done);
});

describe('given a module descriptor', function () {
function buildModule(module) {
Expand Down Expand Up @@ -579,6 +623,7 @@ describe('HalModuleParser', function () {
var testModule1 = {
moduleStartAddy: 0x12345678,
moduleEndAddy: 0x87654321,
moduleFlags: ModuleInfo.Flags.NONE,
moduleVersion: 1234,
platformID: 4567,
moduleFunction: 147,
Expand Down