pages tagged sunxiijc's bloghttp://www.hellion.org.uk/blog/tags/sunxi/ijc's blogikiwiki2014-07-21T18:10:23Zsunxi-tools now available in Debianhttp://www.hellion.org.uk/blog/posts/sunxi-tools-in-debian/2014-07-21T18:10:23Z2014-07-21T18:10:23Z
<p>I've recently packaged the <a href="http://linux-sunxi.org/Sunxi-tools">sunxi
tools</a> for Debian. These are a set
of tools produce by the <a href="http://linux-sunxi.org/Main_Page">Linux Sunxi
project</a> for working with the
<a href="http://allwinner.com/">Allwinner</a> "sunxi" family of processors. See
the <a href="http://packages.debian.org/sunxi%2Dtools">package page</a> for details. Thanks to
Steve McIntyre for sponsoring the initial upload.</p>
<p>The most interesting component of the package are the tools for
working with the Allwinner processors' <a href="http://linux-sunxi.org/FEL">FEL
mode</a>. This is a low-level processor mode
which implements a simple USB protocol allowing for initial
programming of the device and recovery which can be entered on boot
(usually be pressing a special 'FEL button' somewhere on the
device). It is thanks to FEL mode that most sunxi based devices are
pretty much unbrickable.</p>
<p>The most common use of FEL is to <a href="http://linux-sunxi.org/FEL/USBBoot">boot over
USB</a>. In the Debian package the
<code>fel</code> and <code>usb-boot</code> tools are named <code>sunxi-fel</code> and <code>sunxi-usb-boot</code>
respectively but otherwise can be used in the normal way described on
the sunxi wiki pages.</p>
<p>One enhancement I made to the Debian version of <code>usb-boot</code> is to
integrate with the <a href="http://packages.debian.org/u%2Dboot">u-boot</a> packages to allow you to easily
FEL boot any sunxi platform supported by the Debian packaged version
of u-boot (currently only Cubietruck, more to come I hope). To make
this work we take advantage of <a href="https://wiki.debian.org/Multiarch">Multiarch</a> to install the
<a href="https://wiki.debian.org/ArmHardFloatPort">armhf</a> version of u-boot (unless
your host is already armhf of course, in which case just install the
u-boot package):</p>
<pre><code># dpkg --add-architecture armhf
# apt-get update
# apt-get install u-boot:armhf
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
u-boot:armhf
0 upgraded, 1 newly installed, 0 to remove and 1960 not upgraded.
Need to get 0 B/546 kB of archives.
After this operation, 8,676 kB of additional disk space will be used.
Retrieving bug reports... Done
Parsing Found/Fixed information... Done
Selecting previously unselected package u-boot:armhf.
(Reading database ... 309234 files and directories currently installed.)
Preparing to unpack .../u-boot_2014.04+dfsg1-1_armhf.deb ...
Unpacking u-boot:armhf (2014.04+dfsg1-1) ...
Setting up u-boot:armhf (2014.04+dfsg1-1) ...
</code></pre>
<p>With that done FEL booting a cubietruck is as simple as starting the
board in FEL mode (by holding down the FEL button when powering on)
and then:</p>
<pre><code># sunxi-usb-boot Cubietruck -
fel write 0x2000 /usr/lib/u-boot/Cubietruck_FEL/u-boot-spl.bin
fel exe 0x2000
fel write 0x4a000000 /usr/lib/u-boot/Cubietruck_FEL/u-boot.bin
fel write 0x41000000 /usr/share/sunxi-tools//ramboot.scr
fel exe 0x4a000000
</code></pre>
<p>Which should result in something like this on the Cubietruck's serial
console:</p>
<pre><code>U-Boot SPL 2014.04 (Jun 16 2014 - 05:31:24)
DRAM: 2048 MiB
U-Boot 2014.04 (Jun 16 2014 - 05:30:47) Allwinner Technology
CPU: Allwinner A20 (SUN7I)
DRAM: 2 GiB
MMC: SUNXI SD/MMC: 0
In: serial
Out: serial
Err: serial
SCSI: SUNXI SCSI INIT
Target spinup took 0 ms.
AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode
flags: ncq stag pm led clo only pmp pio slum part ccc apst
Net: dwmac.1c50000
Hit any key to stop autoboot: 0
sun7i#
</code></pre>
<p>As more platforms become supported by the u-boot packages you should
be able to find them in <code>/usr/lib/u-boot/*_FEL</code>.</p>
<p>There is one minor inconvenience which is the need to run
<code>sunxi-usb-boot</code> as root in order to access the FEL USB device. This
is easily resolved by creating <code>/etc/udev/rules.d/sunxi-fel.rules</code>
containing either:</p>
<pre><code>SUBSYSTEMS=="usb", ATTR{idVendor}=="1f3a", ATTR{idProduct}=="efe8", OWNER="myuser"
</code></pre>
<p>or</p>
<pre><code>SUBSYSTEMS=="usb", ATTR{idVendor}=="1f3a", ATTR{idProduct}=="efe8", GROUP="mygroup"
</code></pre>
<p>To enable access for <code>myuser</code> or <code>mygroup</code> respectively. Once you have
created the rules file then to enable:</p>
<pre><code># udevadm control --reload-rules
</code></pre>
<p>As well as the FEL mode tools the packages also contain a
<a href="http://linux-sunxi.org/Fex_Guide">FEX</a> (de)compiler. FEX is
Allwinner's own hardware description language and is used with their
Android SDK kernels and the <a href="http://linux-sunxi.org/Linux_Kernel">fork of that
kernel</a> maintained by the
linux-sunxi project. Debian's kernels follow mainline and therefore
use <a href="http://www.devicetree.org/Main_Page">Device Tree</a>.</p>