2013-06-22

Slitaz -- Compiling with qemu-arm-static chroot

Compiling with qemu-arm-static chroot

Target: arm-slitaz-linux-gnueabi

--with-arch=armv6 --with-fpu=vfp --with-float=hard --with-pkgversion=SliTaz
--build=arm-slitaz-linux-gnueabi --host=arm-slitaz-linux-gnueabi

1.
root@slitaz:~# uname -a
Linux slitaz 2.6.37-slitaz #1 SMP Fri May 10 17:42:01 CST 2013 i686 GNU/Linux

2.
root@slitaz:~# tazdev -c /opt/rootfs-armhf

Mounting virtual filesystems...                                    [ Done ]
Chrooting to: /opt/rootfs-armhf

3.
root@slitaz:/# gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-slitaz-linux-gnueabi/4.6.3/lto-wrapper
Target: arm-slitaz-linux-gnueabi
Configured with: /home/slitaz/wok/gcc/source/gcc-4.6.3/configure --prefix=/usr --libexecdir=/usr/lib --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long --enable-__cxa_atexit --with-system-zlib --enable-plugin --disable-multilib --disable-libssp --disable-checking --disable-werror --disable-bootstrap --enable-clocale=gnu --enable-lto --enable-threads=posix --with-arch=armv6 --with-fpu=vfp --with-float=hard --with-pkgversion=SliTaz --build=arm-slitaz-linux-gnueabi --host=arm-slitaz-linux-gnueabi
Thread model: posix
gcc version 4.6.3 (SliTaz)

4.
root@slitaz:/# echo 'int main() { return 0; }' > test.c

root@slitaz:/# gcc -o test.o test.c

root@slitaz:/# ls -l test*
-rw-r--r--    1 root     root            25 Jun  9 13:59 test.c
-rwxr-xr-x    1 root     root          6790 Jun  9 13:59 test.o

5.
root@slitaz:/# file test.o
test.o: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped

root@slitaz:/# readelf -A test.o
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "6"
  Tag_CPU_arch: v6
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_FP_arch: VFPv2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_HardFP_use: SP and DP
  Tag_ABI_VFP_args: VFP registers
  Tag_DIV_use: Not allowed
root@slitaz:/#

Slitaz -- glibc / eglibc

GNU C Library (EGLIBC) stable release version 2.13,

GNU C Library stable release version 2.13,

root@slitaz:~# file /opt/rootfs-armhf/lib/libc-2.13.so
/opt/rootfs-armhf/lib/libc-2.13.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped

1. slitaz-armhf: eglibc-2.13
root@slitaz:/# file /lib/libc-2.13.so
/lib/libc-2.13.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped
root@slitaz:/#

root@slitaz:/# /lib/libc-2.13.so
GNU C Library (EGLIBC) stable release version 2.13, by Roland McGrath et al.
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.6.3.
Compiled on a Linux 3.2.14 system on 2012-06-30.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    Support for some architectures added on, not maintained in glibc core.
    BIND-8.2.3-T5B
libc ABIs: UNIQUE
For bug reporting instructions, please see:
<http://www.eglibc.org/issues/>.

2.
root@slitaz:/# exit

Unmounting virtual filesystems...                                  [ Done ]

3. slitaz-4.0: glibc-2.13
root@slitaz:~# uname -a
Linux slitaz 2.6.37-slitaz #1 SMP Fri May 10 17:42:01 CST 2013 i686 GNU/Linux

root@slitaz:~# file /lib/libc-2.13.so
/lib/libc-2.13.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.30, stripped

root@slitaz:~# /lib/libc-2.13.so
GNU C Library stable release version 2.13, by Roland McGrath et al.
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.5.2.
Compiled on a Linux 2.6.37 system on 2012-03-13.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

root@slitaz:~#

2013-06-20

Slitaz -- qemu-arm-static chroot-2

Chrooting to: /opt/rootfs-armhf/

root@slitaz:~# ls -l /opt/rootfs-armhf

1. download qemu-arm-static-1.1.2.tazpkg
http://tiny.cc/rh7wyw
# tazpkg -i qemu-arm-static-1.1.2.tazpkg

2. copy qemu-arm-static to rootfs-armhf
# cp /usr/bin/qemu-arm-static /opt/rootfs-armhf/usr/bin


3. Mount the binfmt_misc handler
# modprobe binfmt_misc
# mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc


4. register our format with the kernel via the procfs
root@slitaz:~# echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register


5. check register
root@slitaz:~# cat /proc/sys/fs/binfmt_misc/arm
enabled
interpreter /usr/bin/qemu-arm-static
flags:
offset 0
magic 7f454c4601010100000000000000000002002800
mask ffffffffffffff00ffffffffffff00fffeffffff


6. chroot rootfs-armhf
root@slitaz:~# tazdev -c /opt/rootfs-armhf/

Mounting virtual filesystems...                                    [ Done ]
Chrooting to: /opt/rootfs-armhf/

7.
root@slitaz:/# uname -m
armv6l


8.
root@slitaz:/# echo -e 'nameserver 8.8.8.8\n' > /etc/resolv.conf
root@slitaz:/# nslookup www.slitaz.org
Server:    8.8.8.8
Address 1: 8.8.8.8 google-public-dns-a.google.com

Name:      www.slitaz.org
Address 1: 94.23.61.29 pangolin.pimentvert.com
Address 2: 91.121.171.224 ks362096.kimsufi.com
root@slitaz:/#

Slitaz -- rootfs-armhf

rootfs-armhf

1.
# wget http://mirror.slitaz.org/packages/cooking/util-linux-mount-2.21.1.tazpkg
# tazpkg -i util-linux-mount-2.21.1.tazpkg

download slitaz-armhf-mini-2012-12-14.zip and extract it
# wget http://arm.balinor.net/slitaz/armhf/slitaz-armhf-mini-2012-12-14.zip
# unzip slitaz-armhf-mini-2012-12-14.zip

2.
root@slitaz:~# file slitaz-armhf-mini-2012-12-14.img
slitaz-armhf-mini-2012-12-14.img: x86 boot sector; partition 1: ID=0x6, starthead 1, startsector 63, 48132 sectors; partition 2: ID=0x83, starthead 0, startsector 48195, 915705 sectors, code offset 0xb8

root@slitaz:~# fdisk -lu slitaz-armhf-mini-2012-12-14.img

Disk slitaz-armhf-mini-2012-12-14.img: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 cylinders, total 1048576 sectors
Units = sectors of 1 * 512 = 512 bytes

                           Device Boot      Start         End      Blocks  Id System
slitaz-armhf-mini-2012-12-14.img1              63       48194       24066   6 FAT16
slitaz-armhf-mini-2012-12-14.img2           48195      963899      457852+ 83 Linux
root@slitaz:~#

3.
root@slitaz:~# mount -o,offset=$((48195*512)) slitaz-armhf-mini-2012-12-14.img /mnt/raspi

4.
root@slitaz:~# cp -a /mnt/raspi /opt/rootfs-armhf

5.
root@slitaz:~# ls -l /opt/rootfs-armhf
total 68
drwxr-xr-x    2 root     root          4096 Dec  3  2012 bin
drwxr-xr-x    2 root     root          4096 Dec 14  2012 boot
drwxr-xr-x    8 root     root          4096 Dec  3  2012 dev
drwxr-xr-x    7 root     root          4096 Dec 14  2012 etc
drwxr-xr-x    2 root     root          4096 Dec  3  2012 home
lrwxrwxrwx    1 root     root            12 Jun 19 20:03 init -> /bin/busybox
drwxr-xr-x    2 root     root          4096 Dec  3  2012 lib
drwx------    2 root     root          4096 Dec  3  2012 lost+found
drwxr-xr-x    5 root     root          4096 Dec  3  2012 media
drwxr-xr-x    2 root     root          4096 Dec  3  2012 mnt
drwxr-xr-x    2 root     root          4096 Dec  3  2012 proc
drwxr-x---    2 root     root          4096 Dec  3  2012 root
drwxr-xr-x    2 root     root          4096 Dec  3  2012 run
drwxr-xr-x    2 root     root          4096 Dec  3  2012 sbin
drwxr-xr-x    2 root     root          4096 Dec  3  2012 sys
drwxrwxrwt    2 root     root          4096 Dec  3  2012 tmp
drwxr-xr-x    8 root     root          4096 Dec 14  2012 usr
drwxr-xr-x   11 root     root          4096 Dec  3  2012 var

root@slitaz:~# file /opt/rootfs-armhf/lib/libc-2.13.so
/opt/rootfs-armhf/lib/libc-2.13.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped

root@slitaz:~# du -sh /opt/rootfs-armhf
9.2M    /opt/rootfs-armhf
root@slitaz:~#

2013-06-19

Slitaz -- qemu user mode and binfmt_misc

qemu user mode and binfmt_misc

User mode emulation. In this mode, QEMU can launch processes compiled for one CPU on another CPU.

Kernel Support for miscellaneous (your favourite) Binary Formats



1.1 Features
http://qemu.weilnetz.de/qemu-doc.html#Introduction

QEMU is a FAST! processor emulator using dynamic translation to achieve good emulation speed.

QEMU has two operating modes:

    Full system emulation. In this mode, QEMU emulates a full system (for example a PC), including one or several processors and various peripherals. It can be used to launch different Operating Systems without rebooting the PC or to debug system code.
   
   User mode emulation. In this mode, QEMU can launch processes compiled for one CPU on another CPU. It can be used to launch the Wine Windows API emulator (http://www.winehq.org) or to ease cross-compilation and cross-debugging.


Kernel Support for miscellaneous (your favourite) Binary Formats v1.1  ==========================================
https://www.kernel.org/doc/Documentation/binfmt_misc.txt

This Kernel feature allows you to invoke almost (for restrictions see below)
every program by simply typing its name in the shell.
This includes for example compiled Java(TM), Python or Emacs programs.

To achieve this you must tell binfmt_misc which interpreter has to be invoked
with which binary. Binfmt_misc recognises the binary-type by matching some bytes
at the beginning of the file with a magic byte sequence (masking out specified
bits) you have supplied. Binfmt_misc can also recognise a filename extension
aka '.com' or '.exe'.

First you must mount binfmt_misc:
    mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc


Ref:
https://wiki.edubuntu.org/UbuntuDevelopment/Ports

Slitaz -- qemu-arm-static chroot


qemu-arm-static chroot


1.
root@slitaz:~# uname -a
Linux slitaz 2.6.37-slitaz #1 SMP Fri May 10 17:42:01 CST 2013 i686 GNU/Linux

2.
root@slitaz:~# tazdev -c /opt/rootfs-armhf/

Mounting virtual filesystems...                                    [ Done ]
Chrooting to: /opt/rootfs-armhf/

3.
root@slitaz:/# uname -m
armv6l

4.
root@slitaz:/# readelf -A /lib/libc-2.13.so
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "6"
  Tag_CPU_arch: v6
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_FP_arch: VFPv2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_HardFP_use: SP and DP
  Tag_ABI_VFP_args: VFP registers
  Tag_DIV_use: Not allowed

5.
root@slitaz:/# head -5 /var/lib/tazpkg/installed.md5
bbb30be1a2c704154f58e2df501e35fd  busybox-1.20.2-armhf.tazpkg
a82e5ffd86838571addf3eee3f418c7b  dropbear-2012.55-armhf.tazpkg
7015c541e061e277c07f023073faad92  gcc-lib-base-4.6.3-armhf.tazpkg
d165510417ebc3d1e6bf37c96b9db8d8  gettext-base-0.18.1.1-armhf.tazpkg
2f4a5d282889c6fbd228a974822bd0d9  glibc-base-2.13-armhf.tazpkg

6.
root@slitaz:/# tazpkg list | tail -2
18 packages installed

7.
root@slitaz:/# du -sh /
13.4M    /
root@slitaz:/#

Slitaz -- cross / tazdev

Create a chroot (use last tazdev)

cross.txt

    26 Create a chroot (use last tazdev)
    27 ---------------------------------
    28 # tazdev gen-chroot --arch=arm
    29 # tazdev chroot
    30
    31 Clone cookutils to get last cook and cross


# wget http://mirror.slitaz.org/packages/cooking/tazdev-1.9.tazpkg
# tazpkg -i tazdev-1.9.tazpkg

2013-06-03

Slitaz -- raspi / file

  -k, --keep-going           don't stop at the first match

tux@slitaz:/tmp$ file 2013-05-25-wheezy-raspbian.img
2013-05-25-wheezy-raspbian.img: x86 boot sector


1.
tux@slitaz:/tmp$ file -k 2013-05-25-wheezy-raspbian.img
2013-05-25-wheezy-raspbian.img: x86 boot sector; partition 1: ID=0xc, starthead 130, startsector 8192, 114688 sectors; partition 2: ID=0x83, starthead 165, startsector 122880, 3665920 sectors


2.
tux@slitaz:/tmp$ fdisk -lu 2013-05-25-wheezy-raspbian.img

Disk 2013-05-25-wheezy-raspbian.img: 1939 MB, 1939865600 bytes
255 heads, 63 sectors/track, 235 cylinders, total 3788800 sectors
Units = sectors of 1 * 512 = 512 bytes

                         Device Boot      Start         End      Blocks  Id System
2013-05-25-wheezy-raspbian.img1            8192      122879       57344   c Win95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary
2013-05-25-wheezy-raspbian.img2          122880     3788799     1832960  83 Linux
Partition 2 does not end on cylinder boundary

3.
tux@slitaz:/tmp$ sudo mount -o,offset=$((512*122880)) 2013-05-25-wheezy-raspbian.img   /mnt/raspi
udev changed: /dev/loop0
mount changed: /dev/loop0
tux@slitaz:/tmp$ udev changed: /dev/loop0

tux@slitaz:/tmp$ ls -l /mnt/raspi
total 92
drwxr-xr-x    2 root     root          4096 May 25 17:10 bin
drwxr-xr-x    2 root     root          4096 May 25 16:38 boot
drwxr-xr-x    3 root     root          4096 May 25 17:11 dev
drwxr-xr-x   96 root     root          4096 May 25 17:58 etc
drwxr-xr-x    3 root     root          4096 May 25 16:35 home
drwxr-xr-x   12 root     root          4096 May 25 17:00 lib
drwx------    2 root     root         16384 May 25 16:24 lost+found
drwxr-xr-x    2 root     root          4096 May 25 16:26 media
drwxr-xr-x    2 root     root          4096 Dec 26 05:12 mnt
drwxr-xr-x    3 root     root          4096 May 25 16:37 opt
drwxr-xr-x    2 root     root          4096 Dec 26 05:12 proc
drwx------    2 root     root          4096 May 25 16:26 root
drwxr-xr-x    7 root     root          4096 May 25 17:42 run
drwxr-xr-x    2 root     root          4096 May 25 17:10 sbin
drwxr-xr-x    2 root     root          4096 Jun 20  2012 selinux
drwxr-xr-x    2 root     root          4096 May 25 16:26 srv
drwxr-xr-x    2 root     root          4096 Feb 26 05:19 sys
drwxrwxrwt    2 root     root          4096 Dec 26 05:12 tmp
drwxr-xr-x   10 root     root          4096 May 25 16:26 usr
drwxr-xr-x   11 root     root          4096 May 25 16:26 var


4.
tux@slitaz:/tmp$ sudo mount -o,offset=$((512*8192)) 2013-05-25-wheezy-raspbian.img  /mnt/boot
udev changed: /dev/loop1
tux@slitaz:/tmp$ mount changed: /dev/loop1
udev changed: /dev/loop1

tux@slitaz:/tmp$ ls -l /mnt/boot
total 18888
-rwxr-xr-x    1 root     root         17808 May 25 16:58 bootcode.bin
-rwxr-xr-x    1 root     root           142 May 25 17:38 cmdline.txt
-rwxr-xr-x    1 root     root          1180 May 25 17:38 config.txt
-rwxr-xr-x    1 root     root          2012 May 25 16:58 fixup_cd.dat
-rwxr-xr-x    1 root     root          5880 May 25 16:58 fixup.dat
-rwxr-xr-x    1 root     root          8830 May 25 16:58 fixup_x.dat
-rwxr-xr-x    1 root     root           137 May 25 18:58 issue.txt
-rwxr-xr-x    1 root     root       9610248 May 25 16:58 kernel_emergency.img
-rwxr-xr-x    1 root     root       2803168 May 25 16:58 kernel.img
-rwxr-xr-x    1 root     root        467960 May 25 16:58 start_cd.elf
-rwxr-xr-x    1 root     root       2688564 May 25 16:58 start.elf
-rwxr-xr-x    1 root     root       3655652 May 25 16:58 start_x.elf
tux@slitaz:/tmp$


5.
tux@slitaz:/tmp$ cat /mnt/boot/issue.txt
Raspberry Pi reference 2013-05-25 (armhf)
Generated using spindle, http://asbradbury.org/projects/spindle/, 9c87329, stage4-lxde-edu.qed