tools: imx_header should not include flash_offset

Doing a  make distclean; make mx6qsabresd_config; make
and      hexdump -C u-boot.imx | less

 ...
 00000360  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 *
 000003f0  00 00 00 00 00 00 00 00  00 00 00 00 00 04 00 00  |................|
                                                ^^^^^^^^^^^
 00000400  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 *
 00001000  13 00 00 ea 14 f0 9f e5  14 f0 9f e5 14 f0 9f e5  |...ê.ð.å.ð.å.ð.å|
 ...

shows the flash_offset value being written into the final
generated image, wich is not correct.

Instead create flash_offset as static variable such that the
generated image is "clean".

 00000360  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 *
 00001000  13 00 00 ea 14 f0 9f e5  14 f0 9f e5 14 f0 9f e5  |...ê.ð.å.ð.å.ð.å|

Signed-off-by: Stefano Babic <sbabic@denx.de>
tools: rename mximage_flash_offset to imximage_ivt_offset

This better reflects the naming from the Reference Manual
as well as fits better since "flash" is not really applicabe
for SATA.

Signed-off-by: Stefano Babic <sbabic@denx.de>
tools: dynamically allocate imx_header in imximage

Change to dynamically allocate the imx_header to correctly
allocate the IVT, Boot Data and DCD at correct locations
depending on the boot media.

Also check that the Image Vector Table Offset + IVT +
Boot Data + DCD <= Initial Load Region Size.

Previously struct imx_header was always 4096 bytes and was
not dealing correctly with the Image Vector Table Offset.

Now, the memory allocation looks for e.g. SD boot like this

 Storage   u-boot.imx                             RAM
 Device

 00000000                                         177ff000 <--------------
                                                                         |
 00000400  00000000  d1 00 20 40 IVT.header       177ff400 <-------      |
 00000404  00000004  00 00 80 17 IVT.entry        177ff404 -----------   |
 00000408  00000008  00 00 00 00 IVT.reserved1    177ff408        |  |   |
 0000040C  0000000C  2c f4 7f 17 IVT.dcd          177ff40C ------ |  |   |
 00000410  00000010  20 f4 7f 17 IVT.boot         177ff410 ---- | |  |   |
 00000414  00000014  00 f4 7f 17 IVT.self         177ff414 --------  |   |
 00000418  00000018  00 00 00 00 IVT.csf          177ff418    | |    |   |
 0000041C  0000001C  00 00 00 00 IVT.reserved2    177ff41C    | |    |   |
 00000420  00000020  00 f0 7f 17 BootData.start   177ff420 <--- |    | ---
 00000424  00000024  00 60 03 00 BootData.length  177ff424      |    |
 00000428  00000028  00 00 00 00 BootData.plugin  177ff428      |    |
 0000042C  0000002C  d2 03 30 40 DCD.header       177ff42C <-----    |
 ...                                                                 |
 00001000  00000c00  13 00 00 ea U-Boot Start     17800000 <----------

While at it also remove the unused #define HEADER_OFFSET.

Signed-off-by: Stefano Babic <sbabic@denx.de>
tools: add variable padding of data image in mkimage

Use previously unused return value of function vrec_header
to return a padding size to generic mkimage. This padding
size is used in copy_files to pad with zeros after copying
the data image.

Signed-off-by: Stefano Babic <sbabic@denx.de>
tools: add padding of data image file for imximage

Implement function vrec_header to be able to pad the final
data image file according the what has been calculated for
boot_data.length.

Signed-off-by: Stefano Babic <sbabic@denx.de>
tools: add support for setting the CSF into imximage

Add support for setting the CSF (Command Sequence File) pointer
which is used for HAB (High Assurance Boot) in the imximage by
adding e.g.

CSF 0x2000

in the imximage.cfg file.

This will set the CSF pointer accordingly just after the padded
data image area. The boot_data.length is adjusted with the
value from the imximage.cfg config file.

The resulting u-boot.imx can be signed with the FSL HAB tooling.
The generated CSF block needs to be appended to the u-boot.imx.

Signed-off-by: Stefano Babic <sbabic@denx.de>
imx: add status reporting for HAB status

Add functions to report the HAB (High Assurance Boot) status
of e.g. i.MX6 CPUs.

This is taken from

git://git.freescale.com/imx/uboot-imx.git branch imx_v2009.08_3.0.35_4.0.0
cpu/arm_cortexa8/mx6/generic.c
include/asm-arm/arch-mx6/mx6_secure.h

Signed-off-by: Stefano Babic <sbabic@denx.de>
ARM: mxs: tools: Add mkimage support for MXS bootstream

Add mkimage support for generating and verifying MXS bootstream.
The implementation here is mostly a glue code between MXSSB v0.4
and mkimage, but the long-term goal is to rectify this and merge
MXSSB with mkimage more tightly. Once this code is properly in
U-Boot, MXSSB shall be deprecated in favor of mkimage-mxsimage
support.

Note that the mxsimage generator needs libcrypto from OpenSSL, I
therefore enabled the libcrypto/libssl unconditionally.

MXSSB: http://git.denx.de/?p=mxssb.git;a=summary

The code is based on research presented at:
http://www.rockbox.org/wiki/SbFileFormat

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@ti.com>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Otavio Salvador <otavio@ossystems.com.br>
tools: Sort lists of files in Makefile

Fix the lists of files so they are in order again.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
tools: mxsboot: Staticize functions

Make remaining non-static functions static and the same for vars.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
ARM: Congatec: README update

README: U-boot works both on SPI-NOR and SDcard

Signed-off-by: Leo Sartre <lsartre@adeneo-embedded.com>
Acked-by: Otavio Salvador <otavio@ossystems.com.br>
ARM: mxs: rename function that sets AUTO_RESTART flag

The AUTO_RESTART flag of HW_RTC_PERSISTENT0 register will
power up the chip automatically 180ms after power down.
This bit must be enabled by the boot loader to ensure the
target can start upon hardware reset or watchdog reset
even when powered from a battery.

Currently the function named 'mxs_power_clear_auto_restart()'
is setting this flag although the 'clear' in its name suggest
the opposite.

This patch renames the function to 'mxs_power_set_auto_restart()'
and removes the comment about EVK revision A which was confusing
because the function indeed was setting the flag.

Signed-off-by: Hector Palacios <hector.palacios@digi.com>
i.MX6: Add convenience macros cpu_type(rev) and is_cpu_type(cpu)

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>
Acked-by: Stefano Babic <sbabic@denx.de>
i.MX6: Correct ANATOP_PFD (Phase Fractional Divider) register declarations

Some _CLKGATE_MASK and _FRAC_MASK macros were wrong for PFD_480
and the PFD_528 macros were missing.

Fortunately, the incorrect macros weren't being used.

Since both the PFD_480 and PFD_528 registers have the same
structure, and the fields are identical for [0..3] in bytes
[0..3], so a single set of macros will suffice.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>
i.MX6: nitrogen6x: Don't bother setting PLL3(480) PFD1 divisor

This clock isn't feeding anything under U-Boot, so there's no
point in changing it from power-on default.

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>
i.MX6: Set and clear the gating bits for Phase Fractional Dividers

This addresses silicon errata ERR006282 as described in this
document:
	https://community.freescale.com/docs/DOC-94581

Also implemented in Freescale's 2009.08-based release:

	http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/
	Commit id: b7c5badf94ffbe6cd0845efbb75e16e05e3af404

Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>
Acked-by: Stefano Babic <sbabic@denx.de>