implement flashing firmware from new zip format

This commit is contained in:
David Lechner
2020-05-02 14:40:18 -05:00
parent 9d545f8f5c
commit c7b7162693
7 changed files with 149 additions and 15 deletions
+27
View File
@@ -0,0 +1,27 @@
/**
* Compute modulo using floored division
* @param a first operand
* @param b second operand
*/
export function fmod(a: number, b: number): number {
let c = a % b;
if (c / b < 0) {
c += b;
}
return c;
}
/**
* Calculates the 32-bit "sum complement" checksum
* @data an iterable of 32-bit integers
* @returns the value that needs to be added to get 0
*/
export function sumComplement32(data: Iterable<number>): number {
let total = 0;
for (const n of data) {
total += n;
total &= ~0;
}
// checksum is two's complement of total
return ~total + 1;
}