{"id":55,"date":"2020-01-26T03:47:41","date_gmt":"2020-01-26T03:47:41","guid":{"rendered":"http:\/\/junsun.net\/wordpress\/?p=55"},"modified":"2020-03-17T04:01:49","modified_gmt":"2020-03-17T04:01:49","slug":"how-to-cross-build-debian-mips-kernel","status":"publish","type":"post","link":"http:\/\/junsun.net\/wordpress\/2020\/01\/how-to-cross-build-debian-mips-kernel\/","title":{"rendered":"How to Cross-Build Debian\/MIPS Kernel"},"content":{"rendered":"<h2>Background<\/h2>\n<p>I was trying to install Debian\/MIPS on QEMU and found out that <a href=\"https:\/\/lists.debian.org\/debian-mips\/2020\/01\/msg00027.html\">I need to build\/update the kernel<\/a>. \u00a0The <a href=\"https:\/\/wiki.debian.org\/BuildADebianKernelPackage\">existing instructions<\/a> mostly talk about native build, which is painfully slow on QEMU. \u00a0I tried once and it took almost 10 hours! \u00a0There are some references to cross-build debian kernel and none applies straightforwardly. \u00a0 \u00a0I decided to write a blog on how I did it.<\/p>\n<h2>Prepare the host<\/h2>\n<ul>\n<li>My host is Ubuntu 18.04<\/li>\n<li>I&#8217;m building 64bit MIPS little endian kernel for malta board<\/li>\n<li>Need install a build related packages :\n<ul>\n<li><code>apt install -y build-essential linux-source bc kmod cpio flex cpio libncurses5-dev bison libssl-dev<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Need to install crosscompile tools. \u00a0Fortunately we only need gcc and binutils for compiling kernel\n<ul>\n<li><code>apt install -y binutils-mips64-linux-gnuabi64 gcc-mips64-linux-gnuabi64<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Set up the source<\/h2>\n<ul>\n<li>Download and unpack kernel source and config from debian site\n<ul>\n<li><code>cd download<\/code><\/li>\n<li><code>wget http:\/\/security.debian.org\/debian-security\/pool\/updates\/main\/l\/linux\/linux-source-4.19_4.19.67-2+deb10u2_all.deb<\/code><\/li>\n<li><code>wget http:\/\/security.debian.org\/debian-security\/pool\/updates\/main\/l\/linux\/linux-config-4.19_4.19.67-2+deb10u2_mips64el.deb<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Extract the kernel source from .deb file\n<ul>\n<li><code>dpkg -x download\/linux-source-4.19_4.19.67-2+deb10u2_all.deb .<\/code><\/li>\n<li><code>tar xf usr\/src\/linux-source-4.19.tar.xz<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Copy and modify the kernel config as you see fit\n<ul>\n<li><code>dpkg -x download\/linux-config-4.19_4.19.67-2+deb10u2_mips64el.deb .<\/code><\/li>\n<li><code>unxz usr\/src\/linux-config-4.19\/config.mips64el_none_5kc-malta.xz<\/code><\/li>\n<li><code>patch -p0 -b &lt; kconfig.patch<\/code><\/li>\n<li><code>cp usr\/src\/linux-config-4.19\/config.mips64el_none_5kc-malta linux-source-4.19\/.config<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Make deb packages for kernel\n<ul>\n<li><code>cd linux-source-4.19<\/code><\/li>\n<li><code>make ARCH=mips CROSS_COMPILE=mips64-linux-gnuabi64- oldconfig<\/code><\/li>\n<li><code>make ARCH=mips CROSS_COMPILE=mips64-linux-gnuabi64- KDEB_PKGVERSION=1 -j`nproc` bindeb-pkg<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Download the source<\/h2>\n<p>Below the script file and kernel config patch would work together to execute the above steps automatically.<\/p>\n<ul>\n<li><a href=\"http:\/\/junsun.net\/wordpress\/wp-content\/uploads\/2020\/03\/kconfig.patch_.txt\">kernel config patch<\/a><\/li>\n<li><a href=\"http:\/\/junsun.net\/wordpress\/wp-content\/uploads\/2020\/03\/build-mips-kernel.sh_.txt\">build script<\/a><\/li>\n<\/ul>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background I was trying to install Debian\/MIPS on QEMU and found out that I need to build\/update the kernel. \u00a0The existing instructions mostly talk about native build, which is painfully slow on QEMU. \u00a0I tried once and it took almost 10 hours! \u00a0There are some references to cross-build debian kernel and none applies straightforwardly. \u00a0 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/junsun.net\/wordpress\/2020\/01\/how-to-cross-build-debian-mips-kernel\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Cross-Build Debian\/MIPS Kernel&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[3],"tags":[19,15,20,21,11],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts\/55"}],"collection":[{"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":3,"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":69,"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts\/55\/revisions\/69"}],"wp:attachment":[{"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}