OpenWRT compiling programs

780 views
Skip to first unread message

Philipp S

unread,
Jan 26, 2012, 9:31:58 AM1/26/12
to Bifferboard
Hi,

I am trying to compile a hello world program in c. I am using this
hacked version of OpenWrt https://github.com/bifferos/openwrt.

I know that I need to cross compile and I am looking for the SDK for
this release, but I dont know where it
is. In the root directory of this package there is a folder called
toolchain. Is this what I need to compile a simple
hello world in c?

Can someone give me an example how to do this?

I have written a small socket program in c and it would be nice if I
could compile it for bifferboard :).

Thank you

Andrew Scheller

unread,
Jan 26, 2012, 10:00:07 AM1/26/12
to biffe...@googlegroups.com
> I am trying to compile a hello world program in c. I am using this
> hacked version of OpenWrt https://github.com/bifferos/openwrt.
>
> I know that I need to cross compile and I am looking for the SDK for
> this release, but I dont know where it
> is. In the root directory of this package there is a folder called
> toolchain. Is this what I need to compile a simple
> hello world in c?

If your program is sufficiently small, and you're running a 32-bit
linux on your desktop, you can just compile a static binary using your
regular compiler, and just copy (scp) it over to your bifferboard! The
advantage of x86 compatibility :)

But if you do need to use the OpenWRT toolchain, Nicolas seems to be
the current on-list expert...
I used to know how to do it, but can't remember now.

Andrew

Philipp S

unread,
Jan 26, 2012, 10:22:02 AM1/26/12
to Bifferboard
I have a i686 system. If I compile a small hellor world programm on it
as static, then it wont work too.... Think the problem is that
bifferboard is i386 and my system using i686... but i am not sure
about this.

Thank You

On 26 Jan., 16:00, Andrew Scheller <ya...@loowis.durge.org> wrote:
> > I am trying to compile a hello world program in c. I am using this
> > hacked version of OpenWrthttps://github.com/bifferos/openwrt.

Andrew Scheller

unread,
Jan 26, 2012, 10:52:13 AM1/26/12
to biffe...@googlegroups.com
> I have a i686 system. If I compile a small hellor world programm on it
> as static, then it wont work too.... Think the problem is that
> bifferboard is i386 and my system using i686... but i am not sure
> about this.

gcc -m 486 ....
:-)

But as I said, it requires you to be running a 32-bit distro, not a
64-bit distro.

Andrew

nicolas le falher

unread,
Jan 26, 2012, 12:40:57 PM1/26/12
to biffe...@googlegroups.com
> Nicolas seems to be the current on-list expert...

Thanks, but I'm not an expert, just a fan :).


> Can someone give me an example how to do this?

You can compile with toolchain like this :
# cd openwrt/staging_dir/toolchain-i386_gcc-[$GCC_VERSION]-linaro_uClibc-[$LIBC_VERSION]/bin
# /i486-openwrt-linux-gcc -o h h.c
Send binary with scp, and try.

Or you can make an Openwrt package (more useful when you know how it works).

Nicolas.

Rilhas

unread,
Jan 26, 2012, 5:52:53 PM1/26/12
to Bifferboard
If you want to do it the "non-expert" way then you may simply do it
like I did.

I installed Code::Blocks on a 32-bit Ubuntu virtual machine and just
compiled with it. All the magic stays hidden and it works. The
defaults are well chosen, so I only have to tweak whatever things I
know to be special in each of the projects. For example, my SMTP
module needs SSL, so I already know I have to link with SSL. On the
other hand a module that handles strings on my mind shouldn't need
anything special, and so happens that it works in Code::Blocks without
me having to setup any thing special about it.

That must surely mean the default Code::Blocks settings is to invoke
GCC with a 386 or 486 target (or, at least, not using any 686
instructions). I tried using floating point operations and that also
works wthout me needing to adjust anything in Code::Blocks, even with
the Bifferboard missing an FPU.

Using this technique I compiled more than 20 of my modules as static
libraries, I was also able to create SO's from those libraries, and
I've been able to build executables that use the libs, the SO's, and a
mix of the two.

Also, comming from Visual Studio, it was very convenient to have a
similar concept of "workspace" with several projects with multiple
dependencies among them, as well as the ability to share source files
among projects, without having to go to "low level" makefiles. A
visual debugger is also included. So, even though I was comming from
Windows, the transition didn't hurt at all. Now I've been maintaining
both Linux and Windows without any difficulty.

After debugging on my Ubuntu I'm confident that it will work on the
Bifferboard and just copy it there (I even use a visual file copier
that allows me to drag and drop... lazy, huh?). After doing this more
than 100 times for more than 15 executables I feel very confident
about this workflow, and it never went wrong. All updates and
maintenance to executables and SO's is very easy (Code::Blocks
remembers all the settings for all the projects).

I don't think it can get any simpler than that! :-)

Philipp S

unread,
Jan 27, 2012, 8:49:23 AM1/27/12
to Bifferboard
Hi Nicolas,

i am trying to compile the new git from here: https://github.com/bifferos/bb.
I just downloaded it and type make but
neither my laptop(amd64) nor my desktop(i686) can compile this...
I obtained this error message while compiling:

make[6]: Leaving directory `/home/madmoses/bifferboard/bb/openwrt/
build_dir/linux-rdc/linux-2.6.37.6'
i486-openwrt-linux-uclibc-objcopy -O binary -R .reginfo -R .notes -
R .note -R .comment -R .mdebug -R .note.gnu.build-id -S /home/madmoses/
bifferboard/bb/openwrt/build_dir/linux-rdc/linux-2.6.37.6/vmlinux /
home/madmoses/bifferboard/bb/openwrt/build_dir/linux-rdc/vmlinux
i486-openwrt-linux-uclibc-objcopy -R .reginfo -R .notes -R .note -
R .comment -R .mdebug -R .note.gnu.build-id -S /home/madmoses/
bifferboard/bb/openwrt/build_dir/linux-rdc/linux-2.6.37.6/vmlinux /
home/madmoses/bifferboard/bb/openwrt/build_dir/linux-rdc/vmlinux.elf
touch /home/madmoses/bifferboard/bb/openwrt/build_dir/linux-rdc/
linux-2.6.37.6/.image
make -C image compile install TARGET_BUILD=
make[6]: Entering directory `/home/madmoses/bifferboard/bb/openwrt/
target/linux/rdc/image'
make[6]: `compile' is up to date.
cp -fpR /home/madmoses/bifferboard/bb/openwrt/build_dir/linux-rdc/
linux-2.6.37.6/arch/x86/boot/bzImage /home/madmoses/bifferboard/bb/
openwrt/build_dir/linux-rdc/bzImage
# Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
/usr/bin/find /home/madmoses/bifferboard/bb/openwrt/build_dir/target-
i386_uClibc-0.9.32/root-rdc -type f -not -perm +0100 -not -name
'ssh_host*' -print0 | xargs -r -0 chmod u+rw,g+r,o+r
/usr/bin/find /home/madmoses/bifferboard/bb/openwrt/build_dir/target-
i386_uClibc-0.9.32/root-rdc -type f -perm +0100 -print0 | xargs -r -0
chmod u+rwx,g+rx,o+rx
/usr/bin/find /home/madmoses/bifferboard/bb/openwrt/build_dir/target-
i386_uClibc-0.9.32/root-rdc -type d -print0 | xargs -r -0 chmod u+rwx,g
+rx,o+rx
install -d -m0755 /home/madmoses/bifferboard/bb/openwrt/build_dir/
target-i386_uClibc-0.9.32/root-rdc/tmp
chmod 0777 /home/madmoses/bifferboard/bb/openwrt/build_dir/target-
i386_uClibc-0.9.32/root-rdc/tmp
# FIXME: removing this line will cause strange behaviour in the
foreach loop below
/home/madmoses/bifferboard/bb/openwrt/staging_dir/host/bin/mkfs.jffs2
--pad --little-endian --squash -v -X rtime -X lzma --compression-
mode=size -x zlib -e 64KiB -o /home/madmoses/bifferboard/bb/openwrt/
build_dir/linux-rdc/root.jffs2-64k -d /home/madmoses/bifferboard/bb/
openwrt/build_dir/target-i386_uClibc-0.9.32/root-rdc -v 2>&1 1>/dev/
null | awk '/^.+$/'
Compression mode: size
Compressors:
none compr: 39 blocks (24831) decompr: 0 blocks
zlib (prio:80) - compr: 0 blocks (0/0) decompr: 0 blocks
lzma (prio:70) + compr: 523 blocks (787619/1552795) decompr: 0
blocks
rtime (prio:50) + compr: 0 blocks (0/0) decompr: 0 blocks
Compression errors: 0
echo -ne '\xde\xad\xc0\xde' >> /home/madmoses/bifferboard/bb/openwrt/
build_dir/linux-rdc/root.jffs2-64k
cp -fpR /home/madmoses/bifferboard/bb/openwrt/build_dir/linux-rdc/
bzImage /home/madmoses/bifferboard/bb/openwrt/bin/rdc/openwrt-
rdc.bzImage
/home/madmoses/bifferboard/bb/openwrt/target/linux/rdc/image/
mkimg_bifferboard.py /home/madmoses/bifferboard/bb/openwrt/build_dir/
linux-rdc/bzImage /home/madmoses/bifferboard/bb/openwrt/build_dir/
linux-rdc/root.jffs2-64k /home/madmoses/bifferboard/bb/openwrt/bin/rdc/
openwrt-rdc-jffs2-64k-bifferboard.img 0x10
Firmware written to '/home/madmoses/bifferboard/bb/openwrt/bin/rdc/
openwrt-rdc-jffs2-64k-bifferboard.img'
/home/madmoses/bifferboard/bb/openwrt/staging_dir/host/bin/
mksquashfs4 /home/madmoses/bifferboard/bb/openwrt/build_dir/target-
i386_uClibc-0.9.32/root-rdc /home/madmoses/bifferboard/bb/openwrt/
build_dir/linux-rdc/root.squashfs -nopad -noappend -root-owned -comp
lzma -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2 -processors 1
Parallel mksquashfs: Using 1 processor
Creating 4.0 filesystem on /home/madmoses/bifferboard/bb/openwrt/
build_dir/linux-rdc/root.squashfs, block size 131072.
[===============================================================================================================================/]
203/203 100%
Exportable Squashfs 4.0 filesystem, lzma compressed, data block size
131072
compressed data, compressed metadata, compressed fragments, no xattrs
duplicates are removed
Filesystem size 675.34 Kbytes (0.66 Mbytes)
43.16% of uncompressed filesystem size (1564.68 Kbytes)
Inode table size 2669 bytes (2.61 Kbytes)
19.49% of uncompressed inode table size (13696 bytes)
Directory table size 3889 bytes (3.80 Kbytes)
52.17% of uncompressed directory table size (7455 bytes)
Number of duplicate files found 4
Number of inodes 401
Number of files 202
Number of fragments 8
Number of symbolic links 154
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 45
Number of ids (unique uids + gids) 1
Number of uids 1
root (0)
Number of gids 1
root (0)
cp -fpR /home/madmoses/bifferboard/bb/openwrt/build_dir/linux-rdc/
bzImage /home/madmoses/bifferboard/bb/openwrt/bin/rdc/openwrt-
rdc.bzImage
/home/madmoses/bifferboard/bb/openwrt/target/linux/rdc/image/
mkimg_bifferboard.py /home/madmoses/bifferboard/bb/openwrt/build_dir/
linux-rdc/bzImage /home/madmoses/bifferboard/bb/openwrt/build_dir/
linux-rdc/root.squashfs /home/madmoses/bifferboard/bb/openwrt/bin/rdc/
openwrt-rdc-squashfs-bifferboard.img 0x10
Firmware written to '/home/madmoses/bifferboard/bb/openwrt/bin/rdc/
openwrt-rdc-squashfs-bifferboard.img'
( cd /home/madmoses/bifferboard/bb/openwrt/bin/rdc ; /usr/bin/find -
maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs
md5sum --binary > md5sums )
make[6]: Leaving directory `/home/madmoses/bifferboard/bb/openwrt/
target/linux/rdc/image'
make[5]: Leaving directory `/home/madmoses/bifferboard/bb/openwrt/
target/linux/rdc'
make[4]: Leaving directory `/home/madmoses/bifferboard/bb/openwrt/
target/linux'
make[4]: Entering directory `/home/madmoses/bifferboard/bb/openwrt/
target/toolchain'
make[4]: *** No rule to make target `install'. Stop.
make[4]: Leaving directory `/home/madmoses/bifferboard/bb/openwrt/
target/toolchain'
make[3]: *** [target/toolchain/install] Error 2
make[3]: Leaving directory `/home/madmoses/bifferboard/bb/openwrt'
make[2]: *** [/home/madmoses/bifferboard/bb/openwrt/staging_dir/target-
i386_uClibc-0.9.32/stamp/.target_install] Error 2
make[2]: Leaving directory `/home/madmoses/bifferboard/bb/openwrt'
make[1]: *** [world] Error 2
make[1]: Leaving directory `/home/madmoses/bifferboard/bb/openwrt'
make: *** [all] Error 2


So what is the problem here?

If this work then I check your described steps ;)

nicolas le falher

unread,
Jan 27, 2012, 10:41:58 AM1/27/12
to biffe...@googlegroups.com
Philip,

Have you all prerequisites for your distribution ? http://wiki.openwrt.org/doc/howto/buildroot.exigence#prerequisites

Nicolas

Philipp S

unread,
Jan 27, 2012, 11:00:02 AM1/27/12
to Bifferboard
Hi Nicolas,

yes I think so.

nicolas le falher

unread,
Jan 27, 2012, 11:05:47 AM1/27/12
to biffe...@googlegroups.com
Because in bb.git, there is no Makefile for toolchain in target/toolchain.
Untick sdk or toolchain (don't remember name) in "make menuconfig" main page and relaunch "make".

Nicolas

Philipp S

unread,
Jan 27, 2012, 11:23:19 AM1/27/12
to Bifferboard
Thank you :)

Now it works fine :) and compiling helo world works, too.

:)

nicolas le falher

unread,
Jan 27, 2012, 11:25:18 AM1/27/12
to biffe...@googlegroups.com
Nice :)
Reply all
Reply to author
Forward
0 new messages