514 Commits

Author SHA1 Message Date
Siarhei Siamashka
3c9bc29f39 fel: Add SPI flash programmer implementation
Using the new AAPCS function remote execution support, add support to
read from and write to SPI flash connected to a device.
This allows flashing boot code to a device.

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
[Andre: adjust to upstream changes]
Signed-off-by: Andre Przywara <osp@andrep.de>
2018-07-09 09:16:24 +01:00
Siarhei Siamashka
1091f3ac6b fel: Support uploading & executing ARM AAPCS functions on the device
This patch adds a wrapper script, which can automatically compile
and wrap a small C function, taking care of all the necessary
function arguments marshalling.

The functions 'aw_fel_remotefunc_prepare/aw_fel_remotefunc_execute'
allow using such functions in the sunxi-fel tool to get this code
executed remotely on the device.

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
[Andre: adjust to match upstream changes]
Signed-off-by: Andre Przywara <osp@andrep.de>
2018-07-09 09:16:24 +01:00
Icenowy Zheng
d0f2fbb8a1 uart0-helloworld-sdboot: add support for H6
Allwinner H6 SoC has a totally different memory map and different clock
control unit with other SoCs.

Add support for it in uart0-helloworld-sdboot.

To avoid writing blindly into the device MMIO area first (for triggering
the SRAM version register), we query the known content of some GIC register
to verify we are looking at an H6 memory map.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Signed-off-by: Andre Przywara <osp@andrep.de>
2018-07-09 09:16:24 +01:00
Icenowy Zheng
4acf2a922f uart0-helloworld-sdboot: allow flexible GPIO/UART0 base address
Allwinner A80 and H6 SoC has totally different memory map with other
Allwinner SoCs, and so the GPIO/UART0 base addresses are different on
these SoCs.

Use a static variable to store the base address, to fit these SoCs with
different memory map.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Signed-off-by: Andre Przywara <osp@andrep.de>
2018-07-09 09:16:24 +01:00
Icenowy Zheng
ed54b135c1 fel: add SoC info for H6 SoC
Allwinner H6 is a new SoC with its memory map changed.

Add its SoC info, including SRAM addresses and SID address.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Signed-off-by: Andre Przywara <osp@andrep.de>
2018-07-09 09:16:24 +01:00
Andre Przywara
1082b1683f pio: add missing return statement
main() should return 0 if execution was successful.

Signed-off-by: Andre Przywara <osp@andrep.de>
2018-07-09 09:16:24 +01:00
Andre Przywara
7e8be239f8 pio: fix typo in help message
Signed-off-by: Andre Przywara <osp@andrep.de>
2018-07-09 09:16:24 +01:00
Maxime Ripard
ef802e4952
fel: Check for the U-Boot header CRC
A U-Boot image has two CRCs, one to cover the data and that we already
check, and one to cover the header.

Since we're not checking the latter, let's make sure it's the case.

Tested-by: Frank Kunz <mailinglists@kunz-im-inter.net>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2017-11-06 11:43:55 +01:00
Maxime Ripard
e753821ea0
fel: Check the U-Boot's CRC instead of its size
The current code checks that the transferred size is matching the size
reported in the image header.

Unfortunately, the transferred image might be padded, which doesn't change
anything at the functional level, but will make that check trigger since
the actual image will be smaller than the transferred data.

Change that logic to first check that the transferred size isn't less that
the header image size, which will still be an error, and then check for the
CRC of the image itself. This will prove to be an more robust integrity
check than what we have right now anyway.

The CRC used in the image header is the CRC32 algorithm, that is
implemented in the zlib, which is installed on most devices on the planet,
so we can just use that implementation instead of rolling our own.

Tested-by: Frank Kunz <mailinglists@kunz-im-inter.net>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2017-11-06 11:43:36 +01:00
Maxime Ripard
b1bbc431c3
fel: Use U-Boot's header structure
The U-Boot image parsing code so far has been relying on hardcoded offsets
directly into the image's buffer.

While that works, it's a bit obscure and isn't practical to understand and
modify.

Let's add the structure definition, and convert the code to use it.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2017-11-06 11:42:35 +01:00
Chen-Yu Tsai
cd9e6099e8 Merge pull request #102 from Icenowy/spl-v2
fel: enable support for v2 SPL
2017-08-15 11:34:41 +08:00
Icenowy Zheng
c8ada3849e fel: enable support for v2 SPL
The version 2 of SPL added the possibility to add a device tree name in
the header, with adding some pad and using a reserved word.

As FEL boot currently doesn't need the device tree name, directly raise
the maximum supported version number to 2.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
2017-04-29 18:56:43 +08:00
Siarhei Siamashka
d9b1d7e7df Merge pull request #99 from ssvb/20170228-smc-workaround
fel: SMC workaround for the Allwinner SoCs with the secure bit set in eFUSE
2017-03-31 10:06:34 +03:00
Siarhei Siamashka
275827ad73 fel: Enable the SMC workaround for H3/H5/A64/H64
Use a hardwired L.NOP instruction from the OpenRISC reset
vector as a way to check if the workaround is necessary.
Because these L.NOP instructions are guaranteed to be there
and are read-only, this is the most reliable non-invasive test.

Reading SID would be less reliable because it is one-time
programmable and theoretically may be set to zero on some boards.

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2017-02-28 21:10:44 +02:00
Andre Przywara
8c45b33e22 fel: SMC workaround to enter "secure boot" FEL mode on some SoCs
If an SoC has the "secure boot" fuse burned, it will enter FEL mode in
non-secure state, so with the SCR.NS bit set. Since in this mode the
secure/non-secure state restrictions are actually observed, we suffer
from several restrictions:
- No access to the SID information (both via memory mapped and "register").
- No access to secure SRAM (SRAM A2 on H3/A64/H5).
- No access to the secure side of the GIC, so it can't be configured to
  be accessible from non-secure world.
- No RMR trigger on ARMv8 cores to bring the core into AArch64.
Those limitations make a board pretty useless for many applications.

However it has been found out that a simple "smc" call will immediately
return from monitor mode, but with the NS bit cleared, so access to all
secure peripherals is suddenly possible.

Add all the necessary support code for doing a runtime check and
activating this workaround. Affected SoCs need to have the "smc"
workaround enabled in their soc_info struct.

Signed-off-by: Andre Przywara <osp@andrep.de>
["sunxi-fel smc" command changed to automatic detection by Siarhei]
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2017-02-28 21:08:47 +02:00
Bernhard Nortmann
7128c73abf fel: Support "-h" and "--help" options
Closes #96

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2017-02-13 16:21:52 +01:00
Bernhard Nortmann
3eb763588e fel: Safeguard against calling FEL read/write with zero bytes length
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2017-02-11 14:04:40 +01:00
Bernhard Nortmann
d5f5d5d1ad Makefile: Improve auto-detection of ARM cross compiler
This patch moves the scan for an ARM gcc into a separate shell
script. To prevent against recursion issues, the new script adds
"-maxdepth 1" to the find invocation; and it now also correctly
handles directories in $PATH that contain spaces in their name.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2017-02-11 14:02:33 +01:00
Priit Laes
5e8ea17382 Make sure that awk patterns are not locale-specific.
Locales can influence conversion, so make sure we all use the same one.

Signed-off-by: Priit Laes <plaes@plaes.org>
2017-02-11 14:01:40 +01:00
Priit Laes
baa1520714 Hide error messages about nonexisting directories when scanning $PATH
$PATH can contains directories that do not exist, so hide error messages
about those entries.

Signed-off-by: Priit Laes <plaes@plaes.org>
2017-02-11 14:01:40 +01:00
NiteHawk
7252ae1b75 Merge pull request #94 from n1tehawk/20170126_thunks
Move thunk code to a dedicated subdirectory, implement fel_clrsetbits_le32()
2017-02-03 11:28:04 +01:00
Bernhard Nortmann
0858b7105c fel: Implement fel_clrsetbits_le32() helper
This function provides bitwise clear/set operations on 32-bit words
via FEL. It may help with implementing future functionality, where
ARM register manipulations often involve such bit level access.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2017-01-27 23:03:18 +01:00
Bernhard Nortmann
56ef320ad6 thunks: Add assembly sources for some more thunks
These might be useful in case the code requires maintenance/changes.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2017-01-27 23:03:18 +01:00
Bernhard Nortmann
55253760e5 thunks: Adjust build system for ARM thunk .h
"make headers" (which in turn invokes "make -C thunks/" should now
build the include files via awk, avoiding the need for ruby.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2017-01-27 23:03:18 +01:00
Bernhard Nortmann
7ad5f454db Move thunk code / snippets to a dedicated subdirectory
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2017-01-27 23:03:18 +01:00
Bernhard Nortmann
ce583ece03 Makefile: Improve auto-detection of ARM cross compiler
Try an 'educated guess' for a suitable toolchain if no explicit
CROSS_COMPILE was set (but still default to "arm-none-eabi-").

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2017-01-27 23:03:13 +01:00
NiteHawk
e125a9da47 Merge pull request #88 from n1tehawk/20161109_copyl
fel: Implement memory copy operations and "memmove" command
2017-01-21 11:11:07 +01:00
Bernhard Nortmann
95d8d23989 fel: Remove obsolete fel-pio (thunk) code
This functionality is now available via "sunxi-fel memmove", so
change the fel-gpio script accordingly and remove the thunk code.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-30 12:35:24 +01:00
Bernhard Nortmann
37e9965b1e fel: Add "memmove" command
This also obsoletes fel-copy.c - for details see issue #78.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-28 14:20:02 +01:00
Bernhard Nortmann
81f54c0c27 fel_lib: Add generic memcpy() functions and fel_memmove() wrapper
The functions represent ARM "thunk" code that can be invoked via
FEL to execute arbitrary memory copy operations on the target
device, i.e. they deal with overlap and unaligned access. Where
possible, the copy operation will use (32-bit) word transfers,
otherwise it falls back to bytewise copying.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-28 14:20:02 +01:00
Bernhard Nortmann
1e219c0bb9 Makefile: Use uname for OS detection on *nix platforms
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-28 13:47:30 +01:00
NiteHawk
2f6e069790 Merge pull request #91 from n1tehawk/20161220_sid-fix
SID fix / H3 workaround
2016-12-28 13:44:59 +01:00
Bernhard Nortmann
382bb4c2eb uart0-helloworld: Refactor SID fix
Also includes an updated uart0-helloworld-sdboot.sunxi binary.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-28 13:38:56 +01:00
Icenowy Zheng
4d62e7cb63 uart0-helloworld-sdboot: differ H2+ with H3
With fixed SID reading routine, it's now possible to differ H2+ with H3
with SID.

Tested on an Orange Pi One and an Orange Pi Zero.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
2016-12-28 13:30:09 +01:00
Bernhard Nortmann
fcde876250 fel: [Fixup] Use fel_get_sid_root_key() routine for SID retrieval
The patch also introduces a "sid-register" command for diagnostic
purposes. It allows to use/enforce the workaround method for other
SoCs, to check if there are any inconsistencies with the values
read from memory.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-28 13:30:09 +01:00
Bernhard Nortmann
a3ce5f9f76 fel_lib: Implement thunk code for register-based retrieval of SID
The new function fel_get_sid_registers() uses ARM code for register
access to the SID root key. This is necessary to retrieve correct
values for certain SoCs, e.g. when not using this approach the H3
has been observed to return 'mangled' values (when reading SID from
memory).

See https://groups.google.com/forum/#!topic/linux-sunxi/ynyIP8c61Qs

The FEL library provides a uniform fel_get_sid_root_key() wrapper
that will automatically use the workaround method for SoCs that
are tagged accordingly - so the application program does not have
to bother with selecting memory vs. register-based access.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-28 13:30:09 +01:00
Icenowy Zheng
463cd64cbd fel: workaround H3 SID issue
H3 SID controller has some bug, that makes the initial value at
0x01c14200 wrong.

This commit workarounds this bug by reading them with register access
first.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
Reviewed-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-28 13:30:09 +01:00
Bernhard Nortmann
5c501c5bb8 soc_info: Split sid_addr into sid_base + sid_offset
This is a preparatory step. Instead of using memory-based access,
we might want to retrieve SID keys (e-fuses) via SID registers.
For this, it's convenient if the plain base address is available.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-28 13:29:47 +01:00
NiteHawk
9223a10aad Merge pull request #92 from Icenowy/v3s
Add support for Allwinner V3s, which is similar to A10/A13/A20 in terms of SRAM mapping and SID address.
2016-12-28 13:26:18 +01:00
Icenowy Zheng
e96abe7234 uart0-helloworld-sdboot: add support for V3s SoC
Add the SoC ID and UART0 pinmux for V3s.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
2016-12-28 17:50:37 +08:00
Icenowy Zheng
8361dac255 fel: Add SOC ID, SRAM info and SID address for V3s
The V3s SoC looks like A10/13/20 in SRAM mapping and SID address.

Add support for it.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
2016-12-28 17:45:03 +08:00
NiteHawk
24be7518cb Merge pull request #87 from n1tehawk/contrib
fel: Improve on handling invalid options
2016-12-21 14:10:33 +01:00
Bernhard Nortmann
0146dd4ae5 README: Add --verbose to the sunxi-fel example command
This is to make sure that users get notified accordingly if the
"sunxi-fel --list" doesn't find any FEL devices.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-13 14:10:14 +01:00
Bernhard Nortmann
1d2182c4f5 fel: Improve on handling invalid options
For unknown option-style arguments (starting with '-'), exit after
printing an error message.

This avoids situations where sunxi-fel would not report incorrect
options (with no FEL device attached/detected) and fail with
"Allwinner USB FEL device not found" instead, which is undesirable.

TODO: Might have to eventually migrate this to some better argument
parsing, e.g. getopt(3) or something similar.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-13 12:55:07 +01:00
Bernhard Nortmann
e31cbf8625 Cosmetic changes
fel:
- Minor review of ARM scratch code
- POSIX conformance: Use nanosleep() instead of deprecated usleep()

README:
- revert Unicode dash to standard ASCII

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-07 08:19:13 +01:00
Bernhard Nortmann
610ca15715 common.h: Rename errf() to pr_error(), add pr_fatal()
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-07 08:15:03 +01:00
Bernhard Nortmann
b5ba2d3b49 README: Improve sunxi-fel help with a few hints
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-01 17:07:09 +01:00
Bernhard Nortmann
445b1747e5 soc_info: Iterate over soc_info_table with pointer, not by index
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-01 16:24:07 +01:00
NiteHawk
e9c3ff145a Merge pull request #47 from n1tehawk/usblib
Make use of FEL library to implement device enumeration and selection by SID
2016-12-01 12:29:43 +01:00
Bernhard Nortmann
448fa5f74c fel: Add "--sid" option to select FEL device by SID
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-01 11:56:12 +01:00