9
0
Fork 0
Commit Graph

370 Commits

Author SHA1 Message Date
Trent Piepho 4763fac31c socfpga: correct start vector when not using extra barebox header
The barebox ARM image has a 0x50 byte header that consists of:
Bytes 0x00 - 0x0a:  Instruction(s) to jump to start of code
Bytes 0x20 - 0x2f:  Signature and some other data
The rest of header is basically padding.

On SocFPGA, the ROM bootloader expects the 2nd stage bootloader
(barebox) to have a 0x40 byte header with the following fields:
Bytes 0x40 - 0x4b:  Signature and some other data
Bytes 0x4c - 0x4f:  Instruction to jump to start of code

These two headers are compatible, as everything defined in the SocFPGA
header is at a location that is padding the barebox header.

socfpga_mkimage has two methods for creating a SocFPGA image.  One method
prepends an extra 512 byte header to the barebox image, which contains the
SoCFPGA header described above.  The start vector at 0x4c is hard coded to
jump to offset 512, where the barebox header's start vector will be.

socfpga_mkimage can also not prepend this additional header and instead
modify the barebox header to be SoCFPGA compatible.  But it only writes
bytes 0x40-0x4b and not the start vector at 0x4c, leaving that word as
padding.  And so this image will not boot when the ROM bootloader runs it.

This changes the SoCFPGA header creator to write a correct start vector for
both methods.  It will create a branch instruction at 0x4c that jumps to the
start of the barebox image, whether it be at offset 0 or offset 512 (or any
other location).

This makes SoCFPGA images without the extra header bootable.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-05-23 09:48:46 +02:00
Sascha Hauer 4cb8e17aa3 Merge branch 'for-next/misc' 2016-05-09 08:49:43 +02:00
Sascha Hauer 55aca0a48c Merge branch 'for-next/include-cleanup' 2016-05-09 08:49:42 +02:00
Sascha Hauer 21981dbe6c Merge branch 'for-next/imx' 2016-05-09 08:49:42 +02:00
Sascha Hauer 52da32ec4d scripts: Add big endian conversion macros to endian.h
Some programs need the big endian macros, add them to andian.h

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-28 16:43:14 +02:00
Sascha Hauer 854ba3f912 scripts: imx-usb-loader: support set_bits/clear_bits
Now that we can use set_bits/clear_bits in the DCD tables, add support
for this in the imx-usb-loader aswell.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-28 16:08:38 +02:00
Sascha Hauer 471893d020 scripts: imx-usb-loader: make debug output more useful
- print write_memory message only in verbose mode, but in all
  cases when memory is written
- print more information about the DCD section just executed

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-28 16:08:34 +02:00
Sascha Hauer f1d34c2738 scripts: imx: support set_bits/clear_bits
The i.MX SoCs support setting bits and clearing bits in their DCD table.
This adds commands for these in the imx-image tool.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-28 16:08:28 +02:00
Sascha Hauer 473d6f8a7a stdio: replace fprintf(stderr,...) with eprintf
We have a shortcut for fprintf(stderr, so use it. This is done to
be able to remove fprintf in the next step.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-15 12:21:46 +02:00
Alexander Stein 78118046b5 scripts: imx-image: Fix image size in flash header for i.MX35
The i.MX35 needs additional 0x1000 byte. This quirk moved to the wrong
location during refactoring of imx-image for v2016.03.0.

Fixes: adade59759 ""scripts: imx: Allow to create signed images")
Signed-off-by: Daniel Krueger <daniel.krueger@systec-electronic.com>
Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-14 07:58:17 +02:00
Sascha Hauer ca275c3ef1 Merge branch 'for-next/imd' 2016-04-08 13:37:28 +02:00
Sascha Hauer d3b805ad9a scripts: imx: imx-image: Fix image size for HABv3 images
When the image contains CSF data we must add CSF_LEN to the image
size pointer.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-06 10:19:00 +02:00
Sascha Hauer 439d683051 imd: rename imd_search_validate to imd_get
The name is more suitable for what the function does. Also let the
function return a pointer to the imd data found in the buffer.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-01 10:38:55 +02:00
Sascha Hauer 82d40a6214 scripts: Add scripts/include/ to include path for target programs
Programs compiled for the target need -I $(srctree)/scripts/include/ to
be able to include for example linux/err.h.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-01 10:38:54 +02:00
Sascha Hauer f1a2d54cba scripts: make __init__.py nonempty
Otherwise they get removed by make distclean.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-12 08:44:30 +01:00
Sascha Hauer c073534880 Merge branch 'for-next/ratp' 2016-02-08 08:27:01 +01:00
Sascha Hauer 6435fb09d8 Merge branch 'for-next/hab' 2016-02-08 08:26:35 +01:00
Sascha Hauer 610cc35c1e scripts: imx-usb-loader: Do not zero out boot_data_ptr
This shouldn't be necessary. So far it didn't hurt either, but now
this invalidates the signature of the image, so keep the image
unmodified.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 14:38:33 +01:00
Sascha Hauer 796694c0b2 Make: i.MX: Allow to pass config file to cmd_imx_image
Pass the config file to cmd_imx_image as arguments to make it more
flexible. Also add the possibility for another arg containing additional
options.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 14:38:29 +01:00
Sascha Hauer 71e399f6f2 scripts: imx-image: Allow to create HAB signed images suitable for USB upload
For USB upload we must execute the DCD table manually and
invalidate the DCD table in the uploaded image afterwards
to prevent the ROM from executing the DCD data again. Doing this
changes the image and thus also invalidates the signature. To
make HAB signed images suitable for USB upload possible we add an
option to create HAB signed images suitable for USB upload. With
this option the image is created like this:

- The image is created like usual, but with already invalidated DCD
  data (DCD length is set to zero)
- This image is then signed using the CST
- After this the DCD data is made valid (Set DCD length to the real
  length)

imx-usb-loader now finds valid DCD data, executes it and by invalidating
the DCD data it restores the state the image had during signing.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 08:29:17 +01:00
Sascha Hauer 912f66935a scripts: imx-image: Factor out a read_file function
The same code will be used a second time in a followup patch, so
factor out a common function.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 08:29:17 +01:00
Sascha Hauer 7dede160a8 scripts: imx-usb-loader: Use dcd len to invalidate dcd data
We invalidate the dcd data in the uploaded image since we already
processed it manually. To do so we have set the dcd pointer to 0.
Doing it this way prevents the ROM from executing the HAB code in
debug mode. Use the dcd length instead to invalidate the dcd data.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 08:29:17 +01:00
Sascha Hauer 3fc80b8d3d scripts: imx: Generate signed images with imx-image
The imx-image tool can now generate signed images itself, so we can
switch to this mechanism:

- Move the CSF templates to header files which can be included by the
  flash config files
- remove images/Makefile.imxhabv4 which is no longer necessary.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 08:29:17 +01:00
Sascha Hauer adade59759 scripts: imx: Allow to create signed images
This patch allows to call CST directly from imx-image to create signed
images. CST is called whenever the config file contains the hab <str>
commands which means a CSF is generated.
Calling CST requires some quirks. First of all CST returns successfully
whenever a CSF exists, no matter is the CSF actually contains something
sensible or not. So to detect if CST has been called successfully we
have to check if it generated output, not if it returned successfully.
Then CST uses csfsig.bin as a temporary file which breaks when the tool
is called multiple times at once, something which often happens in
parallel builds. We therefore have to lock accesses to this file using
flock().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 08:29:16 +01:00
Sascha Hauer 3b4db3851b scripts: imx: Create CSF files from imx config file
This is the first step to support creating signed images directly
with the imx-image tool. i.MX images must be signed using the Freescale
CST tool. CST needs informations already present in the imx-image tool,
so it's convenient to call CST directly from imx-image.
CST takes CSF files (Command Sequence Files) as input. This patch
supports generating CSF files from the imx-image configuration file.
This adds three new commands to the config file:

hab <str>:  All options to the hab command are directly passed through to
            the CSF.
hab_blocks: This generates the "Blocks =" line in the CSF. This is the
            place where the CSF needs information which is contained in
	    the imx-image tool: The image size, the image filename and
	    the load address.
super_root_key <file>: For HABv3 the super root key hash is needed in
                       the i.MX flash header. This command is used to
		       specify the path to the super root key. Needed
		       for HABv3 only.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 08:29:16 +01:00
Sascha Hauer 0b57bfb12f scripts: imx-image: Support adding a Super Root Key to the image
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 08:29:16 +01:00
Sascha Hauer 310b4a4ce3 scripts: imx-image: pass config data to add_header_*
Now that we have a config data struct we can pass it to add_header_*
to reduce the argument count.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 08:29:15 +01:00
Sascha Hauer 271c93f99f scripts: imx-image: move more variables to context data
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-04 08:28:01 +01:00
Sascha Hauer 6fafba44e7 scripts: imx: Drop double check
We have the same "if (*line == '\0')" check twice. Remove one of them.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer ba8898e63f scripts: imx-usb-loader: Add -s and -i options
Normally imx-usb-loader interprets and executes the DCD table from
an uploaded image and invalidates the DCD before uploading the image
itself to prevent the i.MX ROM code from executing it again. With HAB
signed images this is not possible since invalidating the DCD table
modifies the image which also makes the signature invalid.
To support this usecase add two new options to imx-usb-loader:

The -i option allows to pass in an external config file which can be
used to setup SDRAM. The DCD table in the image can then be made empty
so that the ROM does not see a second SDRAM setup.

The -s option allows to skip interpreting the DCD table in the image.
This may when some setup stuff is still in the images DCD table but
shall be executed by the ROM and not by imx-usb-loader.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer 9ee83d3f8d scripts: imx: make libusb variables global
No need to pass the libusb context through from function to function.
Make them globally visible.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer 64dca713e5 scripts: imx: move config file parser to separate file
To make the config parser usable by imx-usb-loader also move
it to a separate file.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer 2cc35fe5de scripts: imx-image: move check to context data
Move the config parsers check function to context data to make
it possible to pass in a different version of this function later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer 28809d1517 scripts: imx-image: move write_mem to context data
Move the config parsers write_mem function to context data to make
it possible to pass in a different version of this function later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer 020136d26c scripts: imx-image: Add context struct to config parsers
This adds a context struct to the config parser. This is a first
step to make the config parser usable from both imx-image and
imx-usb-loader which will be needed later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer be6b5cf74c scripts: imx: Consolidate flash headers in imx tools
Both imx-image and imx-usb-loader use their own variants of the
i.MX flash header definitions. Consolidate them to avoid code
duplication.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer 24315db717 scripts: imx-usb-loader: Move load_file up
To avoid forward declaration in a later patch.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer eee4a26680 scripts: imx-usb-loader: fully read images into memory
imx-usb-loader tries to safe memory by reading the image in chunks.
This is unnecessarily complicated. The images are small, so fully read
them into memory and store them in a single buffer. This makes handling
them a lot easier.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer 2ae40562ae scripts: imx-image: Allow dcd offset 0x0
0 is a valid offset for the dcd, so do not use this value to detect
an unset dcd offset. Use 0xffffffff instead.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer bca787cf4a scripts: imx-usb-loader: Move definitions up
The macros are needed earlier in a later patch.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer a44976d238 scripts: imx-usb-loader: Make readonly arguments const
The buffers passed to dump_long and dump_bytes are not (and shouldn't
be) modified. Make the arguments const.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer b5eb8b90fe scripts: mxs: Use Kernel includes
Use the common definition of ARRAY_SIZE and roundup.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer 9aa7aa8f08 scripts: imx: Use Kernel includes
Use the common definition of ARRAY_SIZE and offsetof.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer f5c8d18ece scripts: Add scripts/include to host compiler includes
So that host tools can use the kernel includes.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer dd29e91770 scripts/include: Add ARRAY_SIZE
ARRAY_SIZE is another define commonly used in tools. Add it to the
kernel includes.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Sascha Hauer a883d9a3c0 scripts: Add common header files for tools
This imports the tools/include dir from the Kernel as of 4.5-rc1 to
barebox.
The Kernel has many useful defines and helpers which are often
duplicated in the different tools. Let's create a copy of them
in a common place for all tools.

Some files have been skipped for now as I currently see no use for them:

include/linux/filter.h
include/linux/hash.h
include/linux/rbtree.h
include/linux/rbtree_augmented.h

They can be added later if needed.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-02 15:41:04 +01:00
Uwe Kleine-König 39ebd7e73b kwboot: do a filetype check before sending the image
Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-01-26 08:00:15 +01:00
Jan Luebbe be6c6e6536 host side for barebox remote control
This contains the host tool for barebox remote control. It is written in
Phython with its own implementation of the RATP protocol. Currently this
is a very simple tool which needs more work, but the code can also be
used as a library.

Example output:

console: '.      '
console: '..     '
console: 'dev    '
console: 'env    '
console: 'mnt    '
console: '\n'
Result: BBPacketCommandReturn(exit_code=0)

Signed-off-by: Jan Lübbe <j.luebbe@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Tested-by: Andrey Smirnov <andrew.smirnov@gmail.com>
2016-01-18 09:25:50 +01:00
Sascha Hauer 06fc3557c9 pyserial: decrease timeouts
pyserial has very generous timeouts which introduces quite big latencies
at least when used on rfc2217 ports. Decrease timeouts to make it more
reactive.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-01-18 09:25:50 +01:00
Jan Luebbe 80caf8ac43 include pyserial trunk
The current pyserial is broken, this version contains the fix for:
http://sourceforge.net/p/pyserial/bugs/166/

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
2016-01-18 09:25:50 +01:00