Skip to content

Commit

Permalink
Fix structure of the module info
Browse files Browse the repository at this point in the history
  • Loading branch information
monkbroc committed Jun 27, 2024
1 parent a4b0100 commit b48ae06
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/lib/flash-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,11 @@ async function validateModulesForProtection({ modules, device }) {
}

for (const module of modules) {
const oldSystem = module.moduleFunction === ModuleInfo.FunctionType.SYSTEM_PART &&
module.moduleVersion < PROTECTED_MINIMUM_SYSTEM_VERSION;
const oldBootloader = module.moduleFunction === ModuleInfo.FunctionType.BOOTLOADER &&
module.moduleIndex === 0 && module.moduleVersion < PROTECTED_MINIMUM_BOOTLOADER_VERSION;
const { moduleFunction, moduleIndex, moduleVersion } = module.prefixInfo;
const oldSystem = moduleFunction === ModuleInfo.FunctionType.SYSTEM_PART &&
moduleVersion < PROTECTED_MINIMUM_SYSTEM_VERSION;
const oldBootloader = moduleFunction === ModuleInfo.FunctionType.BOOTLOADER &&
moduleIndex === 0 && moduleVersion < PROTECTED_MINIMUM_BOOTLOADER_VERSION;

if (oldSystem || oldBootloader) {
throw new Error(`Cannot downgrade Device OS below version ${PROTECTED_MINIMUM_VERSION} on a Protected Device`);
Expand Down
40 changes: 24 additions & 16 deletions src/lib/flash-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,27 +664,35 @@ describe('flash-helper', () => {
describe('validateModulesForProtection', () => {
let device;
const modulesOldBootloader = [{
moduleFunction: ModuleInfo.FunctionType.BOOTLOADER,
platformId: 12,
moduleIndex: 0,
moduleVersion: 1200,
prefixInfo: {
moduleFunction: ModuleInfo.FunctionType.BOOTLOADER,
platformId: 12,
moduleIndex: 0,
moduleVersion: 1200
}
}];
const modulesOldSystem = [{
moduleFunction: ModuleInfo.FunctionType.SYSTEM_PART,
platformId: 12,
moduleIndex: 0,
moduleVersion: 5800,
prefixInfo: {
moduleFunction: ModuleInfo.FunctionType.SYSTEM_PART,
platformId: 12,
moduleIndex: 0,
moduleVersion: 5800
}
}];
const modulesNew = [{
moduleFunction: ModuleInfo.FunctionType.BOOTLOADER,
platformId: 12,
moduleIndex: 0,
moduleVersion: 3000,
prefixInfo: {
moduleFunction: ModuleInfo.FunctionType.BOOTLOADER,
platformId: 12,
moduleIndex: 0,
moduleVersion: 3000
}
}, {
moduleFunction: ModuleInfo.FunctionType.SYSTEM_PART,
platformId: 12,
moduleIndex: 0,
moduleVersion: 6000,
prefixInfo: {
moduleFunction: ModuleInfo.FunctionType.SYSTEM_PART,
platformId: 12,
moduleIndex: 0,
moduleVersion: 6000
}
}];

beforeEach(() => {
Expand Down

0 comments on commit b48ae06

Please sign in to comment.