350 Commits

Author SHA1 Message Date
Bernhard Nortmann
99daba15e7 Move list declarations from common.h into a separate list.h
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-05-04 10:31:00 +02:00
Bernhard Nortmann
438620e832 travis-ci: Extend build matrix, disable email notifications
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>
2016-05-04 10:29:51 +02:00
Bernhard Nortmann
5507c1f8be Some markdown formatting for proper display of README.md
Also add badges for license and build status.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-05-03 22:24:20 +02:00
Bernhard Nortmann
a7659ab2f5 Rename README to display it as markdown
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-05-03 22:23:47 +02:00
NiteHawk
7b0541537a Merge pull request #40 from n1tehawk/travis-ci
Add continuous integration support (Travis CI), fix Mac OS X build
2016-05-03 08:09:40 +02:00
Bernhard Nortmann
ed94fc2fd4 nand-part: Avoid Linux-only ioctl() on other platforms
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>
2016-05-03 08:03:11 +02:00
Bernhard Nortmann
73c20eea7b Makefile: Have portable_endian.h properly expose all functions
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>
2016-05-03 08:02:09 +02:00
Bernhard Nortmann
d47c3a3649 Replace endian_compat.h with portable_endian.h
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>
2016-04-20 09:45:26 +02:00
Bernhard Nortmann
f3b60f43e3 fel: Introduce helper function for reporting libusb errors
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>
2016-04-20 09:45:26 +02:00
Bernhard Nortmann
6ade0af8d4 Add Travis CI configuration file
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-04-20 09:45:26 +02:00
Bernhard Nortmann
b59f4584f5 fel: Convert "needs_l2en" to boolean type
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-04-20 09:29:50 +02:00
Bernhard Nortmann
3acd9a9dc0 fel: Fix a possible format/conversion error in aw_write_buffer()
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-04-20 09:29:50 +02:00
Bernhard Nortmann
7d59d75eee fexc: Regroup code in script_decompile_bin()
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>
2016-04-20 09:29:50 +02:00
Bernhard Nortmann
ef545814de fexc: Improve script_decompile_bin() safeguards
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>
2016-04-20 09:29:50 +02:00
Bernhard Nortmann
a8054dfa9a fel: Remove surplus colons on perror() messages
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-04-20 09:29:50 +02:00
Bernhard Nortmann
b4aab6baec fel: Use initializers for aw_usb_request and aw_fel_request
instead of memset() and strcpy() to clear / assign member fields.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-04-20 09:29:50 +02:00
Bernhard Nortmann
499529966e fel: Simplify hexdump() single character output, using putchar()
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
2016-04-20 09:29:50 +02:00
Bernhard Nortmann
425278ac0d fel: Do a clean exit(0) after printing usage help
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>
2016-04-20 09:28:08 +02:00
Jens Kuske
b7e092ec3f fel: add fel spl support for Allwinner A80
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>
2016-03-21 19:33:21 +02:00
Jens Kuske
035167cb14 fel: only read MMU control registers if MMU is enabled
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>
2016-03-21 19:07:06 +02:00
Bernhard Nortmann
472ac4759d fel: support selection of specific USB bus and device number
See https://github.com/linux-sunxi/sunxi-tools/issues/37

The patch was originally inspired by
https://github.com/NextThingCo/sunxi-tools/commit/16386a7
and
https://github.com/NextThingCo/sunxi-tools/commit/47bafaf

It introduces a "--dev" (-d) option to specify the desired FEL
device. This is useful if multiple target devices are connected
to the same host.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2016-03-20 15:03:58 +01:00
Lourens Rozema
806030a4e6 fel: Add release USB interface to allow proper operation on Mac OS X.
Closes #24. See https://groups.google.com/forum/#!topic/linux-sunxi/sEJ1eTBoCvw

Tested-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2016-03-20 14:43:52 +01:00
Bernhard Nortmann
be1b4c7400 fel: fix memory leak, properly shut down USB library
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>
2015-12-17 02:00:57 +02:00
Bernhard Nortmann
887a0a7560 fel: unify handling of "prefix"-type command line arguments
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>
2015-12-17 02:00:50 +02:00
Bernhard Nortmann
4a57273df0 fel: bugfix - revert autostart change from d99d59c
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>
2015-12-17 02:00:45 +02:00
Justin Swartz
1fb413d0be README: Cross-compilation examples
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>
2015-12-16 08:44:32 +02:00
Justin Swartz
236e9f4ff4 Makefile: Add sunxi-script_extractor target
Signed-off-by: Justin Swartz <justin.swartz@risingedge.co.za>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-16 08:44:32 +02:00
Bernhard Nortmann
7755022252 fel: support updating the caption for "dialog --gauge"
This patch adds an "echo-gauge" command that is intended for use with
sunxi-fel's output piped into the dialog utility. "echo-gauge" will
output its string argument in a way that updates (i.e. overwrites)
the prompt text that dialog displays, so it's possible to change that
inbetween file transfers from sunxi-fel.

Example:
	sunxi-fel uboot ${UBOOT} \
		echo-gauge "Uploading kernel (1/2)" \
		write-with-gauge 0x42000000 ${KERNEL} \
		write 0x43100000 ${SCRIPT} \
		echo-gauge "Uploading rootfs (2/2)" \
		write-with-gauge 0x44000000 ${ROOTFS} \
		| dialog --gauge "" 6 70

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-16 08:20:46 +02:00
Bernhard Nortmann
6712eb84a0 fel: support FEL progress gauge via dialog utility
This patch adds some additional commands, and implements corresponding
progress callbacks that produce output for the 'dialog' utility:
http://invisible-island.net/dialog/dialog.html

The simple "*-with-gauge" just emits percentage numbers, line by line,
while "*-with-xgauge" outputs extended information to update the
dialog prompt. Both are meant for directly piping the output:
sunxi-fel write-with-gauge <...> | dialog --gauge "FEL upload" 6 70

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-16 08:20:46 +02:00
Bernhard Nortmann
3626803f64 fel: implement "write-with-progress" and "multiwrite"
The two new commands both imply that a (simple) progress bar
display is requested. "multi[write]" allows to upload a group
of files with a single command, resulting in their transfer
showing a common, 'overall' progress status.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-16 08:20:45 +02:00
Bernhard Nortmann
b3c02a0a55 fel: Add file_size() and factor out a reusable file_upload()
This patch moves some code out of the "write" handler, with the intention
to reuse it later for similar commands.

At the same time, it also discards the previous transfer rate output when
using "-v", as that has become redundant with the 'progress bar' display
available by "-p".

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-16 08:20:45 +02:00
Hans de Goede
55eec70cea script_extractor: Remove unnecessary size argument
The script_extractor tool before this commit used to take a size argument
on the cmdline, but the passed in size was only used in some places not
in others. Leading to a segfault if the passed in argument was not
exactly the same as SCRIPT_SIZE.

This commit drops the argument, so that script_extractor will just
work.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2015-12-08 13:05:20 +01:00
Bernhard Nortmann
2d258a30d8 fel: extend progress display with transfer rate and ETA
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-07 12:28:42 +01:00
Bernhard Nortmann
3f0584aaa7 fel: implement simple progress bar for larger transfers
Add "--progress" option and a progress bar display for FEL
transfers. This picks up on a suggestion from Alexander Kaplan
and the discussion at
https://groups.google.com/forum/#!topic/linux-sunxi/lz0oQBwjex0

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-07 12:28:37 +01:00
Bernhard Nortmann
447eb661a9 fel: extend usb_bulk_send() for progress updates
This patch adds a boolean parameter "progress" to several functions.
When set (true), it will cause usb_bulk_send() to notify the progress
framework, using progress_update() to convey the current transfer
status.

The feature gets enabled for the "write" command, and is forced
inactive in most other places, e.g. aw_fel_write_uboot_image().
Also, we specifically want the internal use of aw_fel_write() to
never use it.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-07 12:28:32 +01:00
Bernhard Nortmann
edc48b5e93 fel: refactor aw_fel_write()
This patch introduces a new function aw_write_buffer() to
allow a better distinction between FEL write operations.

aw_fel_write() is meant for "privileged" internal use, while
aw_write_buffer() now represents the preferred entry point
for user code like the "write", "fill" or "clear" commands.

There is some deliberate code duplication here that makes sense
when combined with the next patch, where the aw_usb_write()
call will differ. We want aw_fel_write() to enforce no progress
update/callback, while aw_write_buffer() will (optionally)
support it.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-07 12:28:27 +01:00
Bernhard Nortmann
70951fa99a fel: Introduce progress framework
This patch adds two new source files that will deal with code
related to progress callbacks and display. I have decided to
keep this separate, as there will be many smaller routines
involved, which otherwise would bloat fel.c unnecessarily.

For starters, let's also move the gettime() function there.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Reviewed-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-12-07 12:28:22 +01:00
Siarhei Siamashka
c32eeb88ff fel: Enable MMU on Allwinner-H3 to improve FEL transfer speed
When the CPU clock speed is set to 480 MHz by the U-Boot SPL,
the performance of 'sunxi-fel write' transfers to DRAM improves
from ~95 KB/s to ~510 KB/s.

When the CPU clock speed is set to 1008 MHz by the U-Boot SPL,
the performance of 'sunxi-fel write' transfers to DRAM improves
from ~180 KB/s to ~510 KB/s.

This means that the CPU is not a bottleneck for FEL transfers
anymore. Further performance improvements are possible by
increasing the AHB1 clock speed in the U-Boot SPL (up to
something like ~900 KB/s).

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Acked-by: Peter Korsgaard <peter@korsgaard.com>
2015-11-24 04:50:26 +02:00
Siarhei Siamashka
a275b246a4 fel: Support for enabling MMU after running SPL on new SoC variants
The BROM in newer SoC variants doesn't enable MMU by default anymore.
So in order to benefit from e4b3da2b17ee9d7c5cab9b80e708b3a309fc4c96
("fel: Faster USB transfers via 'fel write' to DRAM"), we need to
be able to enable it from the 'sunxi-fel' tool.

This patch can be interpreted as simply reverting the changes done
by Allwinner and bringing back the MMU support in roughly the same
way as it was before. That's why the values in the hardware
registers and the translation table entries replicate the A20 setup.

Additionally, the code is now more defensive and introduces new
"canary" checks for certain known magic values in the coprocessor
registers in order to safeguard against any unpleasant surprises.

MMU tuning for A80 and A64 will probably need a more sophisticated
setup with a second level page table. Because both the SRAM and
the BROM reside in the same 1MB section there and we need finer
granularity. In other words, enabling the MMU on A80 and A64 is
not supported yet.

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Acked-by: Peter Korsgaard <peter@korsgaard.com>
2015-11-24 04:50:26 +02:00
Siarhei Siamashka
d971b08e5d fel: Helper functions for reading/writing ARM coprocessor registers
This helps to reduce code duplication if we want to read and write
many different kinds of coprocessor registers.

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Acked-by: Peter Korsgaard <peter@korsgaard.com>
2015-11-24 04:50:26 +02:00
Bernhard Nortmann
a9cb1c4c66 sunxi-tools: make use of proper boolean data types
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Peter Korsgaard <peter@korsgaard.com>
2015-11-19 18:04:53 +01:00
Bernhard Nortmann
d99d59c058 sunxi-tools: some trivial fixes
- get rid of double includes
- fix U-Boot source reference
- get rid of "uboot_autostart" variable

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Peter Korsgaard <peter@korsgaard.com>
2015-11-19 18:04:48 +01:00
Peter Korsgaard
9bf1de0ad8 Makefile: use force option when creating symlinks
So it doesn't error out if the symlink already exists (E.G. is pointing to
the old name).

Also add the -n option for consistency with the install target.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
2015-10-27 06:36:46 +02:00
Ian Campbell
0f69187846 Makefile: Add an install rule
Allow for separate installation of tools and target-tools, to aid in packaging.

By default everything the tools are installed into /usr/local/bin but this can
be overridden using PREFIX= or BINDIR= on the make invocation.

To enable this it was necessary to split fex2bin and bin2fex out from $(TOOLS)
into $(FEXC_LINKS), because install(1) does not seem to have a mode which
preserves symlinks so it needs to be done separately.

Supports DESTDIR to allow for convenient installation into a staging dir for
distro packaging convenience.

Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Acked-by: Peter Korsgaard <peter@korsgaard.com>
2015-10-23 23:20:41 +03:00
Ian Campbell
bf4ec9a017 Makefile: Split out target tools rules
Target tools are those which are only useful on a target sunxi system (i.e.
which probe hardware etc).

Currently this is only sunxi-pio. At first I thought sunxi-nand-part might be
included, but I think that is useful on NAND images as well as actual devices.

This will allow for easier packaging, by letting packagers only include the
target tools when building for a suitable ARM architecture.

Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Acked-by: Peter Korsgaard <peter@korsgaard.com>
2015-10-23 23:20:41 +03:00
Ian Campbell
f1cb74d828 Makefile: Prefix most tools with sunxi-
Several of the tools here are too generic and/or short for distro packaging
purposes (which like to try and avoid naming clashes in $PATH). Prefix the
following with "sunxi-":
  - fexc
  - bootinfo
  - fel
  - pio
  - meminfo

Do not prefix any of the fel "payloads" or raw binaries since they would not
normally be installed in $PATH.

Do not prefix "phoenix_info", since "phoenix" already seems like an appropriate
prefix for this particular tool.

Update in-tree callers, README and .gitignore accordingly.

Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Acked-by: Peter Korsgaard <peter@korsgaard.com>
2015-10-23 23:20:41 +03:00
Bernhard Nortmann
6cc91f1062 fel: add a mechanism to provide boot information via FEL
This patch makes use of a new sunxi SPL header format, where
fields for passing data to U-Boot are reserved. This allows the
"fel" utility to provide specific pieces of information by
setting these fields (which will be evaluated by U-Boot then).

For now, we provide the memory location of the boot script file
(boot.scr) this way. A suitably modified U-Boot can adjust the
boot process accordingly and will auto-execute the script.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-10-03 08:24:26 +03:00
Bernhard Nortmann
e324df3b79 fel: implement persistent sram_info information
Information about the SoC-specific memory layout may be required across
several places in the fel utility code. To avoid having to retrieve this
information repeatedly, this patch modifies the aw_fel_get_sram_info()
function to cache its result (via an internal static pointer).

This makes it safe to call aw_fel_get_sram_info() wherever needed, while
avoiding additional aw_fel_get_version() lookups, and potential surplus
"no 'soc_sram_info' data for your SoC" warnings.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-10-03 08:24:01 +03:00
Bernhard Nortmann
3048ebf864 fel: refactor image type detection/query
This patch moves retrieving the image header type into a function
of its own. The idea is that fel "write" can and will also make
use of this function to detect boot scripts (by IH_TYPE_SCRIPT).

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-10-03 08:23:54 +03:00
Bernhard Nortmann
568c7a0e81 fix compiler warnings due to deprecated _BSD_SOURCE
With glibc 2.20 (and newer), defining _BSD_SOURCE (only)
will now generate compiler warnings similar to:

/usr/include/features.h:148:3: warning: #warning "_BSD_SOURCE
and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]

See the glibc 2.20 release notes, https://lwn.net/Articles/611162/.

This patch adds the required _DEFAULT_SOURCE.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
2015-09-13 23:56:46 +03:00