mirror of https://github.com/rusefi/dfu_java.git
proper erase implementation
This commit is contained in:
parent
ac48084f29
commit
52a20bd5af
|
@ -1,6 +1,8 @@
|
|||
package com.rusefi.dfu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ST chips send their memory layout in USB description string
|
||||
|
@ -25,14 +27,15 @@ public class DfuSeFlashDescriptor {
|
|||
int baseAddress = Integer.parseInt(baseAddressString, 16);
|
||||
System.out.printf("Base address %x\n", baseAddress);
|
||||
|
||||
int totalLength = parseRegions(topLevelSections[2].trim());
|
||||
List<Integer> pages = parseRegions(topLevelSections[2].trim());
|
||||
|
||||
return new FlashRange(baseAddress, totalLength);
|
||||
return new FlashRange(baseAddress, pages);
|
||||
}
|
||||
|
||||
private static int parseRegions(String regions) {
|
||||
private static List<Integer> parseRegions(String regions) {
|
||||
List<Integer> pages = new ArrayList<>();
|
||||
|
||||
String[] sections = regions.split(",");
|
||||
int totalSize = 0;
|
||||
for (String section : sections) {
|
||||
System.out.println("Region " + section);
|
||||
String parts[] = section.split("\\*");
|
||||
|
@ -45,8 +48,9 @@ public class DfuSeFlashDescriptor {
|
|||
|
||||
System.out.println("Count " + count + " size " + pageSize);
|
||||
|
||||
totalSize += count * 1024 * pageSize;
|
||||
for (int i = 0; i < count; i++)
|
||||
pages.add(1024 * pageSize);
|
||||
}
|
||||
return totalSize;
|
||||
return pages;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
package com.rusefi.dfu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FlashRange {
|
||||
private final int baseAddress;
|
||||
private final List<Integer> pages;
|
||||
private final int totalLength;
|
||||
|
||||
public FlashRange(int baseAddress, int totalLength) {
|
||||
public FlashRange(int baseAddress, List<Integer> pages) {
|
||||
this.baseAddress = baseAddress;
|
||||
this.totalLength = totalLength;
|
||||
this.pages = pages;
|
||||
int t = 0;
|
||||
for (Integer page : pages)
|
||||
t += page;
|
||||
this.totalLength = t;
|
||||
}
|
||||
|
||||
public int getBaseAddress() {
|
||||
|
@ -17,6 +25,10 @@ public class FlashRange {
|
|||
return totalLength;
|
||||
}
|
||||
|
||||
public List<Integer> getPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FlashRange{" +
|
||||
|
@ -24,4 +36,17 @@ public class FlashRange {
|
|||
", totalLength=" + totalLength +
|
||||
'}';
|
||||
}
|
||||
|
||||
public List<Integer> pagesForSize(int size) {
|
||||
int total = 0;
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (Integer page : pages) {
|
||||
if (total < size) {
|
||||
result.add(page);
|
||||
total += page;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,5 +10,10 @@ public class DfuSeFlashDescriptorTest {
|
|||
FlashRange range = DfuSeFlashDescriptor.parse("@Internal Flash /0x08000000/04*016Kg,01*064Kg,07*128Kg");
|
||||
assertEquals(0x8000000, range.getBaseAddress());
|
||||
assertEquals(0x100000, range.getTotalLength());
|
||||
|
||||
assertEquals(1, range.pagesForSize(1).size());
|
||||
assertEquals(1, range.pagesForSize(16 * 1024).size());
|
||||
|
||||
assertEquals(2, range.pagesForSize(17 * 1024).size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import cz.jaybee.intelhex.IntelHexException;
|
|||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A test tool focused only on HEX file input
|
||||
|
@ -11,7 +12,7 @@ import java.io.IOException;
|
|||
public class HexReaderSandbox {
|
||||
public static void main(String[] args) throws IOException, IntelHexException {
|
||||
|
||||
FlashRange range = new FlashRange(0x8000000, 0x100000);
|
||||
FlashRange range = new FlashRange(0x8000000, Arrays.asList(0x100000));
|
||||
|
||||
HexImage image = HexImage.loadHexToBuffer(new FileInputStream("rusefi.hex"), range);
|
||||
|
||||
|
|
Loading…
Reference in New Issue