479 Commits

Author SHA1 Message Date
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
Bernhard Nortmann
beeb8ec30d fel: Add a --list option to enumerate FEL devices
"./sunxi-fel --list" enumerates Allwinner USB devices that
are in FEL mode. For each device detected, the SoC name/ID
and - if available - the SID key will be printed to stdout.
The utility then exits with status code 0 (upon success),
or 1 if no devices were found.

The current implementation treats the list feature as an option,
to be able to handle it *before* the first attempt to call
feldev_open() - which could fail (with no FEL devices connected).
However, a "list" alias is available for users who expect this
to be 'command' syntax, so "./sunxi-fel list" works too.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-12-01 11:55:49 +01:00
Bernhard Nortmann
31164dc74f fel_lib: Add the ability to retrieve a list of FEL devices
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 14:45:36 +01:00
Bernhard Nortmann
dfc93db131 fel_lib: Add a human-readable SoC name field to the device handle
open_fel_device() will automatically provide this member field,
based on the SoC ID from FEL/BROM version data. The field will
either receive a human-readable identifier, or the ID in 4-digit
hexadecimal representation (for unknown SoCs).

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 14:45:36 +01:00
Bernhard Nortmann
feccad1391 fel: Move readl/writel code over to fel_lib
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 14:22:09 +01:00
Bernhard Nortmann
62daa36f4d fel_lib: Provide BROM version and SoC information via device handle
The feldev_handle struct returned by feldev_open() will now contain
this additional data, so the main application no longer needs to care
about retrieving that.

aw_fel_get_version() has thus become a static (= 'private') function.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 14:22:09 +01:00
Bernhard Nortmann
36978e3e44 fel_lib: Arrange for auto-initialization on first open_fel_device()
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 14:22:09 +01:00
Bernhard Nortmann
aaa677d552 fel: Factor out a new FEL library
The FEL utility had accumulated enough (mostly USB-related)
"low-level" code to justify moving that to a separate code unit.
This will allow us to keep better focus on the higher level
functionality in fel.c.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 14:22:09 +01:00
Bernhard Nortmann
ea3f7fee3d fel: Rework some of the USB functions' logic
This moves claiming / releasing the interface into the respective
"open" / "close" functions. The USB code in main() is now trimmed
down to:

feldev_init();
handle = open_fel_device(...);
feldev_done(handle);

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 14:22:09 +01:00
Bernhard Nortmann
edf6d6c5e6 fel: Eliminate 'global' vars, switching to their handle counterparts
We move USB endpoint detection into the feldev_claim() routine, so
higher level code is no longer involved with that. Also make use of
the "detached" flag within feldev_handle, instead of relying on an
isolated variable.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 14:22:09 +01:00
Bernhard Nortmann
1c8f81aa86 fel: Modify existing USB interface to use a new "FEL device" type
This enables us to move forward to a cleaner implementation,
where the "core" fel.c code will become independent of direct
libusb usage. After moving USB code to a separate module,
in the end the libusb handle could become an 'opaque' field of
feldev_handle.

The "device" handle might also be extended later, to provide
(FEL) version data and SoC-specific information (chip ID, SRAM
info, human-readable name).

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 14:22:09 +01:00
Bernhard Nortmann
85943dfa8f (Fix permissions on autoversion.sh) 2016-11-29 14:07:51 +01:00
Bernhard Nortmann
60ea132fcc Prepare "point" release tag (v1.4.2)
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 13:59:21 +01:00
Bernhard Nortmann
384ff64734 portable_endian.h: A more uniform fix for the various BSD flavours
See pull requests #59 and #83.

It looks like various BSD derivates have adopted the more common naming
conventions for the endian conversion macros, which means that we would
attempt to redefine them without need (potentially even to 'historic'
names that no longer exist).

Try to avoid this by properly checking for existing functions first.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-29 13:50:09 +01:00
Chen-Yu Tsai
4c4111034f fel: Add SID register address for A80
The SID block in the A80 is at 0x01c0e000, with the e-fuses we care
about at offset 0x200 within the block.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
2016-11-29 13:47:39 +01:00
Siarhei Siamashka
40a8f5299e Merge pull request #86 from wens/r40
R40 support for fel and uart0-helloworld
2016-11-29 09:43:26 +02:00
Chen-Yu Tsai
e480633927 uart0-helloworld: Add support for R40
The R40 is the same as the A20 for all intents and purposes of
uart0-helloworld.

Add R40's SOC ID.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
2016-11-29 15:23:11 +08:00
Chen-Yu Tsai
bbfcf117bb fel: Add SOC ID, SRAM info and SID address for R40
The R40 is marketed as the successor to the A20. The SRAM layout is the
same as the A20, but there doesn't seem to be a secure SRAM block.

The SID block is at a completely different address. The layout is the
same as the newer SoCs, with the e-fuses at an offset of 0x200.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
2016-11-29 15:21:17 +08:00
Bernhard Nortmann
8e53d2bf9a fel: Add fel_readl_n() and fel_writel_n() wrappers
These functions solve the problem that large readl/writel
transfers might be limited by insufficient (scratch) buffer
size. To solve this, chunks of no more than LCODE_MAX_WORDS
get transferred individually.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-19 16:49:55 +01:00
Bernhard Nortmann
c4389988aa fel: Rework aw_fel_(read|write)l_n code
This patch reduces on FEL protocol overhead for the 'multiple'
readl/writel transfers (functions that do word-aligned memory
access on the SoC). The ARM "scratch" code now takes a word count
and is able to work with buffered data, so the host is no longer
required to transfer single words in a piecemeal fashion.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-19 16:49:34 +01:00
Bernhard Nortmann
93a26d58ad uart0-helloworld: Refactor SoC detection
Besides having fewer lines of code, the #define macros should
also prevent users from accidentally using these names without
braces (i.e. as function pointers). Instead, this will cause
compiler errors now.

soc_info.c: add "A10s" label in comment for SoC ID 0x1625.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-16 17:37:50 +01:00
Bernhard Nortmann
b8e3a00323 README: add a badge to display commit count since release
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-16 17:37:50 +01:00
Bernhard Nortmann
8640291376 fel: Factor out SoC information (and SRAM buffers) retrieval
While at it, modify the former "sram_info" identifiers
to carry a broader "soc_info" meaning.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-13 21:33:58 +01:00
Bernhard Nortmann
6457c36d39 README: political correctness
Nowadays the term "hacking" has gained increasinly negative
connotations. We don't want people to get a wrong impression
and/or fancy ideas, so remove it.

While at it, also get rid of the emphasis on A10.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-13 21:33:49 +01:00
Bernhard Nortmann
8445d71f4e unify-fex: Use int64_t and portable format specifiers for its output
Otherwise we could run into ambiguities with "long long",
and Windows compilation is likely to bail out as it might
not understand "%ll".

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-13 15:56:32 +01:00
NiteHawk
dfce2034df Merge pull request #53 from n1tehawk/20160530_fextest
Extend continous integration by adding tests framework
2016-11-13 15:27:37 +01:00
Bernhard Nortmann
f957f89d21 fextest: Add a dedicated rule for (CI-)testing sunxi-boards
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-12 13:53:11 +01:00
Bernhard Nortmann
6ec3876b55 tests: Improve code coverage by testing corner cases
This patch adds shell scripts that deliberately go through some
extra program invocations, e.g. erroneous use of fex2bin. The goal
of these test cases is to improve on code (branch) coverage.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-12 13:51:38 +01:00
Bernhard Nortmann
cd5a0a3303 tests: Improve on testing fexc
After all .fex files can be successfully compiled, let's also
test the opposite direction by decompiling the resulting .bin.
The output then has to pass an automated diff against the source
.fex (transformed via some preprocessing with "unify-fex").

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-12 13:38:40 +01:00
Bernhard Nortmann
dd1882c7d7 travis-ci: Add and activate "make check" build step
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-12 13:38:40 +01:00
Bernhard Nortmann
5cbb0c91a4 tests: Introduce a basic testing framework
All tests should go into the new "tests" subdirectory. The idea is
that the separate Makefile in that directory will get invoked via
a top-level "make check".

The tests/Makefile should then take care of running all available
tests, returning an appropriate exit status. Future tests may be
functional, examine code metrics (coverage analysis), or both.

For a start, I'd simply like to check that sunxi-fexc is able to
properly compile all the .fex files from linux-sunxi/sunxi-boards.

(Note: This currently FAILS and will probably require adjustments
to both sunxi-tools and the .fex repository. To work around this,
for now I'm applying patches to fix sunxi-boards.)

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-12 13:38:40 +01:00
Bernhard Nortmann
d3e860b075 fel: Lower timeout to a more practical value
The previous timeout of 60 seconds was mostly based on scenarios
where large ("write") transfers take place. But it could easily
become annoying if users are awaiting completion of simpler
commands like "read" or "hexdump", and for some reason FEL fails
to respond.

Therefore I've decided to lower the timeout value to 10 seconds,
adjust the maximum chunk size accordingly and - while at it -
improve the source comments documenting their relationship.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-11 21:42:54 +01:00
NiteHawk
dc1b5889c3 Merge pull request #81 from n1tehawk/20161110_h5
Add initial H5 support in sunxi-fel and uart0-helloworld-sdboot.sunxi
2016-11-11 13:27:19 +01:00
NiteHawk
29c636211e Merge pull request #80 from n1tehawk/contrib
fexc: Fix .bin header treatment, improve .fex parser
2016-11-11 12:31:37 +01:00
Bernhard Nortmann
2e6697b2bb fexc: Default unquoted values to string type
Vendor-provided .fex files have repeatedly shown key-value pairs
(assignments) where the value is an identifier-style string *not*
surrounded by double quotes. The corresponding .bin files confirm
that such values end up as "string" type entries.

So far, our .fex parser has choked on these values. The commit
changes this behavior and treats them as strings now, to allow
processing 'original' .fex without adjustments.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-11 12:27:03 +01:00
Icenowy Zheng
acd958626d uart0-helloworld: port to H5
Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
Reviewed-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-11-11 01:34:31 +01:00