UNPKG

flashmagic.js

Version:
68 lines (67 loc) 2.67 kB
"use strict"; var Symbol = require('es6-symbol'); var Utilities = require('./Utilities'); var ROMBlock_1 = require('./ROMBlock'); var _blockSym = Symbol(); var ROMWriter = (function () { function ROMWriter(isp, addr, size) { this.isp = isp; if ((addr !== void 0) && size) { this[_blockSym] = ROMBlock_1.ROMBlock.fromAddress(addr, size); } } Object.defineProperty(ROMWriter.prototype, "block", { get: function () { return this[_blockSym]; }, set: function (block) { this[_blockSym] = block; }, enumerable: true, configurable: true }); Object.defineProperty(ROMWriter.prototype, "address", { get: function () { return this.block.address; }, enumerable: true, configurable: true }); Object.defineProperty(ROMWriter.prototype, "sector", { get: function () { return this.block.sector; }, enumerable: true, configurable: true }); Object.defineProperty(ROMWriter.prototype, "length", { get: function () { return this.block.length; }, enumerable: true, configurable: true }); ROMWriter.prototype.eraseBlock = function () { var _this = this; var endSect = Utilities.addressToSector(this.address + this.length - 1); return this.isp.unlock() .then(function () { return _this.isp.sendCommand("P " + _this.sector + " " + endSect); }) .then(function () { return _this.isp.sendCommand("E " + _this.sector + " " + endSect); }) .then(function () { return _this; }); }; ROMWriter.prototype.copyRAMToFlash = function (srcAddr, count) { var _this = this; var endSect = Utilities.addressToSector(this.address + count - 1); return this.isp.unlock() .then(function () { return _this.isp.sendCommand("P " + _this.sector + " " + endSect); }) .then(function () { return _this.isp.sendCommand("C " + _this.address + " " + srcAddr + " " + count); }) .then(function () { var dst = _this.address; var src = srcAddr.address; var len = count; if (dst === 0) { dst += 64; src += 64; len -= 64; } return _this.isp.sendCommand("M " + dst + " " + src + " " + len); }) .then(function () { _this.block = _this.increment(count); return _this; }); }; ROMWriter.prototype.increment = function (count) { count = Utilities.alignCount(count); return this.block.adjust(count); }; return ROMWriter; }()); exports.ROMWriter = ROMWriter;