UNPKG

@twilio/plugin-microvisor

Version:

Interact with your Twilio Microvisor devices

169 lines (168 loc) 8.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseCommand = void 0; const tslib_1 = require("tslib"); exports.BaseCommand = require('@twilio/cli-core').baseCommands.BaseCommand; const core_1 = require("@oclif/core"); const promises_1 = tslib_1.__importDefault(require("node:fs/promises")); const adm_zip_1 = tslib_1.__importDefault(require("adm-zip")); const littlefs_1 = require("../../../lib/factory/littlefs"); const node_process_1 = tslib_1.__importDefault(require("node:process")); class MicrovisorFactoryImage extends exports.BaseCommand { unpackBundle(writer, path, manifestPrefix, layerSuffix) { let zip = new adm_zip_1.default(path); zip.getEntries().forEach((entry) => { if (entry.entryName === 'manifest') { writer.addFile(manifestPrefix + '.manifest', entry.getData()); } else if (entry.entryName.length === 64) { writer.addFile(entry.entryName.slice(0, 32) + '.' + layerSuffix, entry.getData()); } }); } async run() { await super.run(); let writer = new littlefs_1.LittleFsWriter(this.flags['file-system-size']); writer.on('error', (error) => { this.logger.error(error.message); node_process_1.default.exit(1); }); switch (this.flags['purpose']) { case 'factory': { this.logger.info('Building factory provisioning image'); if (typeof this.flags['application'] === 'undefined') { this.logger.error('Application bundle is required for factory image'); node_process_1.default.exit(1); } if (typeof this.flags['application-test'] === 'undefined') { this.logger.error('Test application bundle is required for factory image'); node_process_1.default.exit(1); } if (typeof this.flags['microvisor-test'] === 'undefined') { this.logger.error('Microvisor test bundle is required for factory image'); node_process_1.default.exit(1); } if (typeof this.flags['microvisor'] === 'undefined') { this.logger.error('Microvisor kernel bundle is required for factory image'); node_process_1.default.exit(1); } } break; case 'application': { this.logger.info('Building application sideloading image'); if (typeof this.flags['application'] === 'undefined') { this.logger.error('Application bundle is required for application sideloading image'); node_process_1.default.exit(1); } if (typeof this.flags['application-test'] !== 'undefined') { this.logger.error('Test application bundle does not belong to application sideloading image'); node_process_1.default.exit(1); } if (typeof this.flags['microvisor-test'] !== 'undefined') { this.logger.error('Microvisor test bundle does not belong to application sideloading image'); node_process_1.default.exit(1); } if (typeof this.flags['microvisor'] !== 'undefined') { this.logger.error('Microvisor kernel bundle does not belong to application sideloading image'); node_process_1.default.exit(1); } } break; case 'kernel': { this.logger.info('Building microvisor kernel sideloading image'); if (typeof this.flags['application'] !== 'undefined') { this.logger.error('Application bundle does not belong to microvisor kernel sideloading image'); node_process_1.default.exit(1); } if (typeof this.flags['application-test'] !== 'undefined') { this.logger.error('Test application bundle does not belong to microvisor kernel sideloading image'); node_process_1.default.exit(1); } if (typeof this.flags['microvisor-test'] !== 'undefined') { this.logger.error('Microvisor test bundle does not belong to microvisor kernel sideloading image'); node_process_1.default.exit(1); } if (typeof this.flags['microvisor'] !== 'undefined') { this.logger.error('Microvisor kernel bundle is required for microvisor kernel sideloading image'); node_process_1.default.exit(1); } } break; case 'custom': default: { this.logger.info('Building custom flash image'); if (typeof this.flags['application'] !== 'undefined') { this.logger.info('+ Application bundle is included'); } else { this.logger.info('- Application bundle is NOT included'); } if (typeof this.flags['application-test'] !== 'undefined') { this.logger.info('+ Test application bundle is included'); } else { this.logger.info('- Test application bundle is NOT included'); } if (typeof this.flags['microvisor-test'] !== 'undefined') { this.logger.info('+ Microvisor test bundle is included'); } else { this.logger.info('- Microvisor test bundle is NOT included'); } if (typeof this.flags['microvisor'] !== 'undefined') { this.logger.info('+ Microvisor kernel bundle is included'); } else { this.logger.info('- Microvisor kernel bundle is NOT included'); } } } if (typeof this.flags['application'] !== 'undefined') { this.unpackBundle(writer, this.flags['application'], 'app', 'appl'); } if (typeof this.flags['application-test'] !== 'undefined') { this.unpackBundle(writer, this.flags['application-test'], 'apptest', 'appl'); } if (typeof this.flags['microvisor-test'] !== 'undefined') { this.unpackBundle(writer, this.flags['microvisor-test'], 'hwtest', 'htst'); } if (typeof this.flags['microvisor'] !== 'undefined') { this.unpackBundle(writer, this.flags['microvisor'], 'kernel', 'krnl'); } const fsImageData = writer.encode(); await promises_1.default.writeFile(this.args['out'], fsImageData); } } MicrovisorFactoryImage.description = 'Create SPI flash image for Microvisor factory process'; MicrovisorFactoryImage.args = [ { name: 'out', required: true, description: 'Output file for file system image.' } ]; MicrovisorFactoryImage.flags = Object.assign({ 'purpose': core_1.Flags.string({ options: ['factory', 'application', 'kernel', 'custom'], default: 'factory', description: 'What the image is for: factory process, application sideloading, kernel sideloading or a custom image' }), 'application': core_1.Flags.string({ required: false, description: 'Path to application bundle' }), 'application-test': core_1.Flags.string({ required: false, description: 'Path to test application bundle.' }), 'microvisor-test': core_1.Flags.string({ required: false, description: 'Path to microvisor test bundle.' }), 'microvisor': core_1.Flags.string({ required: false, description: 'Path to microvisor kernel bundle.' }), 'file-system-size': core_1.Flags.integer({ description: 'Size of the file system to create', default: 6 * 1024 * 1024, hidden: true }) }, exports.BaseCommand.flags); module.exports = MicrovisorFactoryImage;