This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

DFU, init packet and protocol buffer

I generated a package with the following command:

nrfutil pkg generate --hw-version 51 --application-version 1 --application nrf51822_xxac.hex --sd-req 0x87 --key-file private.key app_dfu_package.zip

I want to read its .dat file using Java.

I've compiled the .proto file for Java, but when reading the .dat file with my java app, it fails reading it properly, so I started debugging. First thing I did was open the .dat file in a hex editor, along with the protocol buffer spec.

And the first thing I see in the .dat file is 0x12. That is... 0001 0010 Remove MSB, and split, we get 010 as number, 010 as wire type. So it's tag number 2... and it's "length-delimited". Let's open .proto file:

message InitCommand {
	optional uint32	fw_version	= 1;
	optional uint32	hw_version	= 2;
	repeated uint32	sd_req		= 3 [packed = true]; // packed option is default in proto3
	optional FwType	type		= 4;

	optional uint32	sd_size		= 5;
	optional uint32	bl_size		= 6;
	optional uint32	app_size	= 7;

	optional Hash	hash		= 8;
    
	optional bool   is_debug    = 9 [default = false];
}

So it looks like the message starts with "hw_version", however, when it should be a 32 bits int, it's a "length-delimited" thing.

When I build and save a message myself, I get 0x10 0x33, for nRF51, which is exactly what I expect. Does anyone have a clue as why the .dat file starts with 0x12 ?

Related