commit 1423b9e5c70913a2113489a74c05e02948c0b122 Author: Sergey Sergeev Date: Sat Mar 9 18:09:44 2019 +0300 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cfdc141 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.* +!.gitignore +kernel.headers +bins/* +kernel-new.elf diff --git a/README.md b/README.md new file mode 100644 index 0000000..12da54e --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# mtik_initrd_hacks diff --git a/cpio-fs/bin/busybox b/cpio-fs/bin/busybox new file mode 100755 index 0000000..2fbd369 Binary files /dev/null and b/cpio-fs/bin/busybox differ diff --git a/cpio-fs/etc/rc.d/rc.S b/cpio-fs/etc/rc.d/rc.S new file mode 100755 index 0000000..95caa32 --- /dev/null +++ b/cpio-fs/etc/rc.d/rc.S @@ -0,0 +1,7 @@ +#!/bin/sh + +/bin/busybox --install /bin + +mount -v proc /proc -n -t proc + +sh diff --git a/cpio-fs/init b/cpio-fs/init new file mode 100755 index 0000000..cad71cb Binary files /dev/null and b/cpio-fs/init differ diff --git a/cpio-fs/oldinit b/cpio-fs/oldinit new file mode 100755 index 0000000..c023011 Binary files /dev/null and b/cpio-fs/oldinit differ diff --git a/cpio-fs/order b/cpio-fs/order new file mode 100755 index 0000000..fb01c1c Binary files /dev/null and b/cpio-fs/order differ diff --git a/dump_elf.sh b/dump_elf.sh new file mode 100755 index 0000000..aca5f7a --- /dev/null +++ b/dump_elf.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +OPENWRT_DIR=/home/prog/openwrt/lede-all/2019-openwrt-all/openwrt-ipq806x +export STAGING_DIR=$OPENWRT_DIR/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-7.4.0_musl_eabi +#OPENWRT_DIR=/home/prog/openwrt/lede-all/2019-openwrt-all/openwrt-ipq4xxx +#export STAGING_DIR=${OPENWRT_DIR}/staging_dir/toolchain-arm_cortex-a7+neon-vfpv4_gcc-7.4.0_musl_eabi + +GCC=$STAGING_DIR/bin/arm-openwrt-linux-gcc +OBJDUMP=$STAGING_DIR/bin/arm-openwrt-linux-objdump +OBJCOPY=$STAGING_DIR/bin/arm-openwrt-linux-objcopy +LD=$STAGING_DIR/bin/arm-openwrt-linux-ld + +${OBJDUMP} -x kernel.elf > ./kernel.headers +#${OBJDUMP} -x kernel-new.elf > ./kernel.headers + +#${OBJCOPY} -j .text -j initrd -S ./kernel.elf ./kernel.OWL1 +#${OBJCOPY} -R initrd -S ./kernel.elf ./kernel.OWL1 +#${OBJCOPY} -j .rodata -O binary ./kernel.elf ./kernel.OWL1 + +#initrd is kernel.p2-p3 diff --git a/init/compile_for_arm.sh b/init/compile_for_arm.sh new file mode 100755 index 0000000..278d1c5 --- /dev/null +++ b/init/compile_for_arm.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +OPENWRT_DIR=/home/prog/openwrt/lede-all/2019-openwrt-all/openwrt-ipq806x +export STAGING_DIR=$OPENWRT_DIR/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-7.4.0_musl_eabi +#OPENWRT_DIR=/home/prog/openwrt/lede-all/2019-openwrt-all/openwrt-ipq4xxx +#export STAGING_DIR=${OPENWRT_DIR}/staging_dir/toolchain-arm_cortex-a7+neon-vfpv4_gcc-7.4.0_musl_eabi + +GCC=$STAGING_DIR/bin/arm-openwrt-linux-gcc +OD=$STAGING_DIR/bin/arm-openwrt-linux-objdump +OC=$STAGING_DIR/bin/arm-openwrt-linux-objcopy +LD=$STAGING_DIR/bin/arm-openwrt-linux-ld + +$GCC -static ./init.c -o ../cpio-fs/init +$OC --strip-all ../cpio-fs/init ../cpio-fs/init diff --git a/init/init.c b/init/init.c new file mode 100644 index 0000000..89dc019 --- /dev/null +++ b/init/init.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +extern char** environ; + +int main(int argc, char *argv[]){ + char *new_argv[] = { "/bin/busybox", "sh", "/etc/rc.d/rc.S", NULL }; + + environ[0] = "PATH=/sbin:/bin"; + environ[1] = NULL; + + execvp(new_argv[0], new_argv); + return 0; +} diff --git a/kernel.elf b/kernel.elf new file mode 100644 index 0000000..b47a838 Binary files /dev/null and b/kernel.elf differ diff --git a/pack.sh b/pack.sh new file mode 100755 index 0000000..4d09981 --- /dev/null +++ b/pack.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +OPENWRT_DIR=/home/prog/openwrt/lede-all/2019-openwrt-all/openwrt-ipq806x +export STAGING_DIR=$OPENWRT_DIR/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-7.4.0_musl_eabi +#OPENWRT_DIR=/home/prog/openwrt/lede-all/2019-openwrt-all/openwrt-ipq4xxx +#export STAGING_DIR=${OPENWRT_DIR}/staging_dir/toolchain-arm_cortex-a7+neon-vfpv4_gcc-7.4.0_musl_eabi + +GCC=$STAGING_DIR/bin/arm-openwrt-linux-gcc +OBJDUMP=$STAGING_DIR/bin/arm-openwrt-linux-objdump +OBJCOPY=$STAGING_DIR/bin/arm-openwrt-linux-objcopy +LD=$STAGING_DIR/bin/arm-openwrt-linux-ld + +cd cpio-fs +#find . 2>/dev/null | cpio --quiet -o --format='newc' > ../bins/x1.cpio +find . 2>/dev/null | cpio --quiet -o --format='newc' | \ + xz --check=crc32 --lzma2=dict=512KiB > ../bins/kernel.p3-new.xz +#cat ../initramfs.cpio | xz --check=crc32 --lzma2=dict=512KiB > ../bins/kernel.p3-new.xz +cd .. + +cat ./bins/kernel.p2.xz ./bins/kernel.p3-new.xz > ./bins/kernel-new.combo +${OBJCOPY} --update-section initrd=./bins/kernel-new.combo ./kernel.elf ./kernel-new.elf + +cat ./kernel-new.elf > /var/lib/tftpboot/linux_t1.bin + diff --git a/unpack.sh b/unpack.sh new file mode 100644 index 0000000..be6c505 --- /dev/null +++ b/unpack.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +exit 0 + +dd if=kernel.elf bs=1 skip=0 count=43504 of=./bins/kernel.HEAD +dd if=kernel.elf bs=1 skip=43504 count=1605632 of=./bins/kernel.p2.xz +dd if=kernel.elf bs=1 skip=1649136 count=84812 of=./bins/kernel.p3.xz +dd if=kernel.elf bs=1 skip=1733948 of=./bins/kernel.TAIL + +#( xz -dc --single-stream > ./bins/initramfs.cpio && cat > ./bins/p3-tail.bin ) < ./bins/kernel.p3.xz +xz -dc > ./bins/initramfs.cpio < ./bins/kernel.p3.xz + +rm -Rf cpio-fs +mkdir cpio-fs +cd cpio-fs +cpio -idv < ../bins/initramfs.cpio