<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FreeBSD developer&#039;s notebook | All Things FreeBSD</title>
	<atom:link href="http://kernelnomicon.org/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://kernelnomicon.org</link>
	<description>All Things FreeBSD</description>
	<lastBuildDate>Mon, 06 May 2013 00:25:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Work in Progress: LCD driver for AM335x evaluation module</title>
		<link>http://kernelnomicon.org/?p=372</link>
		<comments>http://kernelnomicon.org/?p=372#comments</comments>
		<pubDate>Mon, 06 May 2013 00:25:57 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[FreeBSD]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=372</guid>
		<description><![CDATA[I&#8217;m trying to wrap up some project I started working on quite some time ago and this is first chunk of clean-up. Patch contains: Kernel config for AM335x EVM dts file for AM335x EVM with TFT panel info LCD controller driver with some functionality missing: only 24/32 bit depth and only TFT mode is supported [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m trying to wrap up some project I started working on quite some time ago and this is first chunk of clean-up.  </p>
<p><a href="http://people.freebsd.org/~gonzo/arm/patches/am335x-pwm-lcd.diff">Patch </a>contains:</p>
<ul>
<li>Kernel config for AM335x EVM</li>
<li>dts file for AM335x EVM with TFT panel info</li>
<li>LCD controller driver with some functionality missing: only 24/32 bit depth and only TFT mode is supported</li>
<li>Really simple PWM driver. LCD backlight is controlled through eCAS submodule of PWMSS0 module.</li>
</ul>
<p>I tested it only on evaluation module, although I think with proper panel/pinmux configuration it should work with BeagleBone&#8217;s LCD caps too.<br />
Parts missing: adjusting clock to proper pixel frequency, proper allocation of framebuffer memory. </p>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=372</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FDT driver skeleton generator</title>
		<link>http://kernelnomicon.org/?p=365</link>
		<comments>http://kernelnomicon.org/?p=365#comments</comments>
		<pubDate>Fri, 03 May 2013 18:20:14 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[FreeBSD]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=365</guid>
		<description><![CDATA[Writing new driver for FDT-based device always involves several simple steps: writing generic newbus driver skeleton Checking for compatibility of node in probe routine Allocate memory/IRQ resources in attach routine I can&#8217;t say for other developers but I just copy existing driver, remove all device-specific stuff and rewrite generic stuff. Which is less time-consuming then [...]]]></description>
				<content:encoded><![CDATA[<p>Writing new driver for FDT-based device always involves several simple steps:</p>
<ul>
<li>writing generic newbus driver skeleton </li>
<li>Checking for compatibility of node in probe routine</li>
<li>Allocate memory/IRQ resources in attach routine</li>
</ul>
<p>I can&#8217;t say for other developers but I just copy existing driver, remove all device-specific stuff and rewrite generic stuff. Which is less time-consuming then writing it from scratch but time-consuming it is. Being huge fan of automation of any kind I decided to let computer do all this dumb work and leave creative part (copy-pasting registers definition from spec to code) to myself. the result is <a href="https://github.com/gonzoua/freebsd-misc/tree/master/fdt_skeleton">this script</a>.</p>
<p>Developer feeds driver description in YAML format to the script and gets driver skeleton that requires minimal amount of editing to get it compiled. Driver description includes author name, prefix for macroses, prefix for newbus method-functions, FDT compatibility string, driver name and number of IRQ/MEMORY resources. A minute saved is a minute earned. </p>
<p>YAML example:</p>
<pre>
AUTHOR: Oleksandr Tymoshenko &lt;gonzo@freebsd.org&gt;
PREFIX: am335x_pwm
MACRO_PREFIX: PWM
DRIVER: am335x_pwm
FDT_COMPATIBLE: ti,am335x-pwm
IRQ_RESOURCES: 0
MEM_RESOURCES: 4
</pre>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=365</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netbooting ARM/MIPS devices: ubldr</title>
		<link>http://kernelnomicon.org/?p=351</link>
		<comments>http://kernelnomicon.org/?p=351#comments</comments>
		<pubDate>Sat, 20 Apr 2013 02:24:19 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[netboot]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=351</guid>
		<description><![CDATA[As it was mentioned in previous post U-Boot can boot FreeBSD kernel directly but this approach doesn&#8217;t allow a great deal of control over boot process: there is no way to set tunables&#8217; values or pre-load module. Controlling this stuff requires more knowledge of FreeBSD internal data structures and its boot process then U-Boot holds. [...]]]></description>
				<content:encoded><![CDATA[<p>As it was mentioned in <a href="http://kernelnomicon.org/?p=327">previous post</a> U-Boot can boot FreeBSD kernel directly but this approach doesn&#8217;t allow a great deal of control over boot process: there is no way to set tunables&#8217; values or pre-load module. Controlling this stuff requires more knowledge of FreeBSD internal data structures and its boot process then U-Boot holds.  </p>
<p>On i386 and other Tier1 architectures this task is handled by the <a href="http://www.freebsd.org/cgi/man.cgi?query=loader&#038;sektion=8">loader(8)</a> program. It&#8217;s last stage boot loader (e.g. it&#8217;s supposed to pass control to FreeBSD kernel only), highly customizable and scriptable. <a href="http://www.freebsd.org/cgi/man.cgi?query=loader&#038;sektion=8">loader(8)</a> relies on one of the previous stages boot loader to access resources like disks, console, network. For i386 it&#8217;s BTX and BIOS. </p>
<p>ubldr is implementation of loader(8) for ARM on top of U-Boot. Original code was developed by Semihalf back in 2008 and has been being improved by them and FreeBSD Community since then. Despite it has been around for almost 5 years amount of documentation is shockingly low. I found only <a href="http://www.bsdcan.org/2008/schedule/attachments/49_2008_uboot_freebsd.pdf">these slides</a> from BSDCan 2008.</p>
<p>One of the nice feature U-Boot provides is API for stand-alone process. If you don&#8217;t need full-blown operating system running on your hardware but still want access to SD card/network/console you can request them from U-Boot via syscall-like API that turns boot loader into quasi-OS. Some bits of information on this topic can be found in api/README file in U-Boot sources: <a href="http://git.denx.de/?p=u-boot.git;a=blob_plain;f=api/README;hb=HEAD">here</a>. </p>
<p>ubldr uses U-Boot API to enumerate devices that might be used as a boot source: block (e.g. SD card) or network. For network device it will use BOOTP to try to obtain network/boot data and then mount directory over NFS. For block device it will inspect partition table and try to find suitable partition to use as a root device. Once root is mounted ubldr will perform standard loader(8) magic: get loader-related config from /boot/ directory and act on it. </p>
<p>There is no dedicated top-level build target for ubldr so getting it compiled is a little bit tricky. You need to perform whole buildworld cycle  before compiling ubldr. Build script would look something like this:</p>
<pre>
export SRCROOT=/src/FreeBSD/head
export MAKESYSPATH=$SRCROOT/share/mk
export TARGET=arm
export TARGET_ARCH=armv6
export MAKEOBJDIRPREFIX=/src/FreeBSD/obj

make -C $SRCROOT buildworld

buildenv=`make -C $SRCROOT buildenvvars`

eval $buildenv make -C $SRCROOT/sys/boot clean
eval $buildenv make -C $SRCROOT/sys/boot obj
eval $buildenv make -C $SRCROOT/sys/boot UBLDR_LOADADDR=0x2000000 all
</pre>
<p>Meaning of UBLDR_LOADADDR is the same as KERNPHYSADDR  in <a href="/?p=351&#038;preview=true">previous post</a>.</p>
<p>ubldr is ELF executable and can be used with bootelf command. Typical boot log is something like this:</p>
<pre>
## Starting application at 0x02000054 ...
Consoles: U-Boot console  
Compatible API signature found @7b662a8
Number of U-Boot devices: 2

FreeBSD/armv6 U-Boot loader, Revision 1.2
(gonzo@bsdbox, Fri Apr 19 18:52:33 PDT 2013)
DRAM:    128MB

Device: disk

Device: net

/boot/kernel/kernel data=0x3ae624+0x2128c syms=[0x4+0x71ca0+0x4+0x44075]
Hit [Enter] to boot immediately, or any other key for command prompt.
Booting [/boot/kernel/kernel]...               
Waiting for Ethernet connection... done.
Using DTB provided by U-Boot.
Kernel entry at 0x100100...
Kernel args: (null)
KDB: debugger backends: ddb
KDB: current backend: ddb
Copyright (c) 1992-2013 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
        The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
...
</pre>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=351</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netbooting ARM/MIPS devices: kinds of kernel and u-boot</title>
		<link>http://kernelnomicon.org/?p=327</link>
		<comments>http://kernelnomicon.org/?p=327#comments</comments>
		<pubDate>Sat, 16 Feb 2013 00:33:58 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[netboot]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=327</guid>
		<description><![CDATA[U-Boot is a boot loader. Its task is to get kernel into memory and pass control to it. I will cover only parts of it related to netboot. kernel or kernel.bin But before we start loading something we need to know what to load. In previous post I mentioned that there are kernel, kernel.bin, and [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.denx.de/wiki/U-Boot">U-Boot</a> is a boot loader. Its task is to get kernel into memory and pass control to it. I will cover only parts of it related to netboot. </p>
<h2>kernel or kernel.bin</h2>
<p>But before we start loading something we need to know what to load. In <a href="http://kernelnomicon.org/?p=306">previous post</a> I mentioned that there are kernel, kernel.bin, and ubldr files. Let&#8217;s get into details. First of all: ubldr requires its own post. So there will be one more covering just ubldr. Now kernel and kernel.bin. </p>
<p>kernel is ELF executable. It means that it&#8217;s a self-contained file with all the information required to layout its bits in memory. e.g.: this data in file should be copied to address A, and N bytes at address B should be set to zero, code intry point is address X. All this auxiliary information is stored alongside to raw code and data. U-boot (or any other bootloader) reads it, lays out data/code accordingly and passes control to entry point. U-Boot&#8217;s command for it is <b>bootelf</b>.</p>
<p>Now, <b>bootelf</b> or ELF support in general is not always available in boot loaders. In this case we load ELF on host machine. Technically it&#8217;s called &#8220;convert to binary format&#8221; but essentially what objcopy utility does is it simulates loading of ELF file into memory and dumps memory region from the lowest address that belongs to loaded executable to the highest one into the kernel.bin file. No auxiliary information is saved &#8211; only raw code and data. Without this information it&#8217;s users responsibility to point which address this memory dump should be loaded at and where to start execution. </p>
<p>That&#8217;s theory in a nutshell. Back to practice.</p>
<h2>U-Boot</h2>
<p>Network initialization routine depends on the board you&#8217;re working with. If the ethernet card connected to board over USB (like on Raspberry Pi or Pandaboard) you might need to initialize USB first:</p>
<pre>
U-Boot&gt; usb start
(Re)start USB...
USB0:   Core Release: 2.80a
scanning bus 0 for devices... 3 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
       scanning usb for ethernet devices... 1 Ethernet Device(s) found</pre>
<p>At this point you can either get network settings via DHCP or set them manually.<br />
Manual control over network is performed by setting U-Boot environment variables:</p>
<pre>
U-Boot&gt; setenv ipaddr 192.168.10.21
U-Boot&gt; setenv netmask 255.255.255.0
U-Boot&gt; setenv gatewayip 192.168.10.1
</pre>
<p>DHCP also provides information about TFTP server and boot file, we can set them manually too:</p>
<pre>
U-Boot&gt; setenv bootfile kernel
U-Boot&gt; setenv serverip 192.168.10.1
</pre>
<p>And now load it </p>
<pre>
U-Boot&gt; tftpboot 0x8000
</pre>
<p>and boot</p>
<pre>
U-Boot&gt; bootelf 0x8000
</pre>
<p>By default tftpboot and bootelf would use loadaddr env variable if it&#8217;s set so you can combine last two commands to</p>
<pre>
U-Boot&gt; setenv loadaddr 0x8000
U-Boot&gt; tftpboot
U-Boot&gt; bootelf
</pre>
<p>With DHCP everything above is combined into three commands:</p>
<pre>
U-Boot&gt; setenv loadaddr 0x8000
U-Boot&gt; dhcp
U-Boot&gt; bootelf
</pre>
<p>If you&#8217;re booting ELF loadaddr can be any valid address because bootelf will relocate kernel to proper location. Valid range for addresses depends on the board in use.</p>
<p>With kernel.bin though you have to specify specific value as a loadaddr. Usually it&#8217;s KERNPHYSADDR option in kernel config file for ARM and KERNLOADADDR value for MIPS. U-Boot commands sequence would look like:</p>
<pre>
U-Boot&gt; setenv bootfile kernel.bin
...
U-Boot&gt; setenv loadaddr 0x00100000
U-Boot&gt; dhcp
U-Boot&gt; go 0x00100000
</pre>
<h2>uImage, ubldr</h2>
<p>This is basic stuff I&#8217;ve been using for several years in my development environment. There are more options though: u-boot application images and <b>bootm</b> command and ubldr. Former is well-documented on Internet and about latter I&#8217;ll post some information soon. </p>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=327</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Netbooting ARM/MIPS devices: server setup</title>
		<link>http://kernelnomicon.org/?p=306</link>
		<comments>http://kernelnomicon.org/?p=306#comments</comments>
		<pubDate>Fri, 15 Feb 2013 02:50:42 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[netboot]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=306</guid>
		<description><![CDATA[I was asked to share details about my root-over-NFS setup so here they are. I decided to split how-to in two posts: server/kernel part and u-boot part. Usual components in the setup are: DHCP server TFTP server NFS server NAT (optional) DHCP server I use net/isc-dhcp42-server as a server. Sample dhcpd.conf: option root-opts code 130 [...]]]></description>
				<content:encoded><![CDATA[<p>I was asked to share details about my root-over-NFS setup so here they are. I decided to split how-to in two posts: server/kernel part and u-boot part. </p>
<p>Usual components in the setup are:</p>
<ul>
<li>DHCP server</li>
<li>TFTP server</li>
<li>NFS server</li>
<li>NAT (optional)</li>
</ul>
<h2>DHCP server</h2>
<p>I use <b>net/isc-dhcp42-server</b> as a server. Sample dhcpd.conf:</p>
<pre>
option root-opts code 130 = string; # NFS / mount options
log-facility local7;

subnet 192.168.10.0 netmask 255.255.255.0 {
        server-name "cinderella.bluezbox.com";
        server-identifier 192.168.10.1;
        option subnet-mask 255.255.255.0;
        option broadcast-address 192.168.10.255;
        option domain-name-servers 8.8.8.8;
        option domain-name "bluezbox.com";
        next-server 192.168.10.1;
        option routers 192.168.10.1;
}

group {
        host pandaboard {
                hardware ethernet 0E:60:33:B1:46:01;
                fixed-address 192.168.10.90;
                filename "kernel.PANDA.bin";
                option root-path "/src/FreeBSD/nfs/armv6";
                option root-opts "nolockd";
        }

        host rpi {
                hardware ethernet b8:27:eb:f6:08:83;
                fixed-address 192.168.10.91;
                filename "ubldr";
                option root-path "/src/FreeBSD/nfs/rpi";
                option root-opts "nolockd";
        }
}
</pre>
<p>Config is pretty self-explanatory. I use google&#8217;s <b>8.8.8.8</b> nameserver but you can change it to your very own DNS server. Difference between various <b>filename &#8220;&#8230;&#8221;</b> will be explained later.</p>
<p>dhcpd should be enabled in <a href="http://www.freebsd.org/cgi/man.cgi?query=rc.conf&#038;sektion=5">rc.conf(5)</a></p>
<pre>dhcpd_enable="YES"</pre>
<h2>TFTP server</h2>
<p>TFTP server provides access to all files described in <b>filename &#8220;&#8230;&#8221;</b> options so it&#8217;s better to keep them together. By default it&#8217;s <b>/tftpboot</b> directory but I have whole drive dedicated to FreeBSD development environment and mounted under /src/FreeBSD mountpoint. So I keep everything there and my TFTP server root is <b>/src/FreeBSD/tftpboot</b>. TFTP server is standard FreeBSD&#8217;s one and config line in <a href="http://www.freebsd.org/cgi/man.cgi?query=inetd.conf&#038;sektion=8">inetd.conf(8)</a> looks like:</p>
<pre>tftp    dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s /src/FreeBSD/tftpboot</pre>
<p>inted should be enabled in <a href="http://www.freebsd.org/cgi/man.cgi?query=rc.conf&#038;sektion=5">rc.conf(5)</a></p>
<pre>inetd_enable="YES"</pre>
<h2>NFS Server</h2>
<p>NFS server is not just one daemon but several services combined. So <a href="http://www.freebsd.org/cgi/man.cgi?query=rc.conf&#038;sektion=5">rc.conf(5)</a> part of config looks like this:</p>
<pre>
rpcbind_enable="YES"
rpc_statd_enable="YES"
rpc_lockd_enable="YES"
nfs_server_enable="YES"
mountd_enable="YES"
</pre>
<p>Filesystems that are exported via NFS listed in <a href="http://www.freebsd.org/cgi/man.cgi?query=exports&#038;sektion=5">exports(5)</a>. Mine contains following:</p>
<pre>
# Mind mount points obj and nfs are different
/usr/ports -maproot=0 -network 192.168.10.0/16
/src/FreeBSD/head /src/FreeBSD/nfs/rpi /src/FreeBSD/nfs/armv6 /src/FreeBSD/nfs/am335x -maproot=0 -network 192.168.10.0/16
</pre>
<p>Note that you can join several directories into one line only if they belong to the same mount point.</p>
<h2>NAT</h2>
<p>If you&#8217;re planning on building ports on the device &#8211; you&#8217;ll need internet access on it. All my devices  are restricted to one LAN with laptop acting as a gateway. I use <a href="http://www.freebsd.org/cgi/man.cgi?query=pf&#038;sektion=4">pf(4)</a> for NATing. Config:<br />
<a href="http://www.freebsd.org/cgi/man.cgi?query=pf.conf&#038;sektion=5">/etc/pf.conf(5)</a></p>
<pre>
ext_if=em0
rede="{192.168.0.0/16}"

nat on $ext_if from $rede to any -> ($ext_if)
</pre>
<p>and <a href="http://www.freebsd.org/cgi/man.cgi?query=rc.conf&#038;sektion=5">rc.conf(5)</a></p>
<pre>
gateway_enable="YES"

pf_enable="YES"
pf_rules="/etc/pf.conf"
pf_flags=""
</pre>
<h2>Kernel config</h2>
<p>FreeBSD kernel should be properly configured in order to be suitable for mounting root over NFS:</p>
<pre>
options         NFSCL
options         NFSCLIENT # NFS v3
options         NFS_ROOT
options         BOOTP_NFSROOT
options         BOOTP_COMPAT
options         BOOTP
options         BOOTP_NFSV3
options         BOOTP_WIRED_TO=ue0
</pre>
<p>BOOTP_WIRED_TO value is SoC-specific. If you do not have full control over your DHCP server (e.g. it&#8217;s cable modem) and can&#8217;t specify root-path/root-opts you still can hardcode root location by removing BOOTP_NFSROOT and adding</p>
<pre>
options         ROOTDEVNAME=\"nfs:192.168.10:/src/FreeBSD/nfs/rpi\"
</pre>
<h2>Installation</h2>
<p>Depending on your boot sequence installation consists of one or two steps. </p>
<p>Normal system installation, e.g.:</p>
<pre>
sudo -E make TARGET_ARCH=armv6 DESTDIR=/src/FreeBSD/nfs/rpi -DDB_FROM_SRC installworld
sudo -E make TARGET_ARCH=armv6 DESTDIR=/src/FreeBSD/nfs/rpi -DDB_FROM_SRC distribution
</pre>
<p>And installing kernel copying kernel to tftpboot directory:</p>
<pre>
sudo -E make TARGET_ARCH=armv6 DESTDIR=/src/FreeBSD/nfs/rpi -DDB_FROM_SRC installkernel
cp /src/FreeBSD/nfs/rpi/boot/kernel/kernel /src/FreeBSD/tftpboot/kernel.RPI 
</pre>
<p>In some cases you&#8217;d want to use kernel.bin instead of kernel (more on it in next post) so second step would look like</p>
<pre>
sudo -E make TARGET_ARCH=armv6 DESTDIR=/src/FreeBSD/nfs/rpi -DDB_FROM_SRC KERNEL_EXTRA_INSTALL=kernel.bin installkernel
cp /src/FreeBSD/nfs/rpi/boot/kernel/kernel.bin /src/FreeBSD/tftpboot/kernel.RPI.bin
</pre>
<p>And if you&#8217;re going to use ubldr, there is no need to copy installed kernel anywhere.</p>
<p>More details on different types of binaries and boot process in the next post</p>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=306</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Netbooting Hackberry A10 (Allwinner A10)</title>
		<link>http://kernelnomicon.org/?p=298</link>
		<comments>http://kernelnomicon.org/?p=298#comments</comments>
		<pubDate>Sun, 10 Feb 2013 08:14:34 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=298</guid>
		<description><![CDATA[Last few weeks I&#8217;ve been acting as a reviewer for Ganbold Tsagaankhuu&#8217;s port of FreeBSD for Cubieboard so in order to provide more valuable input and less naysaying I decided to get A10-based device to test his changes. So I ordered Hackberry from miniand.com. I&#8217;m not great fan of pushing SD cards back and forth [...]]]></description>
				<content:encoded><![CDATA[<p>Last few weeks I&#8217;ve been acting as a reviewer for Ganbold Tsagaankhuu&#8217;s port of FreeBSD for Cubieboard so in order to provide more valuable input and less naysaying I decided to get A10-based device to test his changes. So I ordered <a href="https://www.miniand.com/products/Hackberry%20A10%20Developer%20Board">Hackberry</a> from miniand.com. I&#8217;m not great fan of pushing SD cards back and forth so first thing I do with my SoCs is get them netbooting. That&#8217;s where fun begins.</p>
<p>Long story short &#8211; I had to get latest <a href="https://github.com/linux-sunxi/u-boot-sunxi">official u-boot</a>, merge network driver (sunxi_wemac) from <a href="https://github.com/hno/uboot-allwinner">hno&#8217;s u-boot</a> and add some GPIO magic to emac initialization. Namely &#8211; configure pin H19 (emac_power) as function 1 and set its value to 1. Only then I got net-related commands working properly.</p>
<p>If you&#8217;re interested in building your own bootable SD card: <a href="http://people.freebsd.org/~gonzo/arm/hackberry/">fetch these files</a>. uEnv.txt and boot.scr are tailored to my needs so you might want to change them. mksd.sh does all the job, just make sure you use proper device name for SD card. </p>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=298</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Accessing GPIO from Perl, Python, and Ruby</title>
		<link>http://kernelnomicon.org/?p=293</link>
		<comments>http://kernelnomicon.org/?p=293#comments</comments>
		<pubDate>Fri, 08 Feb 2013 02:01:21 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=293</guid>
		<description><![CDATA[I started this smallish project to overcome coder&#8217;s block and original idea was to implement it in only one scripting language. I chose Python as I believed it had most clear API but then I decided to throw in Perl and Ruby as well. It was more exercise in building C extensions then in actual [...]]]></description>
				<content:encoded><![CDATA[<p>I started this smallish project to overcome coder&#8217;s block and original idea was to implement it in only one scripting language. I chose Python as I believed it had most clear API but then I decided to throw in Perl and Ruby as well. It was more exercise in building C extensions then in actual system programming but it was fun nonetheless. All three sub-projects lack proper documentation but there are examples that should be enough to get started.</p>
<p><a href="https://github.com/gonzoua/freebsd-gpio">Sources</a> available on github. </p>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=293</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building image for Raspberry Pi: up to date version</title>
		<link>http://kernelnomicon.org/?p=275</link>
		<comments>http://kernelnomicon.org/?p=275#comments</comments>
		<pubDate>Fri, 01 Feb 2013 23:00:02 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=275</guid>
		<description><![CDATA[Update 1: Add -DDB_FROM_SRC to install targets Update 2: Add user &#8220;pi&#8221; with password &#8220;raspberry&#8221; It&#8217;s been a while since I posted original build instruction and a lot has change. Here is new version of it with some explanations: All code has been moved to HEAD. freebsd-pi repository on github serves only historical purpose and [...]]]></description>
				<content:encoded><![CDATA[<p><b>Update 1: Add -DDB_FROM_SRC to install targets</b><br />
<b>Update 2: Add user &#8220;pi&#8221; with password &#8220;raspberry&#8221;</b></p>
<p>It&#8217;s been a while since I posted original <a href="http://kernelnomicon.org/?p=164">build instruction</a> and a lot has change. Here is new version of it with some explanations:</p>
<p>All code has been moved to HEAD. freebsd-pi repository on github serves only historical purpose and I guess will be removed at some point in future. So in order to build image you need sources for -head</p>
<pre>
svn co svn://svn.freebsd.org/base/head
</pre>
<p>TARGET_CPUTYPE is dropped to in favor of TARGET_ARCH=armv6. U-Boot, firmware files and boot process were upgraded too. Current boot chain is as follows:</p>
<ul>
<li>Pi is powered up and loads firmware files</li>
<li>Firmware loads FDT blob defined in config.txt as device_tree variable at address defined as device_tree_address and fixes up fields like memory size, clock frequency and MAC address</li>
<li>Firmware loads u-boot and passes control to it</li>
<li>U-boot loads boot.scr and executes it</li>
<li>Default boot.scr loads ubldr(loader(8)-compatible implementation built over U-Boot API) and passes control</li>
<li>ubldr checks FreeBSD partition for /boot/loader.rc, loads it, the loads /boot/kernel/kernel and passes control to it</ui>
<li>loader.rc should contain &#8220;fdt addr 0&#215;100&#8243; command. It will pass FDT blob filled in step #2 to kernel</li>
</ul>
<p>So updated build script will look something like this:</p>
<pre>
#!/bin/sh
set -e

# Change this
export GPU_MEM=128
export PI_USER=pi
export PI_USER_PASSWORD=raspberry
export SRCROOT=/src/FreeBSD/head
export MNTDIR=/mnt
export MAKEOBJDIRPREFIX=/src/FreeBSD/obj
export IMG=/src/FreeBSD/obj/bsd-pi.img

export TARGET_ARCH=armv6
export MAKESYSPATH=$SRCROOT/share/mk
export KERNCONF=RPI-B

if [ -z "$MNTDIR" ]; then
        echo "MNTDIR is not set properly"
        exit 1
fi

KERNEL=`realpath $MAKEOBJDIRPREFIX`/arm.armv6/`realpath $SRCROOT`/sys/$KERNCONF/kernel
UBLDR=`realpath $MAKEOBJDIRPREFIX`/arm.armv6/`realpath $SRCROOT`/sys/boot/arm/uboot/ubldr
DTB=`realpath $MAKEOBJDIRPREFIX`/arm.armv6/`realpath $SRCROOT`/sys/$KERNCONF/bcm2835-rpi-b.dtb

make -C $SRCROOT kernel-toolchain
make -C $SRCROOT KERNCONF=$KERNCONF WITH_FDT=yes buildkernel
make -C $SRCROOT MALLOC_PRODUCTION=yes buildworld

buildenv=`make -C $SRCROOT buildenvvars`

eval $buildenv make -C $SRCROOT/sys/boot clean
eval $buildenv make -C $SRCROOT/sys/boot obj
eval $buildenv make -C $SRCROOT/sys/boot UBLDR_LOADADDR=0x2000000 all

rm -f $IMG
dd if=/dev/zero of=$IMG bs=128M count=8
MDFILE=`mdconfig -a -f $IMG`
gpart create -s MBR ${MDFILE}

# Boot partition
gpart add -s 32m -t '!12' ${MDFILE}
gpart set -a active -i 1 ${MDFILE}
newfs_msdos -L boot -F 16 /dev/${MDFILE}s1
mount_msdosfs /dev/${MDFILE}s1 $MNTDIR
fetch -q -o - http://people.freebsd.org/~gonzo/arm/rpi/freebsd-uboot-20130201.tar.gz | tar -x -v -z -C $MNTDIR -f -

cat >> $MNTDIR/config.txt <<__EOC__
gpu_mem=$GPU_MEM
device_tree=devtree.dat
device_tree_address=0x100
disable_commandline_tags=1
__EOC__
cp $UBLDR $MNTDIR
cp $DTB $MNTDIR/devtree.dat
umount $MNTDIR

# FreeBSD partition
gpart add -t freebsd ${MDFILE}
gpart create -s BSD ${MDFILE}s2
gpart add -t freebsd-ufs ${MDFILE}s2
newfs /dev/${MDFILE}s2a

# Turn on Softupdates
tunefs -n enable /dev/${MDFILE}s2a
# Turn on SUJ with a minimally-sized journal.
# This makes reboots tolerable if you just pull power on the BB
# Note:  A slow SDHC reads about 1MB/s, so a 30MB
# journal can delay boot by 30s.
tunefs -j enable -S 4194304 /dev/${MDFILE}s2a
# Turn on NFSv4 ACLs
tunefs -N enable /dev/${MDFILE}s2a

mount /dev/${MDFILE}s2a $MNTDIR

make -C $SRCROOT DESTDIR=$MNTDIR -DDB_FROM_SRC installkernel
make -C $SRCROOT DESTDIR=$MNTDIR -DDB_FROM_SRC installworld
make -C $SRCROOT DESTDIR=$MNTDIR -DDB_FROM_SRC distribution

echo 'fdt addr 0x100' > $MNTDIR/boot/loader.rc

echo '/dev/mmcsd0s2a / ufs rw,noatime 1 1' > $MNTDIR/etc/fstab

cat > $MNTDIR/etc/rc.conf <<__EORC__
hostname="raspberry-pi"
ifconfig_ue0="DHCP"
sshd_enable="YES"

devd_enable="YES"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
__EORC__

cat > $MNTDIR/etc/ttys <<__EOTTYS__
ttyv0 "/usr/libexec/getty Pc" xterm on secure
ttyv1 "/usr/libexec/getty Pc" xterm on secure
ttyv2 "/usr/libexec/getty Pc" xterm on secure
ttyv3 "/usr/libexec/getty Pc" xterm on secure
ttyv4 "/usr/libexec/getty Pc" xterm on secure
ttyv5 "/usr/libexec/getty Pc" xterm on secure
ttyv6 "/usr/libexec/getty Pc" xterm on secure
ttyu0 "/usr/libexec/getty 3wire.115200" dialup on secure
__EOTTYS__

echo $PI_USER_PASSWORD | pw -V $MNTDIR/etc useradd -h 0 -n $PI_USER -c "Raspberry Pi User" -s /bin/csh -m
pw -V $MNTDIR/etc groupmod wheel -m $PI_USER
PI_USER_UID=`pw -V $MNTDIR/etc usershow $PI_USER | cut -f 3 -d :`
PI_USER_GID=`pw -V $MNTDIR/etc usershow $PI_USER | cut -f 4 -d :`
mkdir -p $MNTDIR/home/$PI_USER
chown $PI_USER_UID:$PI_USER_GID $MNTDIR/home/$PI_USER

umount $MNTDIR
mdconfig -d -u $MDFILE


</pre>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=275</wfw:commentRss>
		<slash:comments>79</slash:comments>
		</item>
		<item>
		<title>VCHIQ drivers work again</title>
		<link>http://kernelnomicon.org/?p=271</link>
		<comments>http://kernelnomicon.org/?p=271#comments</comments>
		<pubDate>Mon, 14 Jan 2013 03:19:10 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Raspberry Pi]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=271</guid>
		<description><![CDATA[I synced both vchiq-freebsd and userland to latest and greatest. As I mentioned earlier &#8211; OS compatibility shim was removed from upstream sources so I had to create Linux KPI implementation layer which turned out not that awful task because I managed to reuse a lot of code from Max Khon&#8217;s DAHDI port. I had [...]]]></description>
				<content:encoded><![CDATA[<p>I synced both <a href="https://github.com/gonzoua/vchiq-freebsd">vchiq-freebsd</a> and <a href="https://github.com/gonzoua/userland">userland</a> to latest and greatest. </p>
<p>As I mentioned earlier &#8211; OS compatibility shim was removed from upstream sources so I had to create Linux KPI implementation layer which turned out not that awful task because I managed to reuse a lot of code from Max Khon&#8217;s <a href="http://freebsdfoundation.blogspot.com/2010/10/update-on-dahdi-project.html">DAHDI port</a>. I had to implement (in somewhat hackish fashion) kthread API, re-implement semaphores support using condvar and mutex in order to get _interruptible part of API working properly and create dumb implementation of rather small subset of Linux list.h API. </p>
<p>With latest code I got pretty much all demos in hello_pi working except hello_jpeg(crashes system) and hello_encode(didn&#8217;t test). The most exciting bit for me was watching H.264 video playing on Raspberry Pi in hello_video demo. Network throughput still sucks so I had to copy file to tmpfs partition in order to get smooth playback though. </p>
<p>If you want to test VCHIQ &#8211; in addition to sources you&#8217;ll need latest <a href="https://github.com/raspberrypi/firmware/tree/master/boot">firmware files</a>. For demos you&#8217;ll also have to install freetype2 and manually hack Makefile.include in hello_pi. I&#8217;m planning to create ports/packages for both drivers and userland some time next week. </p>
<p>On the related note: Aleksandr Rybalko <a href="http://raybsd.blogspot.com/2013/01/hope-you-like-it.html">got XOrg working on Efika MX Smartbook</a> so FreeBSD/Pi will get graphic interface soon <img src='http://kernelnomicon.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=271</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Packages(*) for Rasberry Pi(**)</title>
		<link>http://kernelnomicon.org/?p=261</link>
		<comments>http://kernelnomicon.org/?p=261#comments</comments>
		<pubDate>Sat, 12 Jan 2013 04:05:44 +0000</pubDate>
		<dc:creator>gonzo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kernelnomicon.org/?p=261</guid>
		<description><![CDATA[I finally got around to setting up experimental pkgng repo for ARM in order to share packages with other ARM developers and users who feel adventurous. And man, was it simple. I have pandaboard that is super-fast comparing to Raspberri Pi so I use it for building ports. There were several installed so I just [...]]]></description>
				<content:encoded><![CDATA[<p>I finally got around to setting up experimental pkgng repo for ARM in order to share packages with other ARM developers and users who feel adventurous. And man, was it simple. I have pandaboard that is super-fast comparing to Raspberri Pi so I use it for building ports. There were several installed so I just had to generate packages for them using
<pre>pkg create -a</pre>
<p> command. Then I uploaded all newly generated files to the server, grabbed packages <a href="http://lists.freebsd.org/pipermail/freebsd-arm/2012-December/004493.html">built and shared</a> by Stephen Hurd, removed duplicates with older versions and generated repo.txz by issuing
<pre>pkg repo</pre>
<p> command. </p>
<p>Then on a raspberry pi I created pkg.conf in which I pointed to my newly created &#8220;repo&#8221;, updated metada and installed git:</p>
<pre>
# echo 'PACKAGESITE: http://people.freebsd.org/~gonzo/arm/pkg/' > /usr/local/etc/pkg.conf
# pkg update
# pkg install git
</pre>
<p>Pi took some time to push files back and forth over NFS (I use NFS root on my devices) but eventually I got git with all dependencies up and running.</p>
<p><b>!!! Please note that packages are not officially provided by FreeBSD Project. They&#8217;re only for experimental purpose so install them at your own discretion !!!</b></p>
<p>Thanks to bapt@ for working on this great tool. </p>
<p><sup>*</sup> &#8211; some<br />
<sup>**</sup> &#8211; And for other ARM devices</p>]]></content:encoded>
			<wfw:commentRss>http://kernelnomicon.org/?feed=rss2&#038;p=261</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
