Commit Graph

6 Commits

Author SHA1 Message Date
Irfan Ahmad
8d42cd078b scripts: build: Add optimizations in file2hex.py to gzip path as well
Added recently introduced optimizations - generation in string literal form
and faster generation for hexadecimal initializer list form - to gzip path
as well.

Signed-off-by: Irfan Ahmad <irfan.ahmad@siemens.com>
2025-03-07 19:53:34 +01:00
Irfan Ahmad
f3d513da09 scripts: build: Add support for generating string literals in file2hex.py
Currently, file2hex.py supports conversion of binary data into hexadecimal
character list format only. The generated list can then be used to embed
the binary data by using the list to initialize an array. However, this
approach is highly inefficient for large binary files.

A close but considerably more efficient alternative is to use string
literals composed of hex characters (in escaped form) to initialize the
array, instead of an initializer list. Benchmarking (with GCC and clang)
indicates that compile time and host memory usage by the compiler can be
more than an order of magnitude less with string literal approach compared
to the initializer list form.

The only caveat is that string literals contain the null character as
terminator so where accurate length is required, the correct length must
be specified explicitly while defining the array.

Signed-off-by: Irfan Ahmad <irfan.ahmad@siemens.com>
2025-02-08 08:13:08 +01:00
Irfan Ahmad
e30c108728 scripts: build: Optimize hex character list generation in file2hex.py
Read and convert binary data in chunks of 1024 bytes, instead of 8 bytes.
This significantly reduces the conversion time. The improvement increases
with increasing file sizes but saturates to around 60-61% as file size
approaches 64MiB, and beyond.

The existing generated output format of eight byte-values per line is still
preserved.

Signed-off-by: Irfan Ahmad <irfan.ahmad@siemens.com>
2025-01-28 09:49:01 +01:00
Pieter De Gendt
ae8c72444e scripts: build: file2hex: Add optional offset and length parameters
Add optional offset and length parameters to generate partial hex files.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-09-15 13:23:30 +02:00
Jamie McCrae
ec7044437e treewide: Disable automatic argparse argument shortening
Disables allowing the python argparse library from automatically
shortening command line arguments, this prevents issues whereby
a new command is added and code that wrongly uses the shortened
command of an existing argument which is the same as the new
command being added will silently change script behaviour.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-26 20:12:36 +09:00
Anas Nashif
61f672607a scripts: move file2hex.py to scripts/build/file2hex.py
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00