LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Blogs > In The Middle Of Nowhere [edK's blog]
User Name
Password

Notices


In The Middle Of Nowhere

Life, universe and everything...
--
Blog title (C) Orbital
Rate this Entry

gentoo stage3-x86-uclibc-2008.0 hacking

Posted 01-08-2011 at 02:47 PM by Web31337

Long time no posting
Today I'm going to describe my so called experience with gentoo stage3 from 2008, linked against uClibc, a tiny C library for developing embedded environments.
I first met uClibc on my router's tomato-usb firmware. I was amazed when I've seen how small memory usage was, even for coreutils-apps.
Since that I was looking for decent inspiration to try out building my own uClibc-based environment. As I previously wrote (I think I did), I once was an assembler coder, I was having fun with win32-coding. That experience changed my entire life, since that moment I was looking for a hardcore optimization in every aspect of programming. I really dislike when bash takes 2-3 MB RSS while in uClibc build it can fit into 800-1300 KB. I dislike when stdlib uses too much space in resulting binary.
Just look at this:
Code:
x86, asmutils
root     19321  0.0  0.0    144     8 pts/0    S    09:10   0:00 ./sleep 10
x86, coreutils-8.5, uClibc 0.9.30-r1
root     19333  0.0  0.0    556   216 pts/0    S    09:10   0:00 sleep 10
x86, coreutils-8.5, glibc-2.11.2-r3
root       619  0.0  0.0   3228   244 pts/0    S    09:10   0:00 sleep 10
x86_64, coreutils-8.7, glibc-2.11.2-r3
root     14145  0.0  0.0   6512   556 pts/0    S    09:11   0:00 sleep 10
I've appended asmutils binary stats, so that you can see the way programs meant to look like.

If you are quite inspired now, let's get closer to topic.
First thing you need to get this exact stage3 to run is a kernel with CONFIG_UID16 set. Otherwise you won't be able to do much in it. Your options generally are using own livecd image with prepared kernel, or booting from second hdd/partition, after deploying stage3 to first one.
Then, as usual, you boot, and start with syncing portage.
The first step should be a general upgrade.
Initially emerge --info looks like the following:
Code:
Portage 2.1.4.4 (uclibc/x86, gcc-4.1.2, uclibc-0.9.28.3-r2, 2.6.36.2 i686)
=================================================================
System uname: 2.6.36.2 i686 Pentium II (Klamath)
Timestamp of tree: Fri, 07 Jan 2011 07:15:01 +0000
app-shells/bash:     3.2_p17-r1
dev-lang/python:     2.4.4-r6
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.65-r1
sys-devel/automake:  1.11.1
sys-devel/binutils:  2.18-r1
sys-devel/gcc:       4.1.2
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   2.2.6b
sys-devel/make:      3.81
virtual/os-headers:  2.6.23-r3
ACCEPT_KEYWORDS="x86"
CBUILD="i386-gentoo-linux-uclibc"
CFLAGS="-Os -mtune=i386 -pipe"
CHOST="i386-gentoo-linux-uclibc"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/env.d /etc/gconf /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-Os -mtune=i386 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="distlocks metadata-transfer nodoc noinfo noman sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.UTF-8"
LDFLAGS="-Wl,-O1"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
SYNC="rsync://xen/gentoo-portage"
USE="cli cracklib crypt cxx dri modules mudflap ncurses openmp pcre perl python readline session ssl tcpd uclibc x86 xorg zlib" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="uclibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="dummy fbdev v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LC_ALL, LINGUAS, MAKEOPTS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PORTDIR_OVERLAY
The portage version inside is 2.1.4.4, it uses EAPI 1, which will prevent most packages from merging, since they either use EAPI 2 or 3. Your first step is to emerge portage but you are unable to do so, because it requires =python-2.5.4-r4 which requires =pkgconfig-0.25-r2, which requires EAPI 2 for building so you stuck here. What I did is built pkg-config myself, then made portage think I've installed it (you can do this by copying /var/db/pkg/any-category/any-package to /var/db/pkg/required-category/required-package).
The next step is upgrading gcc, because python complains about gcc not having libffi flag: bundled gcc 4.1.2 doesn't have it. gcc upgrade is painful: you have to use custom EXTRA_ECONF=--disable-decimal-float if you are not upgrading uClibc, otherwise your build will fail with
Code:
error: fenv.h: No such file or directory
The link helped me to fix this is http://www.mail-archive.com/openembe.../msg02317.html

Next steps are relatively simple, if you are experienced gentoo user, you will likely hack up further on your own.
Few other problematic places are, when you upgraded to EAPI 2-version of portage, you need to go further to EAPI 3, current: 2.1.9.25, which will ask you to emerge python-2.6. Here you will likely face this funny thing:
Code:
root@embedded:~# emerge -pv portage

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  NS   ] dev-lang/python-2.6.6-r1 [2.4.4-r6, 2.5.4-r4] USE="ncurses readline ssl threads (wide-unicode) xml -berkdb -build -doc -examples -gdbm -ipv6 -sqlite -tk -wininst" 10,837 kB
[ebuild     U ] sys-apps/portage-2.1.9.25 [2.1.6.13] USE="(ipc%*) -build -doc -epydoc -python3% (-selinux)" LINGUAS="-pl" 0 kB
[blocks B     ] >=dev-lang/python-2.6.6:2.6 (">=dev-lang/python-2.6.6:2.6" is blocking sys-apps/portage-2.1.6.13)
[blocks B     ] <sys-apps/portage-2.1.9 ("<sys-apps/portage-2.1.9" is blocking dev-lang/python-2.6.6-r1)

Total: 2 packages (1 upgrade, 1 in new slot), Size of downloads: 10,837 kB
Conflict: 2 blocks (2 unsatisfied)

 * Error: The above package list contains packages which cannot be
 * installed at the same time on the same system.

  ('ebuild', '/', 'dev-lang/python-2.6.6-r1', 'merge') pulled in by
    dev-lang/python:2.6 required by ('ebuild', '/', 'sys-apps/portage-2.1.9.25', 'merge')

root@embedded:~# eix dev-lang/python
[U] dev-lang/python
     Available versions:  
	(2.4)	2.4.6
	(2.5)	2.5.4-r4
	(2.6)	2.6.5-r3 2.6.6-r1
	(2.7)	~2.7 ~2.7.1
	(3.1)	3.1.2-r4 ~3.1.3
	{berkdb bootstrap build cxx doc elibc_uclibc examples gdbm ipv6 ncurses readline sqlite ssl threads tk wide-unicode wininst xml}
     Installed versions:  2.4.4-r6(2.4)(15:51:57 04/25/08)(elibc_uclibc ncurses readline ssl -berkdb -bootstrap -build -doc -examples -gdbm -ipv6 -nocxx -nothreads -tk -ucs2)
			  2.5.4-r4(2.5)(17:28:22 01/07/11)(elibc_uclibc ncurses readline ssl threads wide-unicode xml -berkdb -build -doc -examples -gdbm -ipv6 -sqlite -tk -wininst)
     Homepage:            http://www.python.org/
     Description:         Python is an interpreted, interactive, object-oriented programming language.

root@embedded:~# emerge -pv =python-2.6.5-r3 portage

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  NS   ] dev-lang/python-2.6.5-r3 [2.4.4-r6, 2.5.4-r4] USE="ncurses readline ssl threads (wide-unicode) xml -berkdb -build -doc -examples -gdbm -ipv6 -sqlite -tk -wininst" 12,284 kB
[ebuild     U ] sys-apps/portage-2.1.9.25 [2.1.6.13] USE="(ipc%*) -build -doc -epydoc -python3% (-selinux)" LINGUAS="-pl" 0 kB

Total: 2 packages (1 upgrade, 1 in new slot), Size of downloads: 12,284 kB
As you can see it can be solved with merging older version of python, 2.6.5, you use eix to find out which are your options.

When you are done with upgrading to the latest version of portage, you can move it to python3 (using the latter flag), trash all of your 2.x versions to free space(embedded, uh?), and merge 2.7.x tree for your python2 parser, if you need it.

Then, when you will be upgrading, you should upgrade your uclibc, it's also recommended to re-emerge gcc.
Some packages are problematic, like coreutils-8.7 fails to build, while 8.5 works just fine, busybox-1.17.4 fails to build, while 1.15.3 works, perl won't build also. Generally all other packages should build fine, I believe you can work it out yourself. You won't be needing a CONFIG_UID16-enabled kernel after you upgrade uClibc, so you can use regular gentoo minimalcds.

Happy hacking and welcome to the world of tiny apps
Your next stop should likely be buildroot or lfs
Posted in opensource, etc, hardware
Views 3456 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:28 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration