Skip to content

Instantly share code, notes, and snippets.

@ca4ti
Forked from avoidik/006-glibc-conflict.patch
Created April 3, 2024 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ca4ti/3952bbee245a612eab3523a779e2f983 to your computer and use it in GitHub Desktop.
Save ca4ti/3952bbee245a612eab3523a779e2f983 to your computer and use it in GitHub Desktop.
Compile LEDE v17.01.4 for Mikrotik MetaROUTER (MIPS only)
--- a/misc/create_inode.c 2016-09-02 04:17:32.000000000 +0000
+++ b/misc/create_inode.c 2020-01-04 20:56:26.150590109 +0000
@@ -392,7 +392,7 @@
}
#endif /* !defined HAVE_PREAD64 && !defined HAVE_PREAD */
-static errcode_t copy_file_range(ext2_filsys fs, int fd, ext2_file_t e2_file,
+static errcode_t copy_file_chunk(ext2_filsys fs, int fd, ext2_file_t e2_file,
off_t start, off_t end, char *buf,
char *zerobuf)
{
@@ -466,7 +466,7 @@
data_blk = data & ~(fs->blocksize - 1);
hole_blk = (hole + (fs->blocksize - 1)) & ~(fs->blocksize - 1);
- err = copy_file_range(fs, fd, e2_file, data_blk, hole_blk, buf,
+ err = copy_file_chunk(fs, fd, e2_file, data_blk, hole_blk, buf,
zerobuf);
if (err)
return err;
@@ -516,7 +516,7 @@
}
for (i = 0, ext = ext_buf; i < fiemap_buf->fm_mapped_extents;
i++, ext++) {
- err = copy_file_range(fs, fd, e2_file, ext->fe_logical,
+ err = copy_file_chunk(fs, fd, e2_file, ext->fe_logical,
ext->fe_logical + ext->fe_length,
buf, zerobuf);
if (err)
@@ -569,7 +569,7 @@
goto out;
#endif
- err = copy_file_range(fs, fd, e2_file, 0, statbuf->st_size, buf,
+ err = copy_file_chunk(fs, fd, e2_file, 0, statbuf->st_size, buf,
zerobuf);
out:
ext2fs_free_mem(&zerobuf);

Compile LEDE v17.01.4 for Mikrotik MetaROUTER

Steps

  1. Prepare virtual machine: Install VirtualBox, download Ubuntu ISO image, and install it.

    Add current user to sudoers list

    echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/10-$USER > /dev/null
    # re-login after

    Don't forget to install VirtualBox Additions

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install -y build-essential dkms linux-headers-$(uname -r)
    sudo mount /dev/sr0 /media
    sudo /media/VBoxLinuxAdditions.run
    sudo umount /media

    Optionally, mount VirtualBox shared folder

    mkdir $HOME/projects
    echo "projects /home/$USER/projects vboxsf uid=1000,gid=1000,dmode=755,fmode=755,noauto 0 0" | sudo tee -a /etc/fstab > /dev/null
    mount projects

    Optionally, disable hugepages

    cat << 'EOF' | sudo tee /etc/rc.local > /dev/null
    #!/bin/sh
    if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
      echo never > /sys/kernel/mm/transparent_hugepage/enabled
    fi
    if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
      echo never > /sys/kernel/mm/transparent_hugepage/defrag
    fi
    exit 0
    EOF
    sudo chown root:root /etc/rc.local
    sudo chmod 644 /etc/rc.local

    Optionally, disable timers

    sudo systemctl list-timers --all
    sudo systemctl stop motd-news.timer
    sudo systemctl disable motd-news.timer
    sudo systemctl stop apt-daily-upgrade.timer
    sudo systemctl disable apt-daily-upgrade.timer
    sudo systemctl stop apt-daily.timer
    sudo systemctl disable apt-daily.timer
    sudo systemctl daemon-reload
  2. Prepare environment: Install required packages

    sudo apt-get install -y subversion git libncurses5-dev zlib1g-dev gawk ccache gettext libssl-dev xsltproc zip python-pip
  3. Prepare build system: Git clone

    Fetch OpenWRT source code

    git clone https://git.openwrt.org/openwrt/openwrt.git
    cd openwrt
    git fetch --tags
    git checkout v17.01.4
    git cherry-pick eaf6f1532d78cff68153298334e9b3e513b407ed # nftables: Update to 0.7
    git cherry-pick 74395d97a9d47f1cf8afa4bb6b2f90120072489e # libs/libnftnl: Update to 1.0.7
  4. Prepare build system: Add e2fsprogs patch

    Save included 006-glibc-conflict.patch as tools/e2fsprogs/patches/006-glibc-conflict.patch

    curl -fsSL https://gist.githubusercontent.com/avoidik/b15ef6dd5fb20bf59a5d6a0347034244/raw/96048f2590cb6c65d5522b3118536b00713ae96c/006-glibc-conflict.patch -o tools/e2fsprogs/patches/006-glibc-conflict.patch
  5. Prepare build system: Prepare device branch & build system dependencies

    git clone https://github.com/cuihaoleo/lede-mr-mips target/linux/mr-mips
    make defconfig
    make prereq
    cp target/linux/mr-mips/misc/lede-config .config
    make oldconfig # or make menuconfig

    Prepare tools

    make download
    make tools/install
    make toolchain/install
  6. Build

    make -j $(nproc)

    In case of an error

    make -j1 V=s

    The resulting files will be available in bin/targets/mr-mips/generic/ folder

Build packages

./scripts/feeds update -a
./scripts/feeds install dnsmasq dnscrypt-proxy

Or replace latter to install all available packages

./scripts/feeds install -a

This may change .config file, just run make menuconfig and save

Build single package

Install tools & toolchain first

# build nano package - https://openwrt.org/packages/pkgdata/nano
make package/base-files/compile
make package/base-files/install
make package/ncurses/compile
make package/ncurses/install
make package/nano/compile
make package/nano/install
make package/index

Build kernel modules

Install tools & toolchain first

make menuconfig # set kernel modules
make target/linux/compile
make package/kernel/linux/compile
make package/kernel/linux/install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment