Skip to content

Conversation

@gfabiano
Copy link
Contributor

A first implementation to sparse images flashing. I tested it with some images and it works correctly on my qcom bench.

Signed-off-by: Giuseppe Fabiano <gfabiano40@gmail.com>

let mut fill_vec = Vec::<u8>::with_capacity(out_size);
for _ in 0..out_size / 4 {
fill_vec.extend_from_slice(&fill_value[..]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do something roughly equivalent inside program_storage already, so all this can simplify this branch to passing a &mut &[0u8][..] as an argument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the same because the fill value is a 4 bytes that you get from the sparse file and you repeat for N times. If you set &mut &[0u8][..] you will get zero repeated for N times that not respect the sparse format.

Giving a let mut fill_value = [1, 2, 3, 4]; read from files and an let out_size = 25 ( N=5 ) you shall get something like that

[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]

It can sure be improved but I decided to keep it simple and not modify also the firehose_program_storage function.

If you have some hint on how to handle it better I can sure improve it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

fill_vec.iter().repeat(fill_value).take(out_size/4);

since the value will likely be the same, we can perhaps cache fill_value and check if it differs on each found Fill chunk, and only re-assign the vector if we need to, taking away some overhead

@gfabiano
Copy link
Contributor Author

I think that I must improve the implementation because typically raw chunks are contiguos so calling for every chunk firehose_program_storage can hog the speed. @quic-kdybcio what you propose, maybe moving the sparse handling inside the firehose_program_storage can be better?

}
ChunkType::Crc32 => {
// Not supported, on qcom tools is ignored, seek if present
buf.seek_relative(4)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, is the CRC valid on your images?

@quic-kdybcio
Copy link
Contributor

I think that I must improve the implementation because typically raw chunks are contiguos so calling for every chunk firehose_program_storage can hog the speed. @quic-kdybcio what you propose, maybe moving the sparse handling inside the firehose_program_storage can be better?

I think the current approach is ok - IIUC sparse chunks can be as big as you want (which program_storage handles gracefully) so long as they're 4K-aligned in size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants