Fonera Development

From FON Wiki Beta

Jump to: navigation, search
Changes and instructions described in this page are meant to be done by developers only. Applying these changes to your La Fonera might irremediably damage it. FON will not be held responsible for their consequences. Read instructions carefully!

Contents

How to add extra packages to the firmware

  • Example of adding "bluetooth" support to the "Sylvester" Fon Firmware
    • Remark this will give errors on dbus dependency
% cd fonera2.0-beta2-sylvester.GPL/openwrt
% ./scripts/feeds update -a
% ./scripts/feeds list
% ./scripts/feeds install -p packages bluez-utils
Remark : no dependancies...
  • Never install ALL packages... only the ones you require... do it one by one...so a "failed" one will not break your build environment
./scripts/feeds install -a
  • regarding lines with colons, those are conditional dependency specificiations, I guess the problem can be solved by using feeds.pl and metadata.pm from openwrt trunk:
cd openwrt/scripts
wget https://dev.openwrt.org/browser/trunk/scripts/metadata.pl 
wget https://dev.openwrt.org/browser/trunk/scripts/metadata.pm
wget https://dev.openwrt.org/browser/trunk/scripts/feeds

how to compile a specific package

  • get the Fonera sdk
svn co http://svn.fonosfera.org/fon-ng/trunk fon
cd fon
./install.sh
cd openwrt
make menuconfig (choose Fonera 2.0 and exit)
./scripts/feeds update -a
  • Now which package do you need? Rsync?
./scripts/feeds install rsync
++ mkdir -p /home/steven/FON/trunk/openwrt/staging_dir/toolchain-mips_gcc4.1.2
++ cd /home/steven/FON/trunk/openwrt/staging_dir/toolchain-mips_gcc4.1.2
++ mkdir -p bin lib include stamp
Installing package 'rsync
  • Go again in "make menuconfig" and enable this tool in the "network" section as a "M"odule
  • Now that you selected it...let's compile just this tool:
make package/rsync/{clean,compile} V=99
  • After compilation you will find your package here :
ls bin/packages/mips/rsync*
  • If you now do make menuconfig and change the target into "fonera 2.0n" and redo make package/rsync/{clean,compile} V=99 you can find it here :
ls bin/packages/mipsel/rsync*
  • If you want to compile eg "amule" beware to also "./scripts/feeds install wxbase and others... The errors will show you the necessary dependancies :-)

get only the interesting stuff out of an ipg

  • you don't need to install the whole "pkg" file... you can
cd bin/packages/mips
mkdir test
cd test  
tar xzvf ../rsync_3.0.6-1_mips.ipk
tar xzvf data.tar.gz
  • The usefull bit is ./usr/bin/rsync which can only be run on a MIPS device like La Fonera 2100,2200,2201 or 2202
  • To run it on a 2302 (Fonera 2.0n) you will require a MIPSEL rsync.

How to compile "developer" version for real

  • Choosing "developer" in make menuconfig doesn't do anything. Developer mode will still be "commented" out.
  • edit the file fon/fonbase/files/etc/config/registered and remove the "#" at the start of line 3
config fonreg fonreg
 option registered 0
 option dev 1
  • make package/fonbase/clean && make V=99
  • after a while the image will be inside bin/openwrt and it will offer you "developer" mode after the flash...

Repositories

For the Fonera N

  • Create a directory to allow opkg to create locks:
mkdir /usr/lib/opkg
  • Update opkg.conf with a source with valida packages for the fonera 2.0n architecture:
    • just edit /etc/opkg.conf and add the line:
src snapshots2 http://downloads.openwrt.org/kamikaze/8.09.2-RC2/rb532/packages/
  • At the end, just update opkg lists:
opkg update

Collected Errors

  • when using opkg to install something you get a "collected error" due to not enough space left on the Fonera
    • Only have 0 available blocks on filesystem /
    • You can fix this with the following :
echo option force_space >> /etc/opkg.conf

Debugging

  • use the following to check latest logs
logread 
  • If you have a serial console-cable:
    • try to disable the watchdog (chmod -x /sbin/watchdog) and check for out-of-memory conditions
    • watchdog timmer can't be halted on a running system so you need to reboot after disabling it

No more space

  • Opkg is installed on La Fonera but you can not install "much" or "big" stuff in main memory. 4 megabyte to be exact.
  • If your application is bigger...try to make it an image that can be installed/mounted on a pendrive...
    • Check the Torrent application on how this is done!
  • To recover from "no more space"
  • on jffs2 you need a remount & reboot to recover the space
    • mount -o remount /jffs2
    • reboot

accessing the webcam from WAN (internet)

  • access it directly without using the "java" client, please replace <password> and <dyndns url>
    • http://admin:<password>@<dyndns url>/luci/fon_devices/fon_webcam/mjpeg/
  • another solution is to open up SSH on your internet modem & fonera on WAN side... and use putty & tunnel-config
    • http://127.0.0.1 would then give you the fonera interface as if you were at home behind your fonera
    • linux:
      • ssh -D 8010 root@<dyndns url> and then add 127.0.0.1, port 8010 as socks proxy to firefox
      • also the application "dante-client" provides a command called "socksify"

forwarding certain ports to other servers

  • The new 2.3 firmware uses only https on the WAN side (if you enable it)... you can use these lines to route port 80 now to another server in your network
echo "iptables -t nat -I PREROUTING -p tcp -i eth0.1 --dport 80 -j DNAT --to serverip:80" >> /etc/firewall.user
echo "iptables -I FORWARD -p tcp -i eth0.1 -d serverip --dport 80 -j ACCEPT" >> /etc/firewall.user

Torrent

  1. install opkg (see this wiki)
  2. for the current version of firmware use this repo http://ipkg.nslu2-linux.org/feeds/openwrt/fon-ng/mips/ for transmission .pkg file...install directly on root / or in a pendrive with ext2/3 fs and then make all link that are needed
  3. If in the package there isn't the "web" directory take it from official transmission tarball
  4. move the web directory in the right place (i don't remember where) or make link to a pendrive with ext2/3 fs
  5. run transmission
  6. type in your browser http://ip_fonera:9091
  7. adjust download dir to usb disc

Additional filesystems

http://downloads.openwrt.org/kamikaze/8.09/atheros/packages/

Package Description
kmod-fs-cifs_2.6.26.5-atheros-1_mips.ipk Cifs (Network share)
kmod-fs-ext2_2.6.26.5-atheros-1_mips.ipk Ext2 (allready supported on F2)
kmod-fs-ext3_2.6.26.5-atheros-1_mips.ipk Ext3 (Allready supported on F2)
kmod-fs-hfs_2.6.26.5-atheros-1_mips.ipk HFS (MacOSX)
kmod-fs-hfsplus_2.6.26.5-atheros-1_mips.ipk HFSplus (MacOSX)
kmod-fs-isofs_2.6.26.5-atheros-1_mips.ipk ISO 9660
kmod-fs-minix_2.6.26.5-atheros-1_mips.ipk Minix
kmod-fs-msdos_2.6.26.5-atheros-1_mips.ipk MsDos
kmod-fs-nfs-common_2.6.26.5-atheros-1_mips.ipk NFS
kmod-fs-nfs_2.6.26.5-atheros-1_mips.ipk NFS (Network Filesystem Share)
kmod-fs-nfsd_2.6.26.5-atheros-1_mips.ipk NFS
kmod-fs-ntfs_2.6.26.5-atheros-1_mips.ipk NTFS (Allready supported by F2)
kmod-fs-reiserfs_2.6.26.5-atheros-1_mips.ipk ReiserFS
kmod-fs-udf_2.6.26.5-atheros-1_mips.ipk UDF
kmod-fs-vfat_2.6.26.5-atheros-1_mips.ipk VFAT (Allready supported by F2)
kmod-fs-xfs_2.6.26.5-atheros-1_mips.ipk XFS

Using Lua

(still work in progress)
  • When compiling the fon sourcecode the firmware will contain "binary" .lua files on La Fonera 2;
  • in the FON sourcecode one can get the "fon" library in dl/luci-0.9+svn268.tar.gz which doesn't exist on h[ttp://luci.freifunk-halle.net/Download Luci.freifunk-halle.net]
    • in this archive one can browse to libs/fon/luasrc/fon.lua which is "readeable" and editeable
    • One can adapt it with any text editor and replace the "binary" compilation on the fonera.
    • Compilation just saves 50% size but not necessary. It will keep it's extension (compiled or not)

Using Luci

Hello World

  • cd FON/fon-ng/trunk/luci/applications
  • ls -lrt
    • you will see many examples like luci-ddns, luci-azareus, luci-openvpn, luci-youtube, ...
  • mkdir luci-hello
  • cd luci-hello
  • cp -r ../luci-ddns/* .
  • cd luasrc
  • cd controller
  • rm ddns.lua
  • vi hello.lua
module("luci.controller.hello", package.seeall)
function index()
   local page=entry({"fon_services","hello"}, call("helloworld"), "Hello World")
   page.icon_path="/luci-static/resources/icons/"
   page.icon="HelloWorld.png"
end
function helloworld()
   luci.http.write("HELLO LUCI")
end
  • By doing "fon_services","hello" we are putting our application in the submenu "fon_services"
  • the "Hello World" will be the text label of our menu option
  • By pressing the button it will show a white page containing "Hello Luci"
  • if you put in /FON/fon-ng/trunk/luci/applications/luci-hello/htdocs/luci-static/resources/icons/ an image HelloWorld.png with max size 85x85 in PNG (transparancy is higly recommended) it will be shown in the submenu together with the "Hello World" sub-textlabel
  • go back to /FON/fon-ng/trunk/luci
  • make runhttpd
    • No errors should be mentioned
    • open your browser and visit "http://localhost:8080"
    • you should see the default FON menu...
    • go to "Services"
    • You should see your Hello World application

Hello World Part 2

luci
 |-> applications
       |-> luci-hello
               |- Makefile
               |-> htdocs/luci-static/resources/icons/hello.png (Your pictures/icons/...)
               |-> root/lib/uci/schema/default/hello (Your application system settings)
               |-> luasrc
                      |-> controller/hello.lua (this is your template that mentions where it will be shown, what is shown, which functions & pages it can call on)
                      |-> i18n/hello.en.xml hello.en.lua hello.de.xml hello.de.lua ... (Used for translations & showing the fields you will be asking to fill in)
                      |-> model/cbi/hello.lua (here the links are made between the used fields & translations (i18n) and your systemsettings
                      |-> view/hello/something.htm (static texts (errors?) to refer to & show)
  • the minimal is the Makefile and the luasrc/controller
  • With every "change" you have to rerun make runhttpd locally on your develepmont machine?

What is Luci

  • its our "database/registry/repo/..." existing out of flat files with typed/named sections
  • Examples
uci help
uci show
uci show fon
uci show fon.private
  • option can be a list
config foo bar
option a 1
list b 2
list b 3
list b 4
so, uci get x.bar.b will list 3 values
  • we have a global uci read cursor on the run state /var/state
env.uci_state:get
  • we use uci also on a non persistent ram folder to store runtime info
    • so you get cursor() and cursor_state()
    • env is a global every controller gets passed, to make sure not every controller creates a uci instance
    • uci_state is the cursor instance, created with require("luci.model.cbi").cursor_state()
    • and :get is a property just like :set :revert :delete :commit ........
  • Documentation (not complete or uptodate but still valid) : luci.model.uci

FMG

  • Introduction of the FMG (Fon iMaGe)
    • The idea is that the fonera accepts to install plugins on an external hard disk / Pendrive
    • These self contained plugins meaning that if the harddisk is removed, the fonera will think these plugins are not installed
    • One such plugin is the Transmission plugin (Torrent)
    • This technology leaves the door open to other possible big applications, like emule etc
    • Such plugin consists out of *3* files : the FMG, The SWAP image and a Configuration Image
    • They are all saved in /tmp/mounts/Disc-A1/FoneraApps
    • Issues
      • from 2.2.5 to 2.3.0 a namechange was performed which could create problems with old FoneraApps, the old version should be removed manually
  • Tool used : /bin/fon_image.sh
fon_image.sh start torrent /tmp/mounts/Disc-A1/
fon_image.sh stop torrent
  • At creation
    • using /bin/dd if /dev/zero of /tmp/mounts/Disc-A1/FoneraApp
    • Three files : 4MB .fmg, 125MB .swp and 125MB .var
  • Is currently in a "hack" state and will be reprogrammed in c and added to mountd
  • Contains LUA bindign for start/stop : fon/mountd/files/usr/lib/lua/luci/fmg.lua
    • this makes these scripts autostart on mount (there is a setting to prevent this)
    • Might be useful, since starting an app prevents you from safely unplugging a device
  • http://trac.fonosfera.org/fon-ng/browser/trunk/fon/mountd/files/usr/lib/lua/luci/fmg.lua#L50
    • Check out (dirty hack) of luci.fmg.find_discs
  • To Do
    • Single Swap (150mbyte for just .torrent files is a bit too much)
    • Openvpn in an FMG

FonState

  • The fonera does not have a "start/stop" daemon...
    • This makes init.d useless
  • FON introduced the Fonstate daemon where you can add it to "config fonboot"




How to install examples

  • ssh to your fonera 2 (which has internet connectivity)
cd /usr/lib/lua/luci
  • Here you will find the "controller","i18n","model","view", ... modules
  • Installing "jamendo" as example... you can install the others as found in the La_Fonera_2.0#References references
cd controller
wget http://jamendo.googlecode.com/svn/trunk/3rdparty/fonera2/luci-jamendo/luasrc/controller/jamendo.lua
cd ..
cd view
mkdir jamendo
cd jamendo
wget http://jamendo.googlecode.com/svn-history/r38/trunk/3rdparty/fonera2/luci-jamendo/luasrc/view/jamendo/index.htm
  • when you surf to 192.168.10.1 -> Services you will notice the new application "Jamendo"
    • unluckily the jamendo.png doesn't seem to be available, if it were
wget http://jamendo.googlecode.com/svn/trunk/3rdparty/fonera2/luci-jamendo/htdocs/luci-static/resources/icon/jamendo.png -O /www/luci-static/resources/icons/jamendo.png
    • I have visuals but no sound
cd /tmp
wget http://www.fonera.be/rep/FON2202/index.php?get=345 -O madplay.ipk
wget http://www.fonera.be/rep/FON2202/index.php?get=268 -O libmad.ipk
wget http://www.fonera.be/rep/FON2202/index.php?get=86 -O id3lib.ipk
wget http://www.fonera.be/rep/FON2202/index.php?get=487 -O zlib.ipk
opkg install madplay.ipk libmad.ipk id3lib.ipk zlib.ipk
      • Now choose your favourite Jamendo radio... it should play music now :-)

Other How-to

use brctl to bridge 2 interfaces.... Lan/Wan for instance... it's installed at the commandline...who will make a nice gui plugin in luci?
  • How to automount the fonera share
  • How to check if you can access the fonera from WAN?
    • The following should give "1" as solution...if not please change your password...make it complex...use digits and letters!
    • It will require a "reboot" though to have it turn on ssh and such...
grep 'pass_good' /etc/config/system
  • How to turn of "Wireless" (both Public & Private)...
    • Execute the following command in a SSH-shell
wifi down

Firmware

  • use this command to be sure you don't loose the ssh and your settings
uci set registered.fonreg.dev=1
uci commit
tar cvzf /tmp/sysupgrade.tgz /etc/passwd /etc/group /etc/dropbear
/etc/samba/smbpasswd /etc/samba/secrets.tdb /etc/config/firewall
/etc/config/upnpd /etc/config/umtsd /etc/config/registered
/etc/config/gdata /etc/config/facebook /etc/config/flickr
/etc/config/mountd /etc/config/fon /etc/config/ddns /etc/config/wizard
mtd -j /tmp/sysupgrade.tgz -r write fonera20.image image
  • Adding SSH enabled directly in the firmware without the need for a "developer plugin" and 2 reboots?
edit the file inside your FON-NG trunk checkout repository : fon/fonbase/files/etc/config/registered
remove the "#" at the start of line 3
then make package/fonbase/clean && make V=99
after a while the image will be inside bin/openwrt.....
  • While compiling firmware using the SDK we get a loader.bin and an .image in the bin folder, if you want to flash it using the Webgui this has to be changed into a .tgz.gz:
    • The contents is
YYYYMMDD_<MODELNO>_2.3.0.0_RCx.img
<MODEL_LONG>.img (same size as previous)
upgrade
upgrade_enduser
  • legend
MODEL_LONG can be : fonera, fonera+, fonera20, fonera20n
MODELNO can be : FON2100 (5V), FON2200 (7.5V), FON2201 (+), FON2202 (g), FON2303 (n)
  • upgrade contains:
#!/bin/ash
VERSION=$(cat /etc/fon_version)
FAILSAFE=$(cat /etc/failsafe)
DEVICE=$(cat /etc/fon_device)
if [ "$DEVICE" = "fonera20n" ]
then
tar cvzf /tmp/sysupgrade.tgz /etc/passwd /etc/group /etc/dropbear /etc/samba/smbpasswd /etc/samba/secrets.tdb /etc/config/firewall /etc/config/upnpd /etc/config/umtsd /etc/config/registered /etc/config/gdata /etc/config/facebook /etc/config/flickr /etc/config/mountd /etc/config/fon /etc/config/ddns /etc/config/wizard /etc/pureftpd.pdb /etc/pureftpd.passwd /etc/config/luci_dlmanager
mtd -j /tmp/sysupgrade.tgz -r write fonera20n.img image > /dev/null 2>&1 
return 0
else
return 1
fi


External References

Personal tools