Frankenchroot/Manual Binary Format Setup

From Funtoo
Jump to navigation Jump to search
   Warning

This page is for advanced users and reference only. It is recommended that you use the Binary Format Setup steps as this automates this process for you and makes things tremendously easier.

Building and Installing the Wrapper Binary

   qemu-arm-wrapper.c (C source code) - qemu arm wrapper
/*
     * Call QEMU binary with additional "-cpu cortex-a7" argument.
     *
     * Copyright (c) 2018 sakaki <sakaki@deciban.com>
     * License: GPL v3.0+
     *
     * Based on code from the Gentoo Embedded Handbook
     * ("General/Compiling_with_qemu_user_chroot")
     */

    #include <string.h>
    #include <unistd.h>

    int main(int argc, char **argv, char **envp) {
        char *newargv[argc + 3];

        newargv[0] = argv[0];
        newargv[1] = "-cpu";
        newargv[2] = "cortex-a7";

        memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc -1));
        newargv[argc + 2] = NULL;
        return execve("/usr/local/bin/qemu-arm", newargv, envp);
    }
root # gcc -static -O3 -s -o qemu-arm-wrapper qemu-arm-wrapper.c
root # cp -av /usr/bin/qemu-arm /mnt/piroot/usr/local/bin/qemu-arm
root # cp -av qemu-arm-wrapper /mnt/piroot/usr/local/bin/qemu-arm-wrapper

Setting up binfmt_misc and Starting the Service

root # echo ":arm:M::\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-arm-wrapper:" > /proc/sys/fs/binfmt_misc/register

Setting up binfmt_misc and Starting the Service ARM64

root # echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64:' > /proc/sys/fs/binfmt_misc/register

Setting up binfmt_misc and Starting the Service RISCV64

root # echo ':riscv64:M::\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-riscv64:' > /proc/sys/fs/binfmt_misc/register