Documentation:AVR32 Linux Development/Filesystem over NFS for AVR32 Linux

From AVRFreaks Wiki

Jump to: navigation, search

Contents

[edit] Introduction

Developing software for AVR32 Linux is often an iterating process. The program is compiled on a workstation, transfered to the target and executed.

This can be tedious if an SD memory card is used for the transfer. A more lean approach is to setup a NFS server holding the AVR32 Linux file system. This NFS server can be the development workstation and in this way the executable is directly available both on development and target system.


[edit] NFS server

If developing on Linux kernel drivers or other files that need to reside on the root file system, the NFS server must be capable of storing and exporting the Linux device files correctly. Currently no known Windows NFS server is capable of this. A Linux system is therefore required. This may be a virtual machine (eg. VMware) or at native system.

If, however, only user space programs are developed, AVR32 Linux may boot as normal (from on-board flash or SD-card) and the NFS server mounted at an arbitrary point. In this case any NFS server should do.

In the following a fully featured NFS server running on Linux is assumed and the complete AVR32 Linux file system is exported as NFS.

[edit] Setting up the NFS daemon on Ubuntu

# sudo su -
# apt-get install nfs-kernel-server
# mkdir /nfs
# pico /etc/exports

add this line

 /nfs 10.0.0.0/255.0.0.0(rw,sync,no_root_squash)

save and exit (Ctrl-X), finally type

# /etc/init.d/nfs-kernel-server restart

to reload the nfs daemon.

Note that you might have to adjust the ipaddress/ipmask above to match your network.

[edit] Setting up the NFS daemon on openSUSE

Note this is tested on openSUSE 10.3 and 11.0

Open YaST2, go to the network services tab and select NFS Server.

Select "Start". You may choose to enable NFSv4, it is useful if you're going to be using this share for anything other than the AVR32. It isn't used by the AVR32.

If the network card to which the AVR32 is connected is in External Zone of the firewall (all cards are here by default) then check the "Open Port in Firewall" box as well.

Click "Next". In the Directories to Export box, click "Add Directory" and type the path at which you will be putting your AVR32's root filesystem. This is generally /nfs or something like /nfs/ngw. Once you've added this directory, select it in the top box and select the options entry in the bottom box. Click the edit button below the bottom box and make sure the options list reads "fsid=0,rw,no_root_squash,sync,no_subtree_check".

Click OK, Finish and you're done.

If you don't see the NFS Server option in the Network Services tab, open the Install Software dialog, select "Patterns" in the View drop-down box, scroll down and check the "File Server" pattern under Server Functions. Apply changes and try the above steps again.

[edit] TFTP server

The U-Boot boot loader can retrieve the AVR32 Linux kernel over the network with the TFTP protocol.

[edit] Setting up the TFTP daemon on Ubuntu

# sudo su -
# apt-get install tftpd-hpa
# mkdir -p /nfs/tftp
# pico /etc/default/tftpd-hpa

Change RUN_DAEMON to 'yes' and the path to /nfs/tftp

RUN_DAEMON="yes"
OPTIONS="-l -s /nfs/tftp"

Finally start the tftp server

# /etc/init.d/tftpd-hpa start

[edit] Setting up the TFTP daemon on openSUSE

Open YaST2, go to the Network Services tab and select TFTP server. Check "enable" and put the tftp share directory in the box. This is generally /nfs or /nfs/tftp. If the network card to which the AVR32 is connected is in the External Zone of the firewall (all cards are here by default) then check the "Open Port in Firewall" box too.

Click Finish and you're done.

If you don't see the TFTP Server option in the Network Services tab, open the Install Software dialog, select "Patterns" in the View drop-down box, scroll down and check the "File Server" pattern under Server Functions. Apply changes and try the above steps again.

[edit] DHCP and IP addresses

Das U-Boot and AVR32 Linux can use manually configured ip addresses. However, many will find it more convenient to use dynamic ip assignment: DHCP.

DHCP is usually enabled if you are connecting the AVR32 device to an existing network. However, many IT-departments will deny hooking up non approved hardware (and especially development kits) to the business network. In such case you'll probably setup a small LAN or a direct link between the NFS server and AVR32 device. You will need to configure the network interface on the server for static IP address.

Note that in the following it is assumed that the AVR32 device is connected to the primary ethernet port (eth0) on the server.

[edit] Configuring server for static IP address on Ubuntu

# pico /etc/network/interfaces

You will probably find a line like 'iface eth0 inet dhcp'

change this to:

iface eth0 inet static
  address 10.0.0.1
  netmask 255.255.255.0


Restart network interfaces with

# ifdown eth0
# ifup eth0

[edit] Setting up DHCP server on Ubuntu

WARNING do not install a DHCP server on your workstation if it is part of the business network as it will cause conflict with corporate DHCP servers.

# apt-get install dhcp3-server
# pico /etc/dhcp3/dhcpd.conf

Append the following section at the end:

subnet 10.0.0.0 netmask 255.255.255.0 {
  range 10.0.0.20 10.0.0.200;
  option routers 10.0.0.1;
  option broadcast-address 10.0.0.255;
}

Save and exit

 # pico /etc/default/dhcp3-server

Add 'eth0' to the interface (or eth1 if AVR32 device is connected to a secondary ethernet port)

INTERFACES="eth0"

Restart dhcp server

 # /etc/init.d/dhcp3-server restart

[edit] Configuring your server for static IP and DHCP server on openSUSE

Open YaST2 and go to the Network Devices tab. Select "Network Settings" and in the "Overview" tab, select the interface card to which the AVR32 is connected. Click "Edit" and in the "Address" tab select "Statically assigned IP Address". Type in the IP address you want (generally 10.0.0.1 or 192.168.1.1), the Subnet Mask (generally 255.0.0.0 or 255.255.255.0 for those 2 IP addresses respectively) and a hostname of your choosing. Click "Next" and "Finish".

Note that you will now not be able to access the internet on this network interface. It is recommended that you have 2 network cards in your machine and use the other one for internet duties, but if you must use this interface to connect to the internet too, you should fill in the "DNS" and "Default Gateway" boxes in the "Network Settings" dialog with ones supplied by your Network Administrator or ISP.

Now we've done the Static IP bit we can turn the machine in to a DHCP server. In YaST2, go to the "Network Services" tab. Select "DHCP Server". In the "Network Cards for DHCP Server" box select the network interface which is connected to your AVR32 and click the "Select" button. If the network interface to which the AVR32 is connected is in the "External Zone" of the firewall (all interfaces are by default) then select "Open Firewall for Selected Interfaces". Click "Next" and fill in the boxes with the appropriate values. None of these boxes *must* be filled out, so don't worry if you don't know them. Click "Next" and fill in the first and last IP addresses which the server can allocate. The first IP should be one higher than the static IP you assigned above and the last is generally 10 or 20 addresses above the start. Click next. Select "At Boot" and click finish.

If you don't see the "DHCP Server" icon, open the Install Software dialog, select "Pattern" from the filter drop-down box the scroll down and select "DHCP and DNS Server". Apply changed and try the above steps again.

[edit] U-Boot parameters for TFTP and NFS with DHCP

It is assumed below that the NFS and TFTP server is the same machine and that this has IP address 10.0.0.1. The AVR32 devices receives a dynamic IP address from a DHCP server

UBoot> set serverip 10.0.0.1
UBoot> set tftpserver 10.0.0.1
UBoot> set bootcmd 'set bootfile uImage;dhcp;bootm'
UBoot> set bootargs 'root=/dev/nfs nfsroot=10.0.0.1:/nfs console=ttyS0 ip=dhcp'
UBoot> saveenv
UBoot> boot

[edit] U-Boot parameters for TFTP and NFS without DHCP

It is assumed below that the NFS and TFTP server is the same machine and that this has IP address 10.0.0.1. The AVR32 device uses a static ip address 10.0.0.10

NOTE: Using the saveenv command makes changes the default behavior of booting from flash to booting from the network. You will want to skip issuing the saveenv command if you are just testing things out.

UBoot> set serverip 10.0.0.1
UBoot> set tftpserver 10.0.0.1
UBoot> set bootcmd 'set ipaddr 10.0.0.10;tftp 0x10200000 uImage;bootm'
UBoot> askenv bootargs
>root=/dev/nfs nfsroot=10.0.0.1:/nfs ip=10.0.0.10::10.0.0.1:::eth0:off console=ttyS0
UBoot> saveenv
UBoot> boot

(we use askenv for the bootargs because it is too long for the U-Boot command line interpreter)

For the ngw100, use these commands instead:

UBoot> setenv serverip 10.0.0.1
UBoot> setenv tftpip 10.0.0.1
UBoot> setenv bootcmd 'set ipaddr 10.0.0.10;tftp 0x10200000 uImage;bootm'
UBoot> askenv bootargs
>root=/dev/nfs nfsroot=10.0.0.1:/nfs ip=10.0.0.10::10.0.0.1:::eth0:off console=ttyS0
UBoot> saveenv
UBoot> boot

[edit] Working with the NFS server

When the NFS server is fully functional the /nfs folder will contain the file system for the AVR32 device and where you'll need to place the target application. If you are most comfortable writing your code on an MS Windows workstation but you're running an NFS server on a Linux workstation, you'll need to get them to play nice.

Generally there are two ways to accomplish this: Teach Windows to speak NFS or teach Linux to speak Windows' file sharing (Samba).

[edit] Setting up windows NFS client

Microsoft's Services for UNIX (SFU) provides an NFS client and is free to download. Use the Services for UNIX Administration, User Name Mapping, and map your user name to UNIX 'root'.

Minimal passwd and group files are:

passwd:
root:x:0:0:root:/root:/bin/bash

group:
root:x:0:

Please note that NFS is not secure in a hostile (i.e. public) network environment!

[edit] Setting up samba

An alternative is to setup Samba, a windows file server for Linux which will let you mount the /nfs folder as a network drive in windows.


# sudo su -
# apt-get install samba
# pico /etc/samba/smb.conf

Append the following section at the end

[avr32nfs]
 comment = Target file system
 path = /nfs
 guest ok = yes
 browseable = yes
 writable = yes
 create mask = 0777
 directory mask = 0777
 admin users = avr
 force group = root
 force user = root

Add a samba user 'avr'

# smbpasswd avr

Restart samba server

# /etc/init.d/samba restart

Please note that this setup is usually not recomended for Samba from a security point of view. Nevertheless, it is the easiest way to create files in the NFS folder with correct permissions. Do not use the admin users, force group, force user or guest ok in a hostile (i.e. public) network environment

[edit] Troubleshooting

[edit] Linux freezes at startup after aquiring address

When using NFS to mount the root filesystem, you must disable automatic userspace DHCP requests on that ethernet interface. The kernel takes care of finding an appropriate IP address either statically or by DHCP depending on bootargs as listed above.

The appropriate change to make is usually to edit /etc/network/interfaces and comment out the line 'auto 0' if you're using eth0.

- auto 0
+ #auto 0

[edit] The AVR32 no longer resolves domain names

Because the kernel dhcp server which is used when booting over NFS doesn't update the nameserver registry, you must do this manually. Get the IP address of the local nameserver off your network administrator and add a line to /etc/resolv.conf like

nameserver [ip address]

Note that /etc/resolv.conf may be a symlink, if this is the case remove the symlink and create the regular file /etc/resolv.conf with the above content.

Personal tools