1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-15 20:35:23 +03:00

Remove tabs and some trailing spaces

This commit is contained in:
Miguel Angel Mulero Martinez 2019-11-03 13:40:26 +01:00
parent 55df431247
commit 09e2f6d231
9 changed files with 384 additions and 393 deletions

View file

@ -222,34 +222,34 @@ STM32DFU_protocol.prototype.getInterfaceDescriptors = function (interfaceNum, ca
return;
}
var interfaceID = 0;
var descriptorStringArray = [];
var getDescriptorString = function () {
if(interfaceID < config.interfaces.length) {
self.getInterfaceDescriptor(interfaceID, function (descriptor, resultCode) {
if (resultCode) {
callback([], resultCode);
return;
}
interfaceID++;
self.getString(descriptor.iInterface, function (descriptorString, resultCode) {
if (resultCode) {
callback([], resultCode);
return;
}
if (descriptor.bInterfaceNumber == interfaceNum) {
descriptorStringArray.push(descriptorString);
}
getDescriptorString();
});
});
} else {
//console.log(descriptorStringArray);
callback(descriptorStringArray, 0);
return;
}
}
getDescriptorString();
var interfaceID = 0;
var descriptorStringArray = [];
var getDescriptorString = function () {
if(interfaceID < config.interfaces.length) {
self.getInterfaceDescriptor(interfaceID, function (descriptor, resultCode) {
if (resultCode) {
callback([], resultCode);
return;
}
interfaceID++;
self.getString(descriptor.iInterface, function (descriptorString, resultCode) {
if (resultCode) {
callback([], resultCode);
return;
}
if (descriptor.bInterfaceNumber == interfaceNum) {
descriptorStringArray.push(descriptorString);
}
getDescriptorString();
});
});
} else {
//console.log(descriptorStringArray);
callback(descriptorStringArray, 0);
return;
}
}
getDescriptorString();
});
}
@ -343,7 +343,7 @@ STM32DFU_protocol.prototype.getChipInfo = function (_interface, callback) {
// H750 Partitions: Flash, Config, Firmware, 1x BB Management block + x BB Replacement blocks)
if (str == "@External Flash /0x90000000/1001*128Kg,3*128Kg,20*128Ka") {
str = "@External Flash /0x90000000/998*128Kg,1*128Kg,4*128Kg,21*128Ka"
str = "@External Flash /0x90000000/998*128Kg,1*128Kg,4*128Kg,21*128Ka"
}
// split main into [location, start_addr, sectors]
@ -396,11 +396,6 @@ STM32DFU_protocol.prototype.getChipInfo = function (_interface, callback) {
case 'K':
page_size *= 1024;
break;
/* case ' ':
break;
default:
return null;
*/
}
sectors.push({
@ -419,12 +414,12 @@ STM32DFU_protocol.prototype.getChipInfo = function (_interface, callback) {
'sectors' : sectors,
'total_size' : total_size
}
return memory;
}
var chipInfo = descriptors.map(parseDescriptor).reduce(function(o, v, i) {
o[v.type.toLowerCase().replace(' ', '_')] = v;
return o;
}, {});
return memory;
}
var chipInfo = descriptors.map(parseDescriptor).reduce(function(o, v, i) {
o[v.type.toLowerCase().replace(' ', '_')] = v;
return o;
}, {});
callback(chipInfo, resultCode);
});
}
@ -435,7 +430,7 @@ STM32DFU_protocol.prototype.controlTransfer = function (direction, request, valu
// timeout support was added in chrome v43
var timeout;
if (typeof _timeout === "undefined") {
timeout = 0; // default is 0 (according to chrome.usb API)
timeout = 0; // default is 0 (according to chrome.usb API)
} else {
timeout = _timeout;
}
@ -527,11 +522,11 @@ STM32DFU_protocol.prototype.loadAddress = function (address, callback, abort) {
callback(data);
} else {
console.log('Failed to execute address load');
if(typeof abort === "undefined" || abort) {
self.upload_procedure(99);
} else {
callback(data);
}
if(typeof abort === "undefined" || abort) {
self.upload_procedure(99);
} else {
callback(data);
}
}
});
}, delay);
@ -572,15 +567,15 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
if (typeof chipInfo.internal_flash !== "undefined") {
// internal flash
self.chipInfo = chipInfo;
self.flash_layout = chipInfo.internal_flash;
self.available_flash_size = self.flash_layout.total_size - (self.hex.start_linear_address - self.flash_layout.start_address);
GUI.log(i18n.getMessage('dfu_device_flash_info', (self.flash_layout.total_size / 1024).toString()));
if (self.hex.bytes_total > self.available_flash_size) {
GUI.log(i18n.getMessage('dfu_error_image_size',
[(self.hex.bytes_total / 1024.0).toFixed(1),
GUI.log(i18n.getMessage('dfu_error_image_size',
[(self.hex.bytes_total / 1024.0).toFixed(1),
(self.available_flash_size / 1024.0).toFixed(1)]));
self.upload_procedure(99);
} else {
@ -596,7 +591,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
// external flash, flash to the 3rd partition.
self.chipInfo = chipInfo;
self.flash_layout = chipInfo.external_flash;
var firmware_partition_index = 2;
var firmware_sectors = self.flash_layout.sectors[firmware_partition_index];
var firmware_partition_size = firmware_sectors.total_size;
@ -606,8 +601,8 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
GUI.log(i18n.getMessage('dfu_device_flash_info', (self.flash_layout.total_size / 1024).toString()));
if (self.hex.bytes_total > self.available_flash_size) {
GUI.log(i18n.getMessage('dfu_error_image_size',
[(self.hex.bytes_total / 1024.0).toFixed(1),
GUI.log(i18n.getMessage('dfu_error_image_size',
[(self.hex.bytes_total / 1024.0).toFixed(1),
(self.available_flash_size / 1024.0).toFixed(1)]));
self.upload_procedure(99);
} else {
@ -627,122 +622,120 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
});
break;
case 1:
if (typeof self.chipInfo.option_bytes === "undefined") {
console.log('Failed to detect option bytes');
self.upload_procedure(99);
}
if (typeof self.chipInfo.option_bytes === "undefined") {
console.log('Failed to detect option bytes');
self.upload_procedure(99);
}
var unprotect = function() {
console.log('Initiate read unprotect');
let messageReadProtected = i18n.getMessage('stm32ReadProtected');
GUI.log(messageReadProtected);
TABS.firmware_flasher.flashingMessage(messageReadProtected, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.ACTION)
var unprotect = function() {
console.log('Initiate read unprotect');
let messageReadProtected = i18n.getMessage('stm32ReadProtected');
GUI.log(messageReadProtected);
TABS.firmware_flasher.flashingMessage(messageReadProtected, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.ACTION)
self.controlTransfer('out', self.request.DNLOAD, 0, 0, 0, [0x92], function () { // 0x92 initiates read unprotect
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
if (data[4] == self.state.dfuDNBUSY) { // completely normal
var delay = data[1] | (data[2] << 8) | (data[3] << 16);
var total_delay = delay + 20000; // wait at least 20 seconds to make sure the user does not disconnect the board while erasing the memory
var timeSpentWaiting = 0;
var incr = 1000; // one sec increments
var waitForErase = setInterval(function () {
self.controlTransfer('out', self.request.DNLOAD, 0, 0, 0, [0x92], function () { // 0x92 initiates read unprotect
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
if (data[4] == self.state.dfuDNBUSY) { // completely normal
var delay = data[1] | (data[2] << 8) | (data[3] << 16);
var total_delay = delay + 20000; // wait at least 20 seconds to make sure the user does not disconnect the board while erasing the memory
var timeSpentWaiting = 0;
var incr = 1000; // one sec increments
var waitForErase = setInterval(function () {
TABS.firmware_flasher.flashProgress(Math.min(timeSpentWaiting / total_delay, 1) * 100);
TABS.firmware_flasher.flashProgress(Math.min(timeSpentWaiting / total_delay, 1) * 100);
if(timeSpentWaiting < total_delay)
{
timeSpentWaiting += incr;
return;
}
clearInterval(waitForErase);
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data, error) { // should stall/disconnect
if(error) { // we encounter an error, but this is expected. should be a stall.
console.log('Unprotect memory command ran successfully. Unplug flight controller. Connect again in DFU mode and try flashing again.');
GUI.log(i18n.getMessage('stm32UnprotectSuccessful'));
let messageUnprotectUnplug = i18n.getMessage('stm32UnprotectUnplug');
GUI.log(messageUnprotectUnplug);
if(timeSpentWaiting < total_delay) {
timeSpentWaiting += incr;
return;
}
clearInterval(waitForErase);
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data, error) { // should stall/disconnect
if(error) { // we encounter an error, but this is expected. should be a stall.
console.log('Unprotect memory command ran successfully. Unplug flight controller. Connect again in DFU mode and try flashing again.');
GUI.log(i18n.getMessage('stm32UnprotectSuccessful'));
TABS.firmware_flasher.flashingMessage(messageUnprotectUnplug, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.ACTION)
.flashProgress(0);
let messageUnprotectUnplug = i18n.getMessage('stm32UnprotectUnplug');
GUI.log(messageUnprotectUnplug);
} else { // unprotecting the flight controller did not work. It did not reboot.
console.log('Failed to execute unprotect memory command');
GUI.log(i18n.getMessage('stm32UnprotectFailed'));
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32UnprotectFailed'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
console.log(data);
self.upload_procedure(99);
}
}, 2000); // this should stall/disconnect anyways. so we only wait 2 sec max.
}, incr);
} else {
console.log('Failed to initiate unprotect memory command');
let messageUnprotectInitFailed = i18n.getMessage('stm32UnprotectInitFailed')
GUI.log(messageUnprotectInitFailed);
TABS.firmware_flasher.flashingMessage(messageUnprotectInitFailed, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID)
self.upload_procedure(99);
}
});
});
}
TABS.firmware_flasher.flashingMessage(messageUnprotectUnplug, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.ACTION)
.flashProgress(0);
} else { // unprotecting the flight controller did not work. It did not reboot.
console.log('Failed to execute unprotect memory command');
var tryReadOB = function() {
// the following should fail if read protection is active
self.controlTransfer('in', self.request.UPLOAD, 2, 0, self.chipInfo.option_bytes.total_size, 0, function (ob_data, errcode) {
if(errcode) {
console.log('USB transfer error while reading option bytes: ' + errcode1);
self.upload_procedure(99);
return;
}
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
if (data[4] == self.state.dfuUPLOAD_IDLE && ob_data.length == self.chipInfo.option_bytes.total_size) {
console.log('Option bytes read successfully');
console.log('Chip does not appear read protected');
GUI.log(i18n.getMessage('stm32NotReadProtected'));
// it is pretty safe to continue to erase flash
self.clearStatus(function() {
self.upload_procedure(2);
});
/* // this snippet is to protect the flash memory (only for the brave)
ob_data[1] = 0x0;
var writeOB = function() {
self.controlTransfer('out', self.request.DNLOAD, 2, 0, 0, ob_data, function () {
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
if (data[4] == self.state.dfuDNBUSY) {
var delay = data[1] | (data[2] << 8) | (data[3] << 16);
GUI.log(i18n.getMessage('stm32UnprotectFailed'));
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32UnprotectFailed'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
console.log(data);
self.upload_procedure(99);
}
}, 2000); // this should stall/disconnect anyways. so we only wait 2 sec max.
}, incr);
} else {
console.log('Failed to initiate unprotect memory command');
let messageUnprotectInitFailed = i18n.getMessage('stm32UnprotectInitFailed')
GUI.log(messageUnprotectInitFailed);
TABS.firmware_flasher.flashingMessage(messageUnprotectInitFailed, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID)
self.upload_procedure(99);
}
});
});
}
setTimeout(function () {
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
if (data[4] == self.state.dfuDNLOAD_IDLE) {
console.log('Failed to write ob');
self.upload_procedure(99);
} else {
console.log('Success writing ob');
self.upload_procedure(99);
}
});
}, delay);
} else {
console.log('Failed to initiate write ob');
self.upload_procedure(99);
}
});
});
}
self.clearStatus(function () {
self.loadAddress(self.chipInfo.option_bytes.start_address, function () {
self.clearStatus(writeOB);
});
}); // */
} else {
console.log('Option bytes could not be read. Quite possibly read protected.');
self.clearStatus(unprotect);
}
});
});
}
var tryReadOB = function() {
// the following should fail if read protection is active
self.controlTransfer('in', self.request.UPLOAD, 2, 0, self.chipInfo.option_bytes.total_size, 0, function (ob_data, errcode) {
if(errcode) {
console.log('USB transfer error while reading option bytes: ' + errcode1);
self.upload_procedure(99);
return;
}
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
if (data[4] == self.state.dfuUPLOAD_IDLE && ob_data.length == self.chipInfo.option_bytes.total_size) {
console.log('Option bytes read successfully');
console.log('Chip does not appear read protected');
GUI.log(i18n.getMessage('stm32NotReadProtected'));
// it is pretty safe to continue to erase flash
self.clearStatus(function() {
self.upload_procedure(2);
});
/* // this snippet is to protect the flash memory (only for the brave)
ob_data[1] = 0x0;
var writeOB = function() {
self.controlTransfer('out', self.request.DNLOAD, 2, 0, 0, ob_data, function () {
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
if (data[4] == self.state.dfuDNBUSY) {
var delay = data[1] | (data[2] << 8) | (data[3] << 16);
setTimeout(function () {
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data) {
if (data[4] == self.state.dfuDNLOAD_IDLE) {
console.log('Failed to write ob');
self.upload_procedure(99);
} else {
console.log('Success writing ob');
self.upload_procedure(99);
}
});
}, delay);
} else {
console.log('Failed to initiate write ob');
self.upload_procedure(99);
}
});
});
}
self.clearStatus(function () {
self.loadAddress(self.chipInfo.option_bytes.start_address, function () {
self.clearStatus(writeOB);
});
}); // */
} else {
console.log('Option bytes could not be read. Quite possibly read protected.');
self.clearStatus(unprotect);
}
});
});
}
var initReadOB = function (loadAddressResponse) {
// contrary to what is in the docs. Address load should in theory work even if read protection is active
@ -761,10 +754,10 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
}
}
self.clearStatus(function () {
// load address fails if read protection is active unlike as stated in the docs
self.loadAddress(self.chipInfo.option_bytes.start_address, initReadOB, false);
});
self.clearStatus(function () {
// load address fails if read protection is active unlike as stated in the docs
self.loadAddress(self.chipInfo.option_bytes.start_address, initReadOB, false);
});
break;
case 2:
// erase
@ -795,7 +788,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
}
}
}
if (erase_pages.length === 0) {
console.log('Aborting, No flash pages to erase');
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32InvalidHex'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
@ -805,17 +798,17 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32Erase'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL);
console.log('Executing local chip erase', erase_pages);
console.log('Executing local chip erase', erase_pages);
var page = 0;
var total_erased = 0; // bytes
var erase_page = function() {
var page_addr = erase_pages[page].page * self.flash_layout.sectors[erase_pages[page].sector].page_size +
var page_addr = erase_pages[page].page * self.flash_layout.sectors[erase_pages[page].sector].page_size +
self.flash_layout.sectors[erase_pages[page].sector].start_address;
var cmd = [0x41, page_addr & 0xff, (page_addr >> 8) & 0xff, (page_addr >> 16) & 0xff, (page_addr >> 24) & 0xff];
total_erased += self.flash_layout.sectors[erase_pages[page].sector].page_size;
console.log('Erasing. sector ' + erase_pages[page].sector +
console.log('Erasing. sector ' + erase_pages[page].sector +
', page ' + erase_pages[page].page + ' @ 0x' + page_addr.toString(16));
self.controlTransfer('out', self.request.DNLOAD, 0, 0, 0, cmd, function () {