mirror of
https://github.com/thegecko/web-bluetooth-dfu.git
synced 2025-12-12 20:18:13 +08:00
Softdevice and bootloader updates now working...
commit might get messed up because chrome dev editor caused some problems with this one.
This commit is contained in:
34
dist/hex2bin.js
vendored
34
dist/hex2bin.js
vendored
@@ -54,8 +54,7 @@
|
|||||||
* NOTE: the binary we generate may be bigger than this size because of padding.
|
* NOTE: the binary we generate may be bigger than this size because of padding.
|
||||||
* Really this is just a sanity check for now. If the binary is much bigger than the hex then we probably have some kind of an error.
|
* Really this is just a sanity check for now. If the binary is much bigger than the hex then we probably have some kind of an error.
|
||||||
*/
|
*/
|
||||||
function helperGetHexSize(hex) {
|
function helperGetHexSize(hexLines) {
|
||||||
var hexLines = hex.split("\n");
|
|
||||||
var size = 0;
|
var size = 0;
|
||||||
hexLines.forEach(function(line) {
|
hexLines.forEach(function(line) {
|
||||||
if (line.substr(7, 2) === RECORD_TYPE.DATA) {
|
if (line.substr(7, 2) === RECORD_TYPE.DATA) {
|
||||||
@@ -70,8 +69,7 @@
|
|||||||
* The first record of type extended linear address will store the start base address of the binary.
|
* The first record of type extended linear address will store the start base address of the binary.
|
||||||
* Then the first data record's address offset will complete our start address.
|
* Then the first data record's address offset will complete our start address.
|
||||||
*/
|
*/
|
||||||
function helperGetBinaryStartAddress(hex) {
|
function helperGetBinaryStartAddress(hexLines) {
|
||||||
var hexLines = hex.split("\n");
|
|
||||||
var record;
|
var record;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -94,8 +92,7 @@
|
|||||||
* The last record of type data will store the address offset and length of the data stored at that address.
|
* The last record of type data will store the address offset and length of the data stored at that address.
|
||||||
* Then the last extended linear address record's base address will complete our end address.
|
* Then the last extended linear address record's base address will complete our end address.
|
||||||
*/
|
*/
|
||||||
function helperGetBinaryEndAddress(hex) {
|
function helperGetBinaryEndAddress(hexLines, maxAddress) {
|
||||||
var hexLines = hex.split("\n");
|
|
||||||
var record;
|
var record;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -112,6 +109,10 @@
|
|||||||
var lastBaseAddress = parseInt(record.substr(9, 4), 16) << 16;
|
var lastBaseAddress = parseInt(record.substr(9, 4), 16) << 16;
|
||||||
|
|
||||||
var endAddress = lastBaseAddress + lastDataRecordAddressOffset + lastDataRecordLength;
|
var endAddress = lastBaseAddress + lastDataRecordAddressOffset + lastDataRecordLength;
|
||||||
|
|
||||||
|
if (endAddress > maxAddress) {
|
||||||
|
return helperGetBinaryEndAddress(hexLines, maxAddress);
|
||||||
|
}
|
||||||
log('end address of binary: ' + endAddress);
|
log('end address of binary: ' + endAddress);
|
||||||
return endAddress;
|
return endAddress;
|
||||||
}
|
}
|
||||||
@@ -123,21 +124,21 @@
|
|||||||
* This is because we are not to send the Master Boot Recrod (under minAddress) when updating the SoftDevice.
|
* This is because we are not to send the Master Boot Recrod (under minAddress) when updating the SoftDevice.
|
||||||
* And we are not to send UICR data (above maxAddress) when updating the bootloader or application.
|
* And we are not to send UICR data (above maxAddress) when updating the bootloader or application.
|
||||||
*/
|
*/
|
||||||
return function(hex, minAddress, maxAddress) {
|
return function(hex, maxAddress, minAddress) {
|
||||||
var hexLines = hex.split("\n");
|
maxAddress = maxAddress || 0xFFFFFFFF;
|
||||||
|
minAddress = minAddress || 0x0;
|
||||||
|
|
||||||
var hexSizeBytes = helperGetHexSize(hex);
|
var hexSizeBytes = helperGetHexSize(hex.split("\n"));
|
||||||
var startAddress = helperGetBinaryStartAddress(hex);
|
var startAddress = helperGetBinaryStartAddress(hex.split("\n"), minAddress);
|
||||||
var endAddress = helperGetBinaryEndAddress(hex);
|
var endAddress = helperGetBinaryEndAddress(hex.split("\n"), maxAddress);
|
||||||
|
|
||||||
minAddress = minAddress || startAddress;
|
|
||||||
maxAddress = maxAddress || endAddress;
|
|
||||||
|
|
||||||
if (startAddress < minAddress) {
|
if (startAddress < minAddress) {
|
||||||
startAddress = minAddress;
|
startAddress = minAddress;
|
||||||
|
log('trimmed start address of binary: ' + startAddress);
|
||||||
}
|
}
|
||||||
if (endAddress > maxAddress) {
|
if (endAddress > maxAddress) {
|
||||||
endAddress = maxAddress;
|
endAddress = maxAddress;
|
||||||
|
log('trimmed start address of binary: ' + startAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
var binarySizeBytes = endAddress - startAddress;
|
var binarySizeBytes = endAddress - startAddress;
|
||||||
@@ -148,6 +149,7 @@
|
|||||||
|
|
||||||
var baseAddress;
|
var baseAddress;
|
||||||
|
|
||||||
|
var hexLines = hex.split("\n");
|
||||||
hexLines.forEach(function(line) {
|
hexLines.forEach(function(line) {
|
||||||
|
|
||||||
switch (line.substr(7, 2)) {
|
switch (line.substr(7, 2)) {
|
||||||
@@ -158,7 +160,7 @@
|
|||||||
var data = line.substr(9, length * 2);
|
var data = line.substr(9, length * 2);
|
||||||
for (var i = 0; i < length * 2; i += 2) {
|
for (var i = 0; i < length * 2; i += 2) {
|
||||||
var index = (baseAddress + addressOffset) - startAddress + (i / 2);
|
var index = (baseAddress + addressOffset) - startAddress + (i / 2);
|
||||||
if (index > 0 || index <= binarySizeBytes) { // This cuts off any data below minAddress and above maxAddress.
|
if (index >= 0 && index < binarySizeBytes) { // This cuts off any data below minAddress and above maxAddress.
|
||||||
view[index] = parseInt(data.substr(i, 2), 16);
|
view[index] = parseInt(data.substr(i, 2), 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,4 +190,4 @@
|
|||||||
});
|
});
|
||||||
return buffer;
|
return buffer;
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user