Discussion:
[OpenWrt-Devel] Compiling outside of buildroot
David Farrell
2010-02-19 13:53:55 UTC
Permalink
After OpenWrt was built and installed I wanted to add my own program, ie compile "hello world" and run it. I created a make that points to ./kamikaze/staging_dir/toolchain-mips_gcc-4.3.3+cs_uClibc-0.9.30.1 and uses mips-openwrt-linux-uclibc-gcc and other tools. All build, compile and run are fine.
Now I want to build a loadable kernel module. With a desktop this is easy obj-m += module.o /lib/modules/<kernel-rev->/build etc. How do I do the same using the buildroot created toolchain and kernel? I don't see a ../build directory. I assume I point some kernel sources that provide the linux "make" macro expansion but I am not sure where to look. I don't want to add my module to the OpenWrt build, I just want to treat the OpenWrt system as a general purpose embedded linux box.

D.
Felix Fietkau
2010-02-19 15:14:42 UTC
Permalink
Post by David Farrell
After OpenWrt was built and installed I wanted to add my own program,
ie compile "hello world" and run it. I created a make that points to
./kamikaze/staging_dir/toolchain-mips_gcc-4.3.3+cs_uClibc-0.9.30.1
and uses mips-openwrt-linux-uclibc-gcc and other tools.
All build, compile and run are fine.
Now I want to build a loadable kernel module. With a desktop this is
easy obj-m += module.o /lib/modules/<kernel-rev->/build etc.
How do I do the same using the buildroot created toolchain and kernel?
I don't see a ../build directory. I assume I point some kernel sources
that provide the linux "make" macro expansion but I am not sure where to look.
I don't want to add my module to the OpenWrt build,
I just want to treat the OpenWrt system as a general purpose embedded linux box.
Two possibilities:

a) You read about how the Linux kernel is cross compiled, how to build
external kernel module trees and so on using variables like
CROSS_COMPILE, ARCH, M, ...
The kernel sources are in build_dir/linux-*/linux-*/.
You can put the toolchain dir into your PATH and call the make commands
there (pointing at your external tree), either manually or with your
wrapper makefile.

b) You realize that cross-compiling an external kernel module is much
easier with OpenWrt, and simply copy a package dir like
package/spi-ks8995 and adjust it for your own kernel module, then run
make oldconfig and then run make package/<yourpackage>/compile V=99 ;)

- Felix
Bas Mevissen
2010-02-19 15:48:44 UTC
Permalink
(..)
Post by Felix Fietkau
Post by David Farrell
I just want to treat the OpenWrt system as a general purpose embedded linux box.
a) You read about how the Linux kernel is cross compiled, how to build
external kernel module trees and so on using variables like
CROSS_COMPILE, ARCH, M, ...
The kernel sources are in build_dir/linux-*/linux-*/.
You can put the toolchain dir into your PATH and call the make commands
there (pointing at your external tree), either manually or with your
wrapper makefile.
How about the OpenWRT SDK? Is that still supported?
I never used it, but it would be useful if it would contain some
Makefiles and/or scripts to help building user space and kernel space
code outside the OpenWRT tree.

The idea is that you install a pre-compiled SDK somewhere, source a
script with settings and you can easily build your own stuff without
hassle about paths and stuff. This is how most board support packages
from hardware manufacturers work. It should be as easy as native
compilation.

b) You realize that cross-compiling an external kernel module is much
Post by Felix Fietkau
easier with OpenWrt, and simply copy a package dir like
package/spi-ks8995 and adjust it for your own kernel module, then run
make oldconfig and then run make package/<yourpackage>/compile V=99 ;)
Yes, it is easy to create an external package and include it in the
OpenWRT build. Is there a way to build an OpenWRT image with calling
"make" outside the OpenWRT tree and have the image also outside the
OpenWRT tree?

The idea here is to keep your code and OpenWRT separated during
development.

Bas.
Felix Fietkau
2010-02-19 19:08:27 UTC
Permalink
Post by Bas Mevissen
How about the OpenWRT SDK? Is that still supported?
I never used it, but it would be useful if it would contain some
Makefiles and/or scripts to help building user space and kernel space
code outside the OpenWRT tree.
The SDK does not contain the kernel sources, thus it cannot build kernel
modules. It is still supported for user space stuff.
Post by Bas Mevissen
The idea is that you install a pre-compiled SDK somewhere, source a
script with settings and you can easily build your own stuff without
hassle about paths and stuff. This is how most board support packages
from hardware manufacturers work. It should be as easy as native
compilation.
I disagree with the way manufacturers typically set up board support
packages. Often you have to install something as root, which is annoying
for people that only have user accounts on some machines. Often you can
only have one globally installed instance of the SDK, which makes it
annoying to support multiple different versions, or even just multiple
minor variations of the toolchain.

I think it's much better to have something that's self contained and
which you can install anywhere you want and don't have to set up
environment variables for.
Post by Bas Mevissen
b) You realize that cross-compiling an external kernel module is much
Post by Felix Fietkau
easier with OpenWrt, and simply copy a package dir like
package/spi-ks8995 and adjust it for your own kernel module, then run
make oldconfig and then run make package/<yourpackage>/compile V=99 ;)
Yes, it is easy to create an external package and include it in the
OpenWRT build. Is there a way to build an OpenWRT image with calling
"make" outside the OpenWRT tree and have the image also outside the
OpenWRT tree?
Why do you want to call it outside of the tree? You can keep your
packages as a separate feed, which makes it easy to keep track of your
own work without having to fully integrate it into the OpenWrt tree.

- Felix
Bas Mevissen
2010-02-21 14:49:01 UTC
Permalink
Post by Felix Fietkau
I disagree with the way manufacturers typically set up board support
packages. Often you have to install something as root, which is annoying
for people that only have user accounts on some machines. Often you can
only have one globally installed instance of the SDK, which makes it
annoying to support multiple different versions, or even just multiple
minor variations of the toolchain.
That's true, but for most of people it is a convenient way to just have
to install an SDK and start developing.

One issue with pre-compiled SDK's is gcc hardcoded absolute paths to
libraries that make relocation difficult. There are scripts that change
the absolute paths to relative one. Then it is possible to install a
precompiled SDK in the user accessible location you want.

With OpenWRT, it is possible to have multiple different version
installed at the same time. You can simply choose a different location
for every variant where you build OpenWRT, e.g. build one in
/opt/OpenWRT/<platform>/<variant1> and another one in
/opt/OpenWRT/<platform>/<variant2>

By sourcing a (to be written) script say
/opt/OpenWRT/<platform>/<the_variant>/settings.rc you switch between
different variants.
Post by Felix Fietkau
Why do you want to call it outside of the tree? You can keep your
packages as a separate feed, which makes it easy to keep track of your
own work without having to fully integrate it into the OpenWrt tree.
Personally, I like a complete separation between open source and
propriety code. So when developing propriety code which uses OpenWRT as
a platform, I prefer to use a fixed tree of OpenWRT stuff (packaged and
installed somewhere) and have an entirely separate tree of propriety
code in which I can simply call "make". Then the resulting binaries,
kmods and images should land somewhere in my propriety tree.

Please note that I'm not saying that the system with the feeds is not
working properly! I just want to offer an OpenWRT based SDK for a
certain board (including kernel headers and .config actually) as an easy
to install package and an archive with only the propriety stuff.

One then only needs to install the SDK, unpack the archive with the
propriety code and run make.

Bas.
Luigi Mantellini
2010-02-21 15:18:16 UTC
Permalink
Hi All,

in order to avoid the absoluted-path issue, I suggest to use the
script wrapper.sh (used to create the toolchain target).

https://dev.openwrt.org/browser/trunk/target/toolchain/files/wrapper.sh

Can we integrate this script also into the SDK target?

thanks and best regards,

luigi
Post by Bas Mevissen
Post by Felix Fietkau
I disagree with the way manufacturers typically set up board support
packages. Often you have to install something as root, which is annoying
for people that only have user accounts on some machines. Often you can
only have one globally installed instance of the SDK, which makes it
annoying to support multiple different versions, or even just multiple
minor variations of the toolchain.
That's true, but for most of people it is a convenient way to just have
to install an SDK and start developing.
One issue with pre-compiled SDK's is gcc hardcoded absolute paths to
libraries that make relocation difficult. There are scripts that change
the absolute paths to relative one. Then it is possible to install a
precompiled SDK in the user accessible location you want.
With OpenWRT, it is possible to have multiple different version
installed at the same time. You can simply choose a different location
for every variant where you build OpenWRT, e.g. build one in
/opt/OpenWRT/<platform>/<variant1> and another one in
/opt/OpenWRT/<platform>/<variant2>
By sourcing a (to be written) script say
/opt/OpenWRT/<platform>/<the_variant>/settings.rc you switch between
different variants.
Post by Felix Fietkau
Why do you want to call it outside of the tree? You can keep your
packages as a separate feed, which makes it easy to keep track of your
own work without having to fully integrate it into the OpenWrt tree.
Personally, I like a complete separation between open source and
propriety code. So when developing propriety code which uses OpenWRT as
a platform, I prefer to use a fixed tree of OpenWRT stuff (packaged and
installed somewhere) and have an entirely separate tree of propriety
code in which I can simply call "make". Then the resulting binaries,
kmods and images should land somewhere in my propriety tree.
Please note that I'm not saying that the system with the feeds is not
working properly! I just want to offer an OpenWRT based SDK for a
certain board (including kernel headers and .config actually) as an easy
to install package and an archive with only the propriety stuff.
One then only needs to install the SDK, unpack the archive with the
propriety code and run make.
Bas.
_______________________________________________
openwrt-devel mailing list
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
--
Luigi 'Comio' Mantellini
R&D - Software
Industrie Dial Face S.p.A.
Via Canzo, 4
20068 Peschiera Borromeo (MI), Italy

Tel.: +39 02 5167 2813
Fax: +39 02 5167 2459
web: www.idf-hit.com
mail: ***@idf-hit.com
CHEN XUEQIN
2010-04-25 17:17:01 UTC
Permalink
Post by Luigi Mantellini
Hi All,
in order to avoid the absoluted-path issue, I suggest to use the
script wrapper.sh (used to create the toolchain target).
https://dev.openwrt.org/browser/trunk/target/toolchain/files/wrapper.sh
Can we integrate this script also into the SDK target?
thanks and best regards,
I have SDK with absoluted-path issue in openwrt 8.09. How can I
use the script wrapper.sh to toolchain absoluted-path dependance?
For example, I have built OpenWrt-SDK-ppc44x-for-Linux-i686.tar.bz2.
Should I write some shell code to invoke wrapper.sh or modify openwrt
Makefile to apply it? Any detail directions is appreciated.

Regards,
Chen Xueqin

David Farrell
2010-02-23 16:19:26 UTC
Permalink
Post by Felix Fietkau
Post by Felix Fietkau
b) You realize that cross-compiling an external kernel module is much
Post by Felix Fietkau
easier with OpenWrt, and simply copy a package dir like
package/spi-ks8995 and adjust it for your own kernel module, then run
make oldconfig and then run make package/<yourpackage>/compile V=99 ;)
Yes, it is easy to create an external package and include it in the
OpenWRT build. Is there a way to build an OpenWRT image with calling
"make" outside the OpenWRT tree and have the image also outside the
OpenWRT tree?
.Why do you want to call it outside of the tree? You can keep your
Post by Felix Fietkau
packages as a separate feed, which makes it easy to keep track of your
own work without having to fully integrate it into the OpenWrt tree.
- Felix
I created a package in the tree called template. The kernel module builds and
loads fine. In the course of putting it in a package I have to choose
CONFIG_MOD_TEMPLATE and a couple other items in a manner which doesn't
conflict with existing options. I don't really need to be part of menuconf, I don't
need these options. I also tried the V=99 option, to see what is happening.
The output from this is a little too verbose for me. My plan now is to try to
find out how obj-m is processed on my ubuntu install to see how I can
apply this to the openwrt toolchain.

David.
Jo-Philipp Wich
2010-02-21 18:38:14 UTC
Permalink
Hi.
Post by Bas Mevissen
How about the OpenWRT SDK? Is that still supported?
Yes it is still supported and works well.
It also contains a "relocatable" toolchain, so it doesn't matter where
you unpack it. But it is only suitable for userspace software, iirc it
does not ship with and is not capable of compiling the kernel sources.

~ JoW
Florian Fainelli
2010-02-21 18:45:22 UTC
Permalink
Post by Jo-Philipp Wich
Hi.
Post by Bas Mevissen
How about the OpenWRT SDK? Is that still supported?
Yes it is still supported and works well.
It also contains a "relocatable" toolchain, so it doesn't matter where
you unpack it. But it is only suitable for userspace software, iirc it
does not ship with and is not capable of compiling the kernel sources.
You can however, use the compiled and relocatable toolchain in the SDK to
compile other kernel sources (vanilla, git ...)
--
Best regards, Florian Fainelli
Email: ***@openwrt.org
Web: http://openwrt.org
IRC: [florian] on irc.freenode.net
-------------------------------
Bas Mevissen
2010-02-21 19:53:59 UTC
Permalink
Post by Florian Fainelli
Post by Jo-Philipp Wich
Yes it is still supported and works well.
It also contains a "relocatable" toolchain, so it doesn't matter where
you unpack it. But it is only suitable for userspace software, iirc it
does not ship with and is not capable of compiling the kernel sources.
You can however, use the compiled and relocatable toolchain in the SDK to
compile other kernel sources (vanilla, git ...)
So if the kernel headers and config are added to the SDK, one could
compile out of tree kmods too?

Bas.
David Farrell
2010-02-19 19:41:32 UTC
Permalink
----- Original Message ----
From: Felix Fietkau <***@openwrt.org>
To: OpenWrt Development List <openwrt-***@lists.openwrt.org>
Sent: Fri, February 19, 2010 10:14:42 AM
Subject: Re: [OpenWrt-Devel] Compiling outside of buildroot
Post by David Farrell
After OpenWrt was built and installed I wanted to add my own program,
ie compile "hello world" and run it. I created a make that points to
./kamikaze/staging_dir/toolchain-mips_gcc-4.3.3+cs_uClibc-0.9.30.1
and uses mips-openwrt-linux-uclibc-gcc and other tools.
All build, compile and run are fine.
Now I want to build a loadable kernel module. With a desktop this is
easy obj-m += module.o /lib/modules/<kernel-rev->/build etc.
How do I do the same using the buildroot created toolchain and kernel?
I don't see a ../build directory. I assume I point some kernel sources
that provide the linux "make" macro expansion but I am not sure where to look.
I don't want to add my module to the OpenWrt build,
I just want to treat the OpenWrt system as a general purpose embedded linux box.
Two possibilities:

a) You read about how the Linux kernel is cross compiled, how to build
external kernel module trees and so on using variables like
CROSS_COMPILE, ARCH, M, ...
The kernel sources are in build_dir/linux-*/linux-*/.
You can put the toolchain dir into your PATH and call the make commands
there (pointing at your external tree), either manually or with your
wrapper makefile.

b) You realize that cross-compiling an external kernel module is much
easier with OpenWrt, and simply copy a package dir like
package/spi-ks8995 and adjust it for your own kernel module, then run
make oldconfig and then run make package/<yourpackage>/compile V=99 ;)

- Felix

I have several projects than were originally built for TS-5500 boards from T-Systems.
I modified my makefiles slightly to build them using tools created by the OpenWrt
build. All is fine for the bulk of the projects. There are a couple places that I use
loadable modules, in the past I only used kernel headers to build them. My projects
have nothing to do with wireless or routers, I wanted to stay out of the OpenWrt tree.
I also wanted to locate the projects in an area where I can build for my old design,
linux desktop or or the new mips based design. I guess I am trying to leverage the
fine work the OpenWrt group has done and make use of the latest tools and kernel
it provides. I think I will probably try your b) case with V=99 and see what gets done.
Thanks,
David.
Loading...