Generate full address range
This commit is contained in:
parent
3fe5a2024c
commit
b53fb20281
|
@ -43,13 +43,17 @@ public class BinWriter implements IntelHexDataListener {
|
|||
private final OutputStream destination;
|
||||
private final byte[] buffer;
|
||||
private final MemoryRegions regions;
|
||||
private long maxAddress;
|
||||
private final boolean minimize;
|
||||
|
||||
public BinWriter(Region outputRegion, OutputStream destination) {
|
||||
public BinWriter(Region outputRegion, OutputStream destination, boolean minimize) {
|
||||
this.outputRegion = outputRegion;
|
||||
this.destination = destination;
|
||||
this.minimize = minimize;
|
||||
this.buffer = new byte[(int) (outputRegion.getLength())];
|
||||
Arrays.fill(buffer, (byte) 0xFF);
|
||||
regions = new MemoryRegions();
|
||||
maxAddress = outputRegion.getAddressStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,13 +66,20 @@ public class BinWriter implements IntelHexDataListener {
|
|||
length = (int) (outputRegion.getAddressEnd() - address + 1);
|
||||
}
|
||||
System.arraycopy(data, 0, buffer, (int) (address - outputRegion.getAddressStart()), length);
|
||||
|
||||
if (maxAddress < (address + data.length -1)) {
|
||||
maxAddress = address + data.length - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eof() {
|
||||
try {
|
||||
destination.write(buffer);
|
||||
if (!minimize) {
|
||||
maxAddress = outputRegion.getAddressEnd();
|
||||
}
|
||||
destination.write(buffer, 0, (int)(maxAddress - outputRegion.getAddressStart() + 1));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(BinWriter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,24 @@ public class IntelHexParserDemo {
|
|||
String fileOut = "Application.bin";
|
||||
String dataFrom = "min";
|
||||
String dataTo = "max";
|
||||
boolean minimize = false;
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("usage:");
|
||||
System.out.println(" hex2bin <hex> <bin> <start address> <end address> [minimize]");
|
||||
System.out.println();
|
||||
System.out.println(" full address range of app.hex");
|
||||
System.out.println(" hex2bin app.hex app.bin");
|
||||
System.out.println();
|
||||
System.out.println(" limited exact address range of app.hex, undefined data are 0xff");
|
||||
System.out.println(" hex2bin app.hex app.bin 0x0000 0x1fff");
|
||||
System.out.println();
|
||||
System.out.println(" limited minimal address range of app.hex, start at 0x0000,");
|
||||
System.out.println(" max address is 0x1fff, but can be lower");
|
||||
System.out.println(" hex2bin app.hex app.bin 0x0000 0x1fff minimize");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length >= 1) {
|
||||
fileIn = args[0];
|
||||
}
|
||||
|
@ -82,6 +99,12 @@ public class IntelHexParserDemo {
|
|||
if (args.length >= 4) {
|
||||
dataTo = args[3];
|
||||
}
|
||||
|
||||
if (args.length >=5 ) {
|
||||
if (args[4].equals("minimize")) {
|
||||
minimize = true;
|
||||
}
|
||||
}
|
||||
|
||||
try (FileInputStream is = new FileInputStream(fileIn)) {
|
||||
OutputStream os = new FileOutputStream(fileOut);
|
||||
|
@ -104,7 +127,7 @@ public class IntelHexParserDemo {
|
|||
}
|
||||
|
||||
// 2nd iteration - actual write of the output
|
||||
BinWriter writer = new BinWriter(outputRegion, os);
|
||||
BinWriter writer = new BinWriter(outputRegion, os, minimize);
|
||||
parser.setDataListener(writer);
|
||||
parser.parse();
|
||||
|
||||
|
|
Loading…
Reference in New Issue