mksunxiboot: Fix loading of files with a size which is not a multiple of 4

We should not be aligning the amount of bytes which we try to read from the
disk, this leads to trying to read more bytes then there are which fails.

file_size is already aligned to BLOCK_SIZE before being stored in
img.header.length, so there is no need for load_size at all.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
mvtwsi: Fix clock programming

The TWSI_FREQUENCY macro was wrong in 2 ways:
1) It was casting the result of the calculations to an u8, while i2c clk
rates are often >= 100Khz which won't fit in a u8, drop the cast.
2) It had an extra factor of 2 in the divider which neither the datasheet nor
the Linux driver have.

The comment for the default value was wrongly saying that m lives in
bits 4-7, while in reality it is in bits 3-6, as can be seen from the correct
shift by 3 used in i2c_init().

While at it remove the unused twsi_actual_speed variable.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
mvtwsi: Remove unnecessary twsi_baud_rate and twsi_slave_address globals

These are used only once, so their is no need to have them global.

This also stops mvtwsi from using any bss vars making it easier to use
before dram init (to talk to the pmic to set the dram voltage).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi: Use existing mvtwsi code for i2c master

Sunxi uses the same i2c controller, so re-use the existing code instead of
having our own duplicate code.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sun4i: Stop setting up the non-existing mbus register

sun4i does not have a mbus ccmu register.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sun5i: Drop unused AHB_CLK_SRC_AXI define

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-mmc: Drop unused CONFIG_MMC1_PG code

And while at it make the comment for the mmc3 gpio mux the same as for the
other mmc controllers.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-mmc: Dump debugging code

This syncs us with what is going upstream.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi: Makefile: Drop extra whitespace at end of file

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Revert "get_ram_size incorrectly returns long, should be unsigned long"

This reverts commit 7d8bc87e7e9b444a47715428df5c9a9792c92fd4.

This change has not been accepted upstream and 2G boards work fine without it,
so lets drop it.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sun4i: Remove Cubieboard_512 board

It uses the exact same memory timings as the regular cubieboard, it just
has lower density dram chips.

get_ram_size will detect that only 512 MB is available on these boards, so
they will work fine with the regular Cubieboard board config.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sun7i: Drop FAST_MBUS

We've several bug reports indicating that this causes stability issues,
so lets just drop it.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
cubieboard2: Drop dram clock to 432 MHz

We've several reports indicating that 480 MHz causes stability issues.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
ARM: HYP/non-sec: move switch to non-sec to the last boot phase

Having the switch to non-secure in the "prep" phase is causing
all kind of troubles, as that stage can be called multiple times.

Instead, move the switch to non-secure to the last possible phase,
when there is no turning back anymore.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: add a barrier after setting SCR.NS==1

A CP15 instruction execution can be reordered, requiring an
isb to be sure it is executed in program order.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: non-sec: reset CNTVOFF to zero

Before switching to non-secure, make sure that CNTVOFF is set
to zero on all CPUs. Otherwise, kernel running in non-secure
without HYP enabled (hence using virtual timers) may observe
timers that are not synchronized, effectively seeing time
going backward...

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: add missing HYP mode constant

In order to be able to use the various mode constants (far more
readable than random hex values), add the missing HYP and A
values.

Also update arm/lib/interrupts.c to display HYP instead of an
unknown value.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: add separate section for secure code

In anticipation of refactoring the HYP/non-secure code to run
from secure RAM, add a new linker section that will contain that
code.

Nothing is using it just yet.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: allow relocation to secure RAM

The current non-sec switching code suffers from one major issue:
it cannot run in secure RAM, as a large part of u-boot still needs
to be run while we're switched to non-secure.

This patch reworks the whole HYP/non-secure strategy by:
- making sure the secure code is the *last* thing u-boot executes
  before entering the payload
- performing an exception return from secure mode directly into
  the payload
- allowing the code to be dynamically relocated to secure RAM
  before switching to non-secure.

This involves quite a bit of horrible code, specially as u-boot
relocation is quite primitive.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: add generic ARMv7 PSCI code

Implement core support for PSCI. As this is generic code, it doesn't
implement anything really useful (all the functions are returning
Not Implemented).

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>