Now that we have a better understanding of what's causing the issue
that prevented entering FEL sometimes, we can adjust the workaround
code to a proper solution, i.e. skip over the problematic location.
Since the code amounts to less than a dozen ARM instructions, I've
decided to rewrite it as assembly code - fel-sdboot.S replaces the
former fel-sdboot.c.
The commit also includes a new binary (bin/fel-sdboot.sunxi) with
these changes.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Make fel-sdboot.sunxi usable on A64 and A80
This also fixes potential problems with older SoCs when using certain (cross-)toolchains. See the discussion of #42
The SCTLR bits are somewhat different because the V bit is set
to 0 on A64 (Low exception vectors, base address 0x00000000) and
the UNK bit (Reads of this bit return an UNKNOWN value) is also not
the same as on the other SoCs. So the SCTLR check can be relaxed.
Changes in v2:
- Because the SRAM A and SRAM C reside back-to-back in the address
space, it is possible to use 40 KiB of SRAM by the SPL for its
code+data+stack. So the FEL backup storage is moved from 0x18000
to 0x1A000 to support this.
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
This small bootable stub, which just passes control to the
FEL code in the BROM, needs to be adjusted to also support
Allwinner A64 and Allwinner A80 because the BROM is located
at a different address there.
The SD card boot has a very low priority on Allwinner A64, but
it at least has a higher priority than the SPI NOR Flash:
https://linux-sunxi.org/BROM#A64
So this patch may help to simplify the FEL mode activation on
devices, which are booting their firmware from the SPI NOR Flash.
Changes in v2:
- Use SCTLR.V to detect the exception vectors location as
suggested by Jens Kuske.
- Add a padding of 32 NOP instructions in the beginning as
a workaround for some strange failures.
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
This allows the SRAM section A2 to be exclusively used by
the OpenRISC core.
There are no substantial differences between H3 and A10/A13/A20.
It just has 64 KiB of SRAM starting at the address 0x0 instead
of 48 KiB.
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
This allows the SRAM section A2 to be exclusively used by
the OpenRISC core.
Regarding the potential U-Boot SPL size. The SRAM section A1
only has 32 KiB. But at least the stack can be set at the end
of the SRAM section B. Or runtime UCL or LZO decompression can
be used to unpack the SPL code to 0x24000-0x2FFFF and have
48 KiB of available space there.
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Reviewed-by: Bernhard Nortmann <bernhard.nortmann@web.de>
That would be a more appropriate name. And A31 is going to
implement this in a different way and give the SRAM back to
OpenRISC.
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Acked-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Previously the backup area was allocated at the address 0x8000.
This is not very good because it means that the U-Boot SPL can
only safely use memory at addresses 0x0000-0x7FFF (32 KiB). But
if we move the backup area to the end of the SRAM A4, this can
allow U-Boot SPL to use memory 0x0000-0x9FFF (40 KiB). The BROM
can't load such large SPLs from the SD card. But the SPL still
can move its stack up to the 40 KiB boundary or do UCL or LZO
decompression at runtime to squeeze more code into it.
This patch makes the sunxi-fel tool compatible with 40 KiB SPLs,
even though the current U-Boot releases do not use them yet.
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Acked-by: Bernhard Nortmann <bernhard.nortmann@web.de>
- Convert C++ style comments for a uniform coding style.
- Some small formatting adjustments.
- Change "sid" command to print ':' separators instead of spaces.
Apart from "sid" output, no functional changes involved.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Add DISCARD directives to the linker scripts and also -marm option
to GCC command line. Without this, certain toolchains may build
Thumb2 code by default. Also junk sections may be present in the
final binary and they need to be removed.
This helps at least when using the following Linaro toolchain:
gcc-linaro-5.1-2015.08-x86_64_arm-linux-gnueabihf.tar.xz
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Reviewed-by: Bernhard Nortmann <bernhard.nortmann@web.de>
"make binfiles" should allow building ARM binaries more easily.
Factor out common $(ARM_ELF_FLAGS).
Also rewrite some rules using $< and $@, to avoid repeating
filenames. And trim down on the number of rules using patterns
for objcopy (%.elf -> %.bin) and mksunxiboot (%.bin -> %.sunxi).
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
This patch makes use of the new aw_fel_readl_n() function to output
the first four 32-bit values (SID key) from an SoC-specific address.
The corresponding e-fuses may not necessarily start at the SID
"base" address, e.g. on H3/A83T they are at <base+0x200>.
Note: SoC support is currently incomplete. In particular, reading
the SID on A31(s) is unsupported. Accessing it there is complicated
by the fact that Allwinner moved this information from the SoC into
the PMIC/AXP221.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Squashed commit of the following:
commit 95f3614357446c4a35ec541bb2c21503c54d3fac
Author: Bernhard Nortmann <bernhard.nortmann@web.de>
Date: Fri Apr 8 09:10:17 2016 +0200
fel: Add support for multiple sequential readl/writel
There are cases where "long" reads/writes might be used to transfer
multiple values from/to sequential addresses.
When doing so, we can avoid having to setup and upload the entire
scratch buffer (ARM code) every time, by making the underlying
functions auto-increment the address on each invocation.
The patch implements this functionality, and maps the existing
aw_fel_readl() and aw_fel_writel() to special cases (count == 1).
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
commit 20ececdfc7f3c4070469a7b74ba77bb74e01f876
Author: Bernhard Nortmann <bernhard.nortmann@web.de>
Date: Fri Apr 8 09:00:20 2016 +0200
fel: Modify handling of command line args for "readl"/"writel"
Most other commands use their decoded argument values directly,
without storing them to local vars first. Also "writel" needs
an (argc > 3).
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
commit b4216371b97e9f1dd19f7fc2ce720b9cb8e2434e
Author: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Date: Sat Dec 19 08:22:26 2015 +0200
fel: Add "readl" and "writel" commands
The read/write operations done by FEL are not suitable for accessing
hardware registers. For example, trying to read a SID value using
the "read" or "hexdump" commands results in the following:
$ sunxi-fel hexdump 0x01c23800 4
01c23800: 87 00 00 00 __ __ __ __ __ __ __ __ __ __ __ __
Apparently, FEL tries to read data one byte at a time and this does
not always work correctly. Introducing new commands to explicitly
do 32-bit reads and writes helps:
$ sunxi-fel readl 0x01c23800
0x16254187
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Tested-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Doing certain operations may need uploading and executing code
on the device. For example, such operations right now are
reading/writing ARM CP15 coprocessor registers. Uploading the
code to the device is naturally overwriting some part of SRAM
as a side effect. Right now it is not a problem, because the
CP15 coprocessor registers are only accessed as part of uploading
and executing U-Boot SPL. They are nicely timed not to cause
problems and the temporary scratch area gets overwritten by
the SPL code anyway.
But if we decide to provide access to such operations via
command line interface, then any side effects may potentially
cause problems for the users. Consider the following scenario:
sunxi-fel clear 0x2000 0x100 \
advanced-command-which-uploads-and-executes-code \
hexdump 0x2000 0x100
The user may rightfully expect that clearing a buffer in SRAM
to zero and then reading it back should show all zero bytes.
But inserting advanced commands in the middle may cause data
corruption.
In order to resolve this problem, just move the scratch area
away from the 0x2000-0x5BFF addresses range. These particular
addresses are already known to the users as a safe place for
their bare metal expariments in FEL mode. The "sunxi-fel spl"
command is a special case though and it is expected to
overwrite data in this area too.
A possible alternative would be to just backup & restore data
in the scratch area. But this has some disadvantages:
1. Extra code in the sunxi-fel tool and extra roundtrips over
USB to do the backup/restore job.
2. If we allow the OpenRISC core to use the 0x2000-0x5C00
range in SRAM A1, then this becomes unsafe and racy
(we can't really backup & restore data without causing
a temporarily glitch for the currently running code on
the OpenRISC core).
To sum it up. With this patch we make it so that now the
0x2000-0x5BFF range is freely available for the users of the
sunxi-fel tool. The 0x1000-0x1FFF range is off limits (the
upper part of it is used by the FEL IRQ handler, the lower
part of it is reserved for internal use by the sunxi-fel
tool). The 0x0000-0x0FFF addresses range is reserved for
passing data from the SPL to the main U-Boot binary (via
the SPL header) and is also off limits.
Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Tested-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Bernhard Nortmann <bernhard.nortmann@web.de>
After eliminating all warnings, we can disallow them for future
builds. This is done by passing an additional "-Werror" flag
from the Travis build step. Introducing new warnings will cause
a (CI) build failure from now on.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
This is done by explicitly setting at least one member field
(preferably the one that gets tested for validity later),
instead of just using "{ 0 }".
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Commit 73c20eea7bf0f12795ab94685fbb98eda0cf2cce removed that symbol
from fel.c - this adds it back (in the Makefile) to address #22.
Caveat: This probably requires you to use "make OS=NetBSD". I have
currently no way of testing it; we're only checking Linux and OSX
builds.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
We'll be testing both gcc and clang builds on Linux. As for now,
Travis CI only supports clang for OSX - so exclude gcc currently.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
The nand-part.c code tries to re-read the partition tables
by issuing an ioctl(fd, BLKRRPART, NULL). This isn't available
on non-Linux platforms, e.g. Mac OS X.
Add preprocessor conditionals to prevent this from breaking
the build.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
For Linux, this requires additional #defines, see
https://gist.github.com/panzi/6856583#gistcomment-1656524
Placing those #defines into portable_endian.h would mean we
depend on the specific order of #includes (whatever pulls
in endian.h first, including other system includes). Avoid
this by using symbols provided "globally" via the Makefile.
Also nuke the _NETBSD_SOURCE definition in fel.c
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Our previous include file only supplied a very limited set of
wrapper redefinitions for platforms that define __APPLE__ (i.e.
Mac OS). In particular, some needed big endian conversions were
missing, causing "symbol(s) not found" errors when linking.
Instead of patching the existing file, let's do away with it
completely and replace it by something more sophisticated.
The portable_endian.h used is in the public domain, and was
taken from https://gist.github.com/panzi/6856583
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Commit 472ac4759df557c00248e557beb869f4fe7d75f7 introduced
a possible regression by relying on the availability of
libusb_strerror(). There are libusb versions out there _not_
offering this function, which breaks compilation.
Introducing a separate helper function allows us to work around
this, refactor existing code and have more streamlined error
reporting - avoiding the message string retrieval where needed.
The usb_error() function can also optionally abort execution
with a given exit code.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Move some lines so that the safeguards run (and exit, if needed)
before the normal output of header information.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
When declaring 'signed' values for section count and version
information in the script_bin_head structure, testing them to be
below certain thresholds (SCRIPT_BIN_*_LIMIT) is insufficient;
as 'negative' values like in "fexc-bin: script.bin: version:
-404840454.-1074397186.-1073906177" would still pass.
Fix this by making these member fields unsigned.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Gracefully shut down the FEL utility, instead of continuing
execution. This avoids a possible "ERROR: Allwinner USB FEL
device not found!" when doing a plain `./sunxi-fel` without
any arguments (and no suitable USB device connected).
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
The A80 has the V bit in SCTLR set to 0 because of the BROM
being at 0x00000000 now, so the SCTLR check has to be relaxed.
Signed-off-by: Jens Kuske <jenskuske@gmail.com>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
This workaround is necessary for A80, which sometimes
fails at reading DACR.
Signed-off-by: Jens Kuske <jenskuske@gmail.com>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
The aw_fel_process_spl_and_uboot() was missing a free() for the file
buffer. This patch also adds a proper libusb cleanup/shutdown.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
This patch forces relevant options to be placed at the beginning of
the command line, but also makes sure that their specific order does
not matter.
Currently this applies to "-p" (--progress) and "-v" (--verbose).
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Commit d99d59c introduces a bug when the "spl" command is used with a
file that contains a U-Boot binary. "spl" will now try to execute it,
while it's not supposed to. (The command should only start the SPL.)
This patch brings back the `uboot_autostart` flag, which is meant to
remain `false` for the "spl" command, and gets set by "uboot" only.
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
The meminfo example has been corrected to match the Makefile's
"sunxi-meminfo" target, and an example has been added for the
"sunxi-script_extractor" target.
Signed-off-by: Justin Swartz <justin.swartz@risingedge.co.za>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>