2013/12/03

Build Arch Linux sh4 Packages by qemu-static-sh4

Here we use PC to cross build Arch Linux package for sh4 CPU.
The tips are:
  1. Install qemu-sh4-static (yaourt -S qemu-static)
  2. setup binfmt_misc kernel module
  3. Install chroot environment (Arch Linux sh4 rootfs)

STEP 1.  Install qemu-sh4-static simulate sh4 program

yaourt -S qemu-static ( build glib2-static, glibc-static and pcre-static at first)
qemu-static 1.6.1-2
# test
wget http://linux.fjfi.cvut.cz/\~zub/blog/foreign-chroot/hello_world/hello_world-sh4-static
qemu-sh4-static ./hello_world-sh4-static

STEP 2. Setup binfmt_misc Kernel Module

zgrep BINFMT_MISC /proc/config.gz   # check if kernel support it
sudo modprobe binfmt_misc  # load module
wget http://linux.fjfi.cvut.cz/\~zub/blog/foreign-chroot/binfmt-misc-sh.sh
chmod +x binfmt-misc-sh.sh hello_world-sh4-static
sed -ie 's:usr/local:usr:' binfmt-misc-sh.sh  # patch the path to fit Arch's convention
sudo ./binfmt-misc-sh.sh

# check status
ls /proc/sys/fs/binfmt_misc  # it should display 'register sh4 status'
cat /proc/sys/fs/binfmt_misc/status
cat /proc/sys/fs/binfmt_misc/sh4
./hello_world-sh4-static  # it should display 'Hello world!'

STEP 3. Install Arch Linux sh4 Rootfs

wget http://sh4twbox.googlecode.com/files/target.arch.20130416.tgz
sudo tar xpf target.arch.20130416.tgz
sudo mv mnt_system arch

sudo cp /usr/bin/qemu-sh4-static arch/usr/bin  # should be same path as host linux
yaourt -S arch-install-scripts 
sudo arch-chroot arch

Problems:

I can only run one command.
#To use binfmt_misc you have to mount it first. You can mount it with
#"mount -t binfmt_misc none /proc/sys/fs/binfmt_misc" command, or you can add
#a line "none  /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0" to your
#/etc/fstab so it auto mounts on boot.

#There are some restrictions:
# - the whole register string may not exceed 255 characters
# - the magic must reside in the first 128 bytes of the file, i.e.
#   offset+size(magic) has to be less than 128
# - the interpreter string may not exceed 127 characters

# name:type:offset:magic:mask:interpreter:flags

沒有留言: