Skip to Content

My first port on Ben NanoNote: gnuchess (Howto)

Finally I have some time to be able to hack a little bit with somthing I was curious since I have Nanonote, and is how to port applications using the  OpenWRT framework,so based on the manuals an HowTos  of Qi Hardware and OpenWRT, I set to myself the goal to port a simple application without many dependencies and not included yet on the repositories, so I remember an old friend (Steve this one is for you :P) and I choose gnuchess , following I detail the steps I have done to have a pretty package to intall in Ben Nanonote

Set up of the framwork and toolchain compilation
on Ubuntu/Debian to obtain the packages needed to start working with OpenWRT execute the following in a console:
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make gettext unzip libz-dev libc6 ncurses-dev subversion libxml-simple-perl gawk git-core

We will create a folder where we will save all related OpenWRT stuff, and we will download the framwork with git from qi-hardware repositories to be up to date and future updating.

mkdir openwrt
cd openwrt
git clone git://projects.qi-hardware.com/openwrt-xburst.git
cd openwrt-xburst
git fetch origin
git checkout --track -b xburst origin/xburst
make menuconfig


Here a popup will be shown with a graphical menu, this is the OpenWRT configuration menu, as you can see is based on the Linux kernel configuration menu, here we can select the packages we want to compile and a lot of parameters to generate a firmware to fit our needs, for now we will focus on select the Target Platform.

On  Target we have to select "Ingenic Xburst" which is the Ben NanoNotes platform

Select Exit and select Yes when asked to save changes

We can return to that menu executin  "make menuconfig"
To compile the toolchain, last kernel and some basic packages just type the folowing in the console:
make

Creating a Package with OpenWRT
In OpenWRT the packages are defined by a Makefile file, we will not enter in too much detail about aaaaaalll the parameters,variables and functions you can use in that file, instead we have take the example from here and we have modified it to fit our package

Now we will create a folder to create our own package and avoid messing with core ones of OpenWRT framwork, out of folder openwrt-xburst, to the folder we we create now you can name it as you like

cd ..
mkdir mutroxports

Due I have the willing, if time and fortune allow me, to create various ports I have createda s subfolder for games inside this folder
mkdir mutroxports/games
and a folder to the package itself
mkdir mutroxports/games/gnuchess
and we will create a text file witho our favourite editor in my case  joe
joe mutroxports/games/gnuchess/Makefile

Lines marked as  # are coments to explain briefly each part

# Copyright (C) 2008 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
#

include $(TOPDIR)/rules.mk
##name of the package
PKG_NAME:=gnuchess
## version application we will i
PKG_VERSION:=5.07
## Version number of the package itself
PKG_RELEASE:=3
##Name of the file with the source code, we use the variables we just have defined
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
##Url where the source file is aviable for downloading
PKG_SOURCE_URL:=http://ftp.gnu.org/pub/gnu/chess
## program to decompress de source file
PKG_CAT:=zcat

include $(INCLUDE_DIR)/package.mk
#Definition of the package, title, classification and url of the project
#this info will be included in the ipkg and used to classify in the menuconfig
define Package/gnuchess
  TITLE:=Chess GNU from FSF
  SECTION:=games
  CATEGORY:=Games
  URL:=http://www.gnu.org/software/chess/chess.html
endef
#Folder where we will extract source and build the application
#BUILD_DIR is a framework variable of  OpenWrt commonly used by all packages
PKG_BUILD_DIR:=$(BUILD_DIR)/gnuchess-$(PKG_VERSION)
#Long description of the application
define Package/gnuchess/description
  GNU Chess lets most modern computers play a full game of chess. It has a plain terminal interface but supports visual interfaces such as xboard and eboard
endef
#If you don't have to pass any especial parameter to   ./configure you can forget about the following block.
define Build/Configure
      $(call Build/Configure/Default)

endef
#Defining from and where to copy binaries and libraries when installed
#gnuchess builds the binary inside his src folder
define Package/gnuchess/install
    $(INSTALL_DIR) $(1)/usr/sbin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/gnuchess $(1)/usr/sbin/
endef
#Final instruction to build the package.
$(eval $(call BuildPackage,gnuchess))

Save and go back to the openwrt-xburst folder, where we will include our folder as feed.

Third party packages, the  feeds
OpenWRT includes an easy way to agregate packages not included in his own repositories, we will include our folder as feed.  
On openwrt-xburst folder
cp feeds.conf.default feeds.conf
with this we activate some feed included by default by OpenWRT growing the packages available.
Add following line to the end of the feed.conf file
src-link mutroxports /path/where/you/created/folder/openwrt/mutroxports
now we will include the packages to the framework.
./scripts/feeds update
./scripts/feeds install -p mutroxports

and the next step is to compile our packages, we can select it in the menuconfig, than thanks to the black magic of OpenWRT has been inclueded in a new section called Games, as we define in the CATEGORY variable of the Makefile

<M> build just as packages, <*> builds packages and inclue it inside firmware
Due build a full firmware is out of the scope os this Howto , we will select <M>

That way when we execute "make" this package will be generated as well.

We can also build that package only directly from console without needed to review/rebuild all stuff.

make package/gnuchess/compile

OOOH it diiidn't  wooooork... it briings an eeeerrroorrr,(I'm evil , isn't? }:P)
To take a look what can be the cause of this error we can execute
make package/gnuchess/compile V=99
This use to happen, most applications are not thinked to work in other arquitectures or to do crosscompiling, but in this case it has a easy solution, and will help me to introduce the last part of the HowTo.

Patches , solving errors and adapting the code
In the folder where we have defined our Makefile, we can include another subfolder called  patches, there we can include the modification needed to application original source code to make the program able to compile, to strip unneeded parts, adapting gui for lower resolutions... well anithing we have to modify in the source code to adapt it to the target platform.
In our example the error is a different variable definition between the header common.h and the file input.c, in the line 719 of the common.h file we have to change extern by static , to generate the patch file I have made the following, in a temp folder, if posible far away of the one we have being working  on to not mess up things:
Download the original sources
wget http://ftp.gnu.org/pub/gnu/chess/gnuchess-5.07.tar.gz
extract
tar -xzf gnuchess-5.07.tar.gz
make a clone of the just extracted folder
cp gnuchess-5.07 gnuchess-5.07.mod
make the modifications in the cloned folder
joe gnuchess-5.07.mod/src/common.h
and generate the patch with following command
diff -crB gnuchess-5.07 gnuchess-5.07.mod > 001_static_definition.patch

And we have the patch created, the tree numbers in the beginning of the patch file name is to let OpenWrt control the order how the patch has to be applied if there is more than one pathch to be applied, but not applicable on this case.
If any body knows a more confortable way of generating patch, I'm all ears :P

Create a folder patches inside the gnuchess folder
mkdir /whereeveritis/openwrt/mutroxports/games/gnuchess/patches
cp 001_static_definition.patch /
whereeveritis/openwrt/mutroxports/games/gnuchess/patches

and now yes!, we return to the openwrt-xburst folder and execute
make package/gnuchess/clean
make package/gnuchess/compile
make package/gnuchess/install

And if every thing works as expected in the openwrt-xburst/bin/xburst/packages you will finde a brand new ipkg packages ready to install in Ben as you can find in  http://tuxbrain.org/downloads/nanonote/packages :)

In  http://tuxbrain.org/downloads/nanonote/mutroxports you can find the Makefile and the patches folder

This tutorial has been created quickly, at late hours of the night, and translated without too much deep review so any mistake you can find on it please report in the comments and I will try to fix it as soon as possible :)