-
Notifications
You must be signed in to change notification settings - Fork 4
Development Environment Setup
This page is intended to guide you in setting up your development environment for the orange pi. Instructions are relevant for Ubuntu 16.04 and may have to be adjusted for other front end development machines.
Much of the information on this page is copied or otherwise borrowed from Tom's very helpful orange pi notes. If/when you find holes in the information on this page, Tom's notes are a good first place to check for more in depth information.
The instructions here are made mostly from memory of when I got this set up running on my particular machine in my particular network configuration. Therefore, these instructions are far from infallible. It is likely that you will need to do extra research/reading and troubleshooting to get all of these steps working properly for your particular development environment.
- Orange Pi
- USB to Serial TTL Cable (I've been using this one)
- Micro SD Card and Adapter (I've been using this one)
- Ethernet Cable (If your board has an Ethernet Port)
- Power Adapter (I've been using this one)
- (Recommended) Power Strip
The power strip is recommended for easy power cycling of the orange-pi. It does not have an on/off switch, and unplugging and plugging back in the barrel jack power adapter can be annoying and will probably break the power input socket on the board after a while. Plugging the power adapter into a power strip allows one to use the power strip's on/off switch to power cycle the board more easily.
There are lots of ways to form serial connections to other machines or devices like putty, cygwin, etc. I am using 'screen', so that is what I will demonstrate below. If you already have a preferred serial connection application then feel free to use it instead.
You will have to locate the GPIO pins designated to serial I/O for your flavor of orange pi. On some boards they are part of the main GPIO pin array. On the orange pi one and orange pi lite they are separate pins labeled TX, RX, and GND next to the ethernet port or one of the usb ports.
The serial end of the cable is color coded and should attach as follows:
- white: TX
- green: RX
- black: GND
- Install the 'screen' linux utility.
sudo apt-get install screen
- Plug in the Serial TTL to USB cable as described above.
- Identify the device folder the the cable. This can be done by checking the tty devices both before and after plugging in the cable with
ls /dev/tty*
On my machine it is /dev/ttyUSB0.
- Open up a new linux terminal for the session. Ctrl+alt+t and Ctrl+shift+t are useful shortcuts.
- Start a screen session to your tty device with a baud rate of 115200.
sudo screen /dev/<your_tty_device> 115200
Tom has instructions on how to set this up here. They are summarized below.
This can be a tricky process. Ultimately, it is easier and faster to simply download the pre-built binary for your orange-pi board here. If that is not possible, Tom has some notes on this here, and I have provide some loose instructions on how to do this below:
Note: before building u-boot you will need the arm cross compiler toolchain. For some reason, I was only able to build u-boot with the 'arm-none-eabi' toolchain. Google searching the issue I had with the other toolchains suggested that is a known bug with certain versions of the gnu arm toolchain. Hopefully, the same thing doesn't happen to you. If it does use:
sudo apt-get install gcc-arm-none-eabi
Next, download the h3 allwinner linux and u-boot sources:
git clone https://github.com/orangepi-xunlong/orangepi_h3_linux.git
You may have to edit the file 'build_mainline_uboot.sh' so the the CROSS_COMPILE prefix is correct for you toolchain. E.g. I had to edit this to be
CROSS_COMPILE=arm-none-eabi-
You can then build u-boot with
sudo ./build_mainline_uboot.sh <orangepi_version>
where orangepi_version is your flavor of orange pi (e.g. one or pc). You should then be able to find the u-boot binary at build/uboot/u-boot-sunxi-with-spl.bin.
A decent tutorial on this is given by orangepi.org here. I have summarized it below.
- Plug in your SD-Card/Adapter pair.
- Find out the device file identity of your SD-Card/Adapter pair. On my machine it usually shows up as /dev/sdb or /dev/sdb1.
sudo fdisk -l
(Note: if you are still in doubt about which device it is, you can do 'ls /dev/sd*' before inserting the SD card and after to see which device folder appeared when the SD card was inserted.
- Write u-boot onto the SD card.
Warning: Be very careful with this part. Make sure you are writing to the correct disk device (which is the SD card). If you make a mistake here, you could accidentally overwrite or wipe out your computer's file system. Double check all commands before you hit enter. Think carefully about what you are typing. Do not accidentally format the wrong disk.
sudo dd if=/dev/zero of=/dev/<SD_Card_device_folder> bs=1024 count=2048
sudo dd if=<u-boot_binary> of=/dev/<SD_Card_device_folder> bs=1024 seek=8
sync
Now that you have a bootable SD Card it is time to set up the orange pi for network booting.
-
Insert your SD-Card into the orange pi.
-
With a serial terminal session on, turn on the orange-pi. You should see some output from u-boot.
(Tip: Sometimes the serial/ttl cable connection can get out of sync, producing garbled, half-intelligible output in your screen terminal. When this happens to me, I'm able to fix it by unplugging the usb end of my serial/ttl cable from my computer and then plugging it back in and trying again.)
-
Interrupt the u-boot count-down by typing any character as suggested.
-
Issue the following commands:
setenv bootaddr 0x40000000
setenv bootfile xinu.bin
setenv bootxinu "echo Booting ${bootfile} via TFTP; dhcp ${bootaddr}; go ${bootaddr}"
setenv bootcmd "run bootxinu"
saveenv
Now, the orange pi should always look for a boot file named xinu.bin in you computer's /var/lib/tftpboot directory.
- Before restarting, get the MAC address for your network interface with
printenv ethaddr
Tom has some helpful notes on this here. This part of the set up is dependent on your particular network configuration. A very general example is provided below, but it is likely that you will have to do further research and troubleshooting to get things working on your system. NOTE: You should replace "USER" below with your user name.
- Install a DHCP server.
sudo apt-get install isc-dhcp-server
- You will have to edit the DHCP server/daemon configuration file (/etc/dhcp/dhcpd.conf) to fit your particular network set up. When doing this, I found the comments to be adequately verbose and helpful. Read through this file very carefully and edit flags variables as needed. I had to edit the following:
- options domain-name "USER.lan";
- option domain-name-servers ubuntuserver.USER.lan;
- uncomment the authoritative flag
I then added this subnet configuration. Feel free to use this as a template and edit values for your network configuration as needed:
subnet 192.168.0.0 netmask 255.255.255.0 {
interface enp4s0;
range 192.168.0.0 192.168.0.254;
option domain-name-servers ubuntuserver.USER.lan;
option domain-name "USER.lan";
option broadcast-address 192.168.0.255;
default-lease-time 600;
max-lease-time 7200;
}
- In the DHCP server/daemon configuration file (/etc/dhcp/dhcpd.conf) add the following:
host orangepi {
hardware ethernet <orange_pi_eth_addr>;
option host-name "orangepi";
server-name "<ubuntuserver.USER.lan>";
filename "xinu.bin";
}
- Restart server:
sudo service isc-dhcp-server restart
NOTE: Before restarting, make sure that your ethernet interface has an IP address in the range defined for the subnet in your dhcpd.conf file. Otherwise, the service will fail to start. Again, this depends on your particular network configuration. If, like me, you are connecting directly to the orange pi on you ethernet interface and nothing else, then you may have to assign the interface an IP address in this range:
sudo ifconfig <INTERFACE_NAME> <IP_ADDRESS> netmask
- Install a TFTP server.
sudo apt-get install tftpd-hpa
- Restart server:
sudo service tftpd-hpa restart
If you are just trying to get things up and running and are not too concerned about dynamic IP addresses, then you can set default values in u-boot so that DHCP isn't necessary. Go back to the u-boot environment set up mode you used to configure u-boot above and enter:
setenv ipaddr <IP_ADDRESS>
setenv serverip <ETH_IF_ADDRESS>
saveenv
This sets the orange pi's default IP address to IP_ADDRESS and tells is to look for any server at the default IP address ETH_IF_ADDRESS, which is the address of your computer's ethernet interface. You can then modify the boot command to skip the DHCP step and jump straight to TFTP:
setenv bootxinu "echo Booting ${bootfile} via TFTP; tftpboot ${bootaddr} ${bootfile}; go ${bootaddr}"
saveenv
While this isn't the preferred network booting configuration in a production type environment, like the Xinu lab, it will get things going for you on your local machine.
Tom has some helpful notes on this here. They are summarized below.
The first time you try to build, you may get some errors when the Xinu Makefile calls certain programs it assumes you have installed. You will have to install these packages as you go based on the error output. Here are some packages you definitely need:
sudo apt-get install gcc-arm-linux-gnueabihf flex bison flex-devel
- Pull the xinu-orangepi source code.
- From the compile directory in the xinu-orangepi repository, build Xinu with:
make clean; make
Note: It is best to always always always clean before you build. I almost never run make alone, but rather, I always run make clean; make.
- Make sure you copy the resulting xinu.bin file to your /var/lib/tftpboot directory and then power cycle the orange pi and you should hopefully see Xinu come alive :)
Here are a couple of nice things to add to your ~/.bashrc or ~/.bash_aliases that will make life a little easier:
alias piscreen='sudo screen /dev/ttyUSB0 115200'
alias cmt='make clean; make; pibin xinu.bin'
alias test='pibin xinu.bin; pieth'
# copy executeable to tftp directory for orange pi
function pibin { # file to be copied
echo "copying $1 for orange pi tftp boot"
sudo rm /var/lib/tftpboot/$1
sudo cp $1 /var/lib/tftpboot/$1
}
The piscreen alias makes it easy to start up a screen session. You will just have to adjust 'ttyUSB0' to whatever name applies to your TTL-USB cable.
The cmt alias (clean, make, test) is the one I use the most. After making a change to source code, you can just type cmt and then power cycle the orange pi and everything else is taken care of.
The test alias and the pibin function work together to automatically copy your xinu.bin to the appropriate tftp directory for u-boot to find. Technically, the rm in pibin isn't necessary, but I find it helps me from going crazy when a build fails with cmt but I don't notice it. This way, the old xinu.bin file that was in the tftp directory is erased so that u-boot fails rather than loading the old xinu.bin and making me think I am crazy when the changes I just made don't have any effect.