Hello world at Beagleboard (native toolchain gcc)
Created on 04 May 2012 14:51
As the first step of my journey, this step-by-step guide is that I used to set up a native toolchain (a gcc complier) at Beagleboard and compile/build the program to get executable file locally at the Beagleboard. Since I mainly use Windows and running the Matlab at 64-bit Windows 7, my first choice is to set up a Windows-based development environment for Beagleboard. (I tried a VMwavre virtual machine with ubuntu, but it failed to install Matlab on a virtual machine. I guess this is because the Matlab need to check the series number of harddrive and Enternet MAC address, whileas the series number of MAC address in a virtual machine seems different from those in the host windows. That is another long story. If you have solution to this, it will be really appreciated to let me know.)
Writing a hello world programme, building it and run it is always the first step for a programmer. Although there are have been instructions on how to build a image to start the Beagleboard, It is a technical-intensive and deep learning curve. Too deep to build a Hello world easily. Since the Beagleboard has come with a SD card with a linux, it is more exciting to build your own programme and run it at BB. I have spending nearly ten days to find how can I do this. Thanks to Gerard Marull Paretas and his introduction document (www.teslabs.com/wp-content/uploads/2010/02/beagleboard.pdf) which gives me a good starting point.
The instructions below assume a 64bit PC (intel) running Windows 7 and a Beagleboard-xM running linux unbuntu 11.04.If you have a different Windows/Linux distribution, the menus and other details may vary. Also I have wholesale copied instructions from various websites that showed how to do some of the individual bits. I originally wrote this for my own memory and I tried to keep the links to these website and people, but apologize for not properly attributing all of these, since I have forgotten where I borrowed from.)
There has been a lot of step-by-step tutorial on installing a linux on the Beagleboard. I'll save that for another day, as I am interested in build your own application programm and run it on your beagle board.
For a simple installation, I used the Matlab 2012a to build the ubuntu for my BB. Simply type ">> targetInstaller" at the Mablab command window and follow the instruction there. (More details see Install Target for Use with BeagleBoard Hardware, http://www.mathworks.co.uk/help/simulink/ug/install-target-for-beagleboard-hardware.html).
In my case, the host computer is a PC running Win7. The steps are summarized as follows, for more details, see Open a Serial Command Line Session with the BeagleBoard Hardware.
(2a) Use a USB-Serial cable to connect the usb port of the host computer to the DB9 port of the beagle board.
(2b) If it is your first time to use the USB-serial cable, you need install a driver for the USB-serial cable.
(2c) Identify the COM port for your serial connection. In Win7, search and open the 'Device Manger' and expand Ports (COM&LPT) to see the list of serial connections. Usually, you will find a device called "Prolific USB-to-Serial Comm Port (COM#)", where '#' is a number.
(2d) Start PuTTY by typing 'Putty' at the 'Search Programmes and files' box in the Start menu and click the

(2e) In the PuTTY window, select the Serial Category and configure the selected COM port to:
Serial line to connect to: COM# (in my laptop, it is COM6)
Speed (baud) 115200
flow control: None
![Machine generated alternative text: PuTTY Configuration
Category:
9 Session J Options controlling local seilal lines
Logging Select a serial line
9.. Terminal
Keyboard SerraI line to connect to COM1
Features Configure the serial line
Q.. Window Speed firaud) 115200
Appearance
. Databits B
Behaviour
[ Tran&ation Stop bits 1
Selection
Colours Panty [None V j
8 Connection Row control [None .]
Data
Telnet
f Riogin
Ë SSH
j bout ] [ Open ][ Cancel ]](1_Helloworld_at_Beagleboard_files/mhtBBFB1.png)
(2f) In the PuTTY dialog box, select the Session category.

You may type in a name in the 'Saved Sessions' and click 'Save' button for future use. The next time when you start PuTTY, you can select the session you saved and click 'Load' and then 'Open' to start serial session straightforward.
(2g) When a terminal window opens, press the Enter. Then type in the user name ubuntu and the password temppwd to login.

To install ARM GNU/LINUX compiler collection from Ubuntu, enter the following at the command line.
$ sudo apt-get install gcc-4.5-arm-linux-gnueabi
You may choose other compilers, such as the CodeSourcery ARM/LINUX Lite compiler, etc. The good thing of CodeSourcery is that they provide a free lite version that runs in Windows 7 without any Cygwin/MingWin etc. That is great for me (I use Linux from time to time, Linux is great, but I feel more comfortable when using windows. In particular, installing a programme in Windows is straightforwad, you do not need keep googling to sort out the dependences of packages). I save it for another day. More details, see http://elinux.org/BeagleBoard_Ubuntu_%26_DSP_From_Sources
You can verify that the gcc is set up correctly by entering
$ gcc
You should get an error message
"gcc: no input files"
This suggests that the compiler has been installed sucessfuly and beagleboard can find the gcc compiler.
Use nano to edit the "hello world" programme. Click here to download the main.c source code.
main.c(hello world)
____________________________________________
#include <stdio.h>
int
main (void)
{
printf("Hello Xuewu Dai\n");
return 0;
}
____________________________________________

Press Ctrl+x.
Enter Y to save the modified buffer.
For "File
Name to Write: main.c", press Enter.
Then, enter
$ ls
You will see a file 'main.c' at your current folder.
To compile your programme and generate an executable file, enter
$ gcc main.c -o helloworld
I name the output executable file to helloworld.
Run the programme by entering
$ ./helloworld
Great! You will see
'Hello Xuewu Dai'

I feel difficult to edit program in nano. A better way is to edit the program at the windows host PC and transfer the file to the beagleboard. You can use usb drive, but it would be more convient to use Ethernet connection without a lot of plug-in-and-plug-out. I decide to use SSH+WinSCP to transfer the file vis Ethernet.
Before transfering the file at WinSCP, we need set up the IP configuration at both Beagleboard and the host PC (Windows 7).
If you want edit your program at the terminal window, you do not need do this step.
The IP address of the Beagleboard is configured by the interfaces file at
/etc/network/interfaces. You need to edit the file to modify the IP configuration.
At the terminal window of PuTTY,
(3a) Display the conetents of the /etc/network/interfaces file. Enter
$ cat /etc/network/interfaces
(3b) Create a backup of the interfaces file. Enter
$ sudo cp /etc/network/interfaces /etc/network/interfaces.backup
(3c) Change the
permissions of interfaces so you can edit the file. Enter:
$sudo chmod 777
/etc/network/interfaces
Enter the root password when prompted (default: temppwd).
(3d)Edit
interfaces using a simple editor called nano.
Enter:
$ nano interfaces
(3e) Edit the
last word of line that starts with iface eth0 inet.
To use DHCP services, edit the line to say:
iface eth0 inet dhcp
For static IP settings, add lines for address, netmask, and gateway. For example:
iface eth0 inet static
address
192.168.2.2
netmask
255.255.255.0
gateway 192.168.2.1

(3f) Tell nano to
exit and save the changes:
Press Ctrl+x.
Enter Y to save the modified buffer.
For "File
Name to Write: interfaces", press Enter.
The nano editor confirms that it
"Wrote # lines" and returns control to the command line.
(3g) Restore the
original file permissions. Enter:
$ sudo chmod
u=rw,g=r,o=r interfaces
Enter the root password when prompted. (default: temppwd)
Check the ip seetings. Enter
$ Ifconfig

(3h) If the inet addr, netmask and gateway is not as same as the interferces, you need to refresh the network configuration. Enter
$ /etc/init.d/networking restart
And then check the IP settings to confirm the modification has taken effect.
(3i) Use a Ethernet cable to connect the BB to a hub or directly to your computer's LAN port.
Open a DOS command window at the host computer (note, it is the DOS command window at your host Win 7 computer, not the PuTTY window) and Enter
Ping 192.168.2.2
Easiest method is probably going to be SFTP/SCP.
(6a) On the BeagleBoard
Install ssh if not already installed:
$ sudo apt-get install ssh
(6b) On the Windows Host computer,
You can grab a copy of WinSCP or the Portable version for your windows machine. Then in WinSCP, put the linux machine name as the server (or IP if you can't connect via name). Once connected, navigate to preferred/necessary directories and drag and drop as desired.
For more "permanent" solution, you could install samba on your linux machine and then connect from the windows machine, but that would require learning how to configure samba so that the two systems can connect to each other.
<http://superuser.com/questions/315566/transfer-files-from-windows-to-linux-over-the-network>
![Machine generated alternative text: WinSCP Login I 11
Session Session
Stored sessions Host name: Post number
Environment
192.168.2.2 22
Directories
SSH
ijser name: Eassword:
Preferences
ubuntu
Private hey file:
Protocol
Eue protocol: [SFTP ‘rj LAllowSCPfallback
[_Select color_]
D Advanced options ______
L AbouL. J Languagesj 1n L Save... J L Close J](1_Helloworld_at_Beagleboard_files/mhtBC8D1.png)

You can check the files at your home directory of Beagleboard through the PuTTY serial session. At the PuTTY window, enter
$ cd ~
$ pwd
$ ls -l
You will find the new file main.c

Created
with Microsoft OneNote 2010
One place for all your notes and
information