pack: stop prepending a space to model, manufacturer and id - #20
Open
akiernan wants to merge 1 commit into
Open
Conversation
pack_rkaf prepends a leading space to three fixed-width identity fields of the
RKAF header:
let model_str = if model.starts_with(' ') { model.to_string() }
else { format!(" {}", model) };
and the same for manufacturer, and unconditionally for id.
That looks like it is imitating genuine Rockchip images, which really do carry
a leading space on the manufacturer field - but not because the vendor packer
put one there. Comparing three RK3308 factory update images against the
parameter.txt each one carries, field by field:
parameter.txt RKAF header
MACHINE_MODEL:RK3308 model='RK3308'
MACHINE_ID:007 id='007'
MANUFACTURER: RK3308 manufacturer=' RK3308'
All three images, identical. The header holds each value exactly as the
parameter file spelled it, space and all. rkpack.c writing the fields with a
plain "%s", and rkflashtool's rkunpack.c reading the model straight from offset
0x08, are the same story from the other side. The vendor tool prepends nothing:
the space belongs to one line of the vendor's parameter.txt, MANUFACTURER being
the only one of the three the Rockchip parameter-file spec's own example writes
spaced.
So this code matched the reference output on manufacturer by accident and
diverged from it on the other two - backwards from following it. id is the
clearest case: the value is read from parameter.txt and .trim()ed, discarding
whatever spacing the file used, then a space is synthesised back on. Copying
verbatim is both simpler and what the vendor does.
These are machine-readable fields. A consumer comparing model against a known
board identity gets a mismatch for a reason that has nothing to do with the
image, and its only ways out are to strip whitespace from a fixed-width binary
field or to hard-code an offset of 9. It also spends a byte of a bounded field
that write_cstr_preserving_tail already has to share with the NUL.
Nothing is taken away from callers that want the vendor's spacing: model and
manufacturer are supplied by the caller and are now written through untouched,
so passing " RK3308" still yields " RK3308". Where the leading space goes is
the caller's decision, which is the point - it should be a decision, not
something the packer does behind them.
Two existing tests asserted the space (" RK3588\0", " 007\0") - their
expectations are updated. Neither was testing the padding: one covers
string-field tail preservation across a repack, the other that a removed
MACHINE_ID does not leak from a saved template, and both still cover exactly
that. A new test pins the fixed behaviour, checking all three fields land flush
and that bytes 8, 42 and 72 are not spaces.
Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pack_rkaf prepends a leading space to three fixed-width identity fields of the RKAF header:
and the same for manufacturer, and unconditionally for id.
That looks like it is imitating genuine Rockchip images, which really do carry a leading space on the manufacturer field - but not because the vendor packer put one there. Comparing three RK3308 factory update images against the parameter.txt each one carries, field by field:
All three images, identical. The header holds each value exactly as the parameter file spelled it, space and all. rkpack.c writing the fields with a plain "%s", and rkflashtool's rkunpack.c reading the model straight from offset 0x08, are the same story from the other side. The vendor tool prepends nothing: the space belongs to one line of the vendor's parameter.txt, MANUFACTURER being the only one of the three the Rockchip parameter-file spec's own example writes spaced.
So this code matched the reference output on manufacturer by accident and diverged from it on the other two - backwards from following it. id is the clearest case: the value is read from parameter.txt and .trim()ed, discarding whatever spacing the file used, then a space is synthesised back on. Copying verbatim is both simpler and what the vendor does.
These are machine-readable fields. A consumer comparing model against a known board identity gets a mismatch for a reason that has nothing to do with the image, and its only ways out are to strip whitespace from a fixed-width binary field or to hard-code an offset of 9. It also spends a byte of a bounded field that write_cstr_preserving_tail already has to share with the NUL.
Nothing is taken away from callers that want the vendor's spacing: model and manufacturer are supplied by the caller and are now written through untouched, so passing " RK3308" still yields " RK3308". Where the leading space goes is the caller's decision, which is the point - it should be a decision, not something the packer does behind them.
Two existing tests asserted the space (" RK3588\0", " 007\0") - their expectations are updated. Neither was testing the padding: one covers string-field tail preservation across a repack, the other that a removed MACHINE_ID does not leak from a saved template, and both still cover exactly that. A new test pins the fixed behaviour, checking all three fields land flush and that bytes 8, 42 and 72 are not spaces.