Commit Graph

147 Commits

Author SHA1 Message Date
Marc Herbert e67d68e8e1 adsp_config.c: actually check error when parsing "version" array elements
Caveat: this was just reported by valgrind. I did not test any actual
toml parsing error either (who tests error handling?) but this code
can't be worse than the previous one.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-09-23 19:11:48 +01:00
Marc Herbert 75f96956e0 elf.c: check ELF32-LE magic number instead of crashing
Passing a 64 bits ELF file by accident (for instance: '/usr/bin/openssl'
while messing up the command line options) caused an interesting cascade
of errors and memory corruption which are all caught in this commit.

This doesn't make rimage fuzz-proof far from it; only fool-proof which
is still useful.

In passing add some quotes so the error message when failing to find the
SHT_NULL section with an empty name is a little bit more readable.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-09-23 19:11:48 +01:00
Marc Herbert 91bd4fe796 rimage.c: print an error instead of crashing when zero ELF argument
Also rename elf_argc to first_non_opt because it's a position, not a
count.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-09-23 19:11:48 +01:00
Marc Herbert 82d4767ca5 Stop silently discarding -l option
Commit https://github.com/thesofproject/soft/commits/59d81995f6828 added
an -l option (for --liam? :-) which was never implemented. Remove it
because silently discarding user input is really not nice no matter how
wrong it is.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-09-23 19:11:48 +01:00
Karol Trzcinski f4e01789f0 travis: Treat warnings as errors
Then each warning message should be addressed.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-22 19:24:22 +01:00
Karol Trzcinski 3b2398a97d travis: Add more warnings to make command
Warnings may point some fatal error in source code.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-22 19:24:22 +01:00
Karol Trzcinski 6dcf1b6ae8 toml: Use only standard error codes
Error codes like ENOKEY and EBADE are not provide for all windows
toolchains, so to immit possible build errors, some more standard
error codes should be used.
Detailed error message is printed in stderr, so end user still
will be well informed about error source.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-22 12:34:40 +01:00
Karol Trzcinski e9759df946 toml: Fix adsp v1.5 parsing
Set right write function.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-18 10:25:18 +01:00
Karol Trzcinski d3ead755c9 toml: manifest: Clear manifest allocated on heap before use
Memory clear allows to easily set seserved/padding fields to zero.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-18 10:25:18 +01:00
Karol Trzcinski 3169dbd40d toml: Add adsp_file_ext attributes parsing
This field left without possibility to set value from
config file.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-18 10:24:26 +01:00
Karol Trzcinski dab973039c toml: Add version information in verbose mode
It allows to assure right version of chosen headers during
reading logs in verbose mode.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-18 10:24:26 +01:00
Karol Trzcinski 2965908135 manifest: Remove -m option
Used platform should be defined by config file, given in
-c option. Double ways of defining platform may lead to
missalignement, so old way should be removed.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-16 15:15:14 +01:00
Karol Trzcinski a94e12d7d6 toml: Add platform configuration files
Given config files may be used as template for new platforms.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-16 15:15:14 +01:00
Karol Trzcinski de1b0f7def config: Add configuration file parsing interface
This allow to add new platform with old version of rimage tool.
Default values are easily to define for any fields, so fields
duplication in config files should be reduced.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-16 15:15:14 +01:00
Karol Trzcinski f654d5337d manifest: Export man_write_fw_vX_Y() to global context
Exported function will be used in configuration parser, to
assign correct function version depending on manifest versiony

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-16 15:15:14 +01:00
Karol Trzcinski 210009c829 adsp: Refactor machine searching
This part should be moved to separate function,
to allow easily add another way of machine description.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-16 15:15:14 +01:00
Karol Trzcinski 29ed0da494 toml: Add TOML parsing library as git submodule
TOML aims to be a minimal configuration file format that's easy to read
due to obvious semantics. TOML is designed to map unambiguously to a hash table.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-09-16 15:15:14 +01:00
Janusz Jankowski 7317f2af39 manifest: set feature mask to 0xffff
This feature is not used by SOF anyway and only causes
FW load failures, we can set it to 0xffff so it will
work for ADL+ platforms.

Signed-off-by: Janusz Jankowski <janusz.jankowski@linux.intel.com>
2020-07-14 12:18:05 +01:00
Marc Herbert 2156dcb00d rimage.c: add assert(image.adsp->write_firmware[_meu])
This makes the write_firmware NULL pointer added by commit
dd77445f01 and corresponding crash more user-friendly.
Before:

  Program received signal SIGSEGV, Segmentation fault.

After:

  rimage: src/rimage.c:197: main: Assertion `image.adsp->write_firmware'
  failed.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-06-16 08:50:28 +01:00
Marc Herbert 4348e2a2bd cmake: use CMAKE_BUILD_TYPE and default to Debug
Unlike hardcoded target_compile_options(-g) can be overriden from the
command line, from the parent ExternalProject_Add(CMAKE_ARGS) (tested)
or from a CMake GUI (not tested).

Default to Debug because the time spent running rimage is negligible
compared to building the image to sign and because the time saved
learning CMake when it crashes can be huge for some people.

BTW -O2 -g is rarely ever useful.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-06-16 08:50:28 +01:00
Karol Trzcinski 9f3f2d7d71 headers: Use full path to header
Path added to include should end at 'include' as usual, then
it is easy to see where specific headers comes from during reading
source code. It is especially important for projects composed from
a few parts, like firmware, driver, build and debug tools in this
project.
Moreover changed "" to <> in include directives because there is
specified full path to file from project include root and to be
aligned with code style from firmware repository,

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-05-25 12:36:12 +01:00
Karol Trzcinski 116e141193 headers: Move headers to rimage namespace
Because there is possibility to reference headers from this repo
from another one, there is a need to put every header into rimage
namespace. Otherwise reference to headers from duplicated
namespace (like kernel) from external repo may be ambiguous.
Update guard ifdef/define/endif sequence value, to make it more
unique

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-05-25 12:36:12 +01:00
Karol Trzcinski 67d09d61c8 ext_man: Move extended manifest generator out of kernel folder
Generator is part of rimage tool and there is any reference to them
in kernel source code, so it should be moved out of kernel folder.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-05-25 12:36:12 +01:00
Adrian Bonislawski f23b2c2d07 rimage: use lma if available
some sections may use different lma than vma address,
in such case rimage needs to use lma

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@linux.intel.com>
2020-05-12 09:10:54 +01:00
Adrian Bonislawski 932478abd6 rimage: show LMA and VMA in section view
Sometimes they will be different and this will make developer
aware of the differences

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@linux.intel.com>
2020-05-12 09:10:54 +01:00
Karol Trzcinski ece04f9656 manifest: ads: meu: Fill FW version description also when MEU is used
This part of binary should contain valid firmware version.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-05-07 11:45:18 +01:00
Karol Trzcinski 537255bdd0 ext_man: Remove redundant variable assign
ret variable is always set in elf_read_section(), to initial value
is not important.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-05-07 11:45:18 +01:00
Karol Trzcinski 76b6301e57 ext_man: Make extended manifest build optional
Try to build extended manifest only when `e` flag will be set,
to prevent error and warning printing during creating optional
part of formware image.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-04-24 11:08:36 +01:00
Karol Trzcinski 328867431c ext_man: Fix write flow when ext_man should be build
elf_read_section() returns section size when everything is ok,
so ret value should be reset to 0 after this function call

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-04-24 11:08:36 +01:00
Karol Trzcinski 0fa22ac38c ext_man: elf: Split module and section searching
Such a solution improve code hermentization and flexibility.
Also such a solution is more relevant because of focus on particular
module during section reading, so there won't be possibility to
implicity scan section 'A' from first module and section 'B' from
second one.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-04-24 11:08:36 +01:00
Karol Trzcinski 6b34a04527 ext_man: Move data section name to global define
This name is used in different part of source code so should refer
to single place instead by copied.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-04-24 11:08:36 +01:00
Karol Trzcinski f0c6ee0f3a ext_man: Create extended manifest
Extended manifest is a place to store metadata about firmware, known during
compilation time - for example firmware version or used compiler.
Given information are read on host side before firmware startup.
This part of output binary is not signed.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-04-21 09:09:18 +01:00
Karol Trzcinski f79d8d7f1e elf: Add function to read section content with allocation
In many functions there is need to read user section content
and check firmware version or write section content to some
manifest or dictionary. Previously to do it, in each function
was loop to search for proper section in proper module,
then allocate buffer, read content and check for possible error
between each step what is quite overwhelming. After change there
will be one function responsible for this task.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-04-21 09:09:18 +01:00
Pan Xiuli aecc0b51d0 CI: Travis: init build test for rimage
Enable simple build test for rimage.

Signed-off-by: Pan Xiuli <xiuli.pan@linux.intel.com>
2020-04-17 10:47:44 +01:00
Andrei Emeltchenko ca65a442bb Handle missing .init_array section
Fixes issue ".init_array" is not copied to ri image making it zero
filled. This causes Zephyr crashing trying to execute functions from
this section.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2020-04-16 09:12:47 +01:00
Andrei Emeltchenko cc5eabb349 Fix compiler errors
Fixes following error when compiling code:
...
src/elf.c: In function ‘elf_find_section’:
src/elf.c:469:20: error: initialization discards ‘const’ qualifier
           from pointer target type [-Werror=discarded-qualifiers]
  469 |  Elf32_Ehdr *hdr = &module->hdr;
      |                    ^
cc1: all warnings being treated as errors
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2020-04-15 15:46:38 +01:00
Daniel Leung 6c4c873b9d Match LICENSE from the main SOF repo
This changes the LICENSE file to match the LICENSE file
from the main SOF repo, except they entries for the kconfig
scripts which are not here in this repo.

Signed-off-by: Daniel Leung <danielcp@gmail.com>
2020-04-15 15:44:51 +01:00
Karol Trzcinski e433e87865 rimage: Remove unused 'image' argument in elf_find_section()
Unused arguments shouldn't be passed to function because it
makes code messy.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-04-07 16:14:48 +01:00
Karol Trzcinski c4701c7664 rimage: Align function arguments in rimage.h
Code formatting should be consistent and function arguments
should be aligned to opening parenthesis.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
2020-04-07 16:14:48 +01:00
Daniel Leung ea04cb816e Remove cmake option SOF_SOURCE_DIR
Since both fw.h and manifest.h are being used in the main SOF
repo and also here in the standalone rimage repo, to prevent
them getting out of sync, the SOF main repo is going to use
the ones coming from the rimage repo. So there is no need for
the option anymore.

Signed-off-by: Daniel Leung <danielcp@gmail.com>
2020-04-05 20:02:13 +01:00
Daniel Leung e09354a5b5 Update rimage to remove ldc generation ability
This reflects the changes on SOF project commit
b3c16790cd.

Signed-off-by: Daniel Leung <danielcp@gmail.com>
2020-04-05 20:02:13 +01:00
Daniel Leung a264697961 Use CMake to build rimage
This adds the necessary bits to allow building rimage
with CMake with similar configure options as the just
removed autotools files.

Also update README.md for new build instructions.

Signed-off-by: Daniel Leung <danielcp@gmail.com>
2020-03-26 09:41:34 +00:00
Daniel Leung 58acbefc8e Remove autotools files
CMake is to be used instead of autotools. So remove the autotools
files.

This revert commit f6bf4b0d72 and
commit 0d33e87433

Signed-off-by: Daniel Leung <danielcp@gmail.com>
2020-03-26 09:41:34 +00:00
Daniel Leung 0adacd5ac2 Update source files from main SOF repo
Update source files from main SOF repository
@ commit 4e87899f25.

Signed-off-by: Daniel Leung <danielcp@gmail.com>
2020-03-26 09:41:34 +00:00
Liam Girdwood 502b5817e3
Merge pull request #2 from dbaluta/db
rimage: Add support for i.MX8X
2020-01-14 13:41:10 +00:00
Daniel Baluta 713e0f8513 rimage: Add support for i.MX8X
i.MX8X is very similar with i.MX8. Memory layout is the same
except IRQSTEER address.

Code will be shared but there will be different firmware binaries
named:
	* sof-imx8.ri, for i.MX8
	* sof-imx8x.ri, for i.MX8X

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
2020-01-13 20:27:23 +02:00
Liam Girdwood f4e515bcd7
Merge pull request #1 from dcpleung/standalone_rimage
Initial commit of rimage tool
2019-11-18 15:39:30 +00:00
Daniel Leung f2e92812af Add building instructions to README.md
This adds intructions to build the rimage tool.

Signed-off-by: Daniel Leung <danielcp@gmail.com>
2019-11-12 09:50:17 -08:00
Daniel Leung f6bf4b0d72 Add files created after running autoreconf
This adds the files created after running `autoreconf -i`.
This allows the project to be 'configure'-d and built.

Signed-off-by: Daniel Leung <danielcp@gmail.com>
2019-11-12 09:50:17 -08:00
Daniel Leung 0d33e87433 Enable autotools to build rimage
This adds the necessary configuration files to enable
autotools for configure/make files generation.

Signed-off-by: Daniel Leung <danielcp@gmail.com>
2019-11-12 09:50:17 -08:00