Trying to add support 7.0b1. So far, unsuccessful!

Unpacking the 7.0b1 npk file into its parts and pack it back work fine.
But the fake /init does not start. Perhaps some additional compilation flags are required.
This commit is contained in:
Sergey Sergeev 2019-09-11 21:52:24 +03:00
parent e70bb37609
commit 26f20be410
17 changed files with 101 additions and 56 deletions

3
.gitignore vendored
View file

@ -5,3 +5,6 @@ bins/*
finder/kernel-extractor finder/kernel-extractor
finder/finder finder/finder
ros/* ros/*
init/init.objdump
init/oldinit.objdump

View file

@ -6,7 +6,7 @@ All that you do is at your own risk!
The author has not liable for any of you actions and their consequences! The author has not liable for any of you actions and their consequences!
This code is presented as is and is solely for educational purposes ONLY! This code is presented as is and is solely for educational purposes ONLY!
0) Use RouterOS 6.44! 0) Use RouterOS 6.44 or 7.0b1!
1) Upload content of ./for_ftp_upload/* to target RouterOS device via FTP 1) Upload content of ./for_ftp_upload/* to target RouterOS device via FTP
2) Netboot with kernel-new.elf 2) Netboot with kernel-new.elf
3) telnet x.x.x.x 22111 3) telnet x.x.x.x 22111
@ -14,3 +14,19 @@ This code is presented as is and is solely for educational purposes ONLY!
Все что вы делаете, вы делаете на свой страх и риск! Все что вы делаете, вы делаете на свой страх и риск!
Автор не несет никакой ответственности за ваши действия и их последствия! Автор не несет никакой ответственности за ваши действия и их последствия!
Данный код представляется as-is и исключительно в учебных целях! Данный код представляется as-is и исключительно в учебных целях!
For Developers:
Place routeros-XXX.mpk to ./ros/
cd ./finder
./Build.sh
cd ..
./unpack-npk.sh ./ros/routeros-7.0beta1-arm.npk
./unpack-kernel.sh
cd ./init
./compile_for_arm.sh
cd ..
Make the necessary changes to the ./cpio-fs(compile add add busybox, etc...)
In the end, when everything is ready, to get ./bins/kernel-new.elf, run: ./pack-kernel.sh
Upload content of ./for_ftp_upload/* to target RouterOS device via FTP(to /flash/rw/disk/)
Put ./bins/kernel-new.elf to your tftp and Netboot from it
telnet x.x.x.x 22111

Binary file not shown.

View file

@ -1,28 +0,0 @@
#!/bin/sh
/bin/busybox --install -s /bin
reset
echo ""
echo "Starting system...."
mount -v proc /proc -n -t proc
mount -v sysfs /sys -n -t sysfs
mount -v devtmpfs /dev -n -t devtmpfs
echo "Done. Enjoy the power of linux."
echo
echo "Reboot is not working!"
echo "So just type an exit if you want for reboot."
echo
sh
echo "Reboot(r) or start RouterOS(s) ?"
ANSV="r"
read -n1 ANSV
[ "${ANSV}" == "r" ] && exit 0
echo "Ok. Ok. Let's run an RouterOS"
/oldinit

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

24
ftp_upload.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/sh
WORKDIR="/home/prog/openwrt/lede-all/new-lede-rb941/source"
HOST="172.20.1.1"
USER="admin"
PASS=${FTP_UPLOAD_PASS}
[ -z ${PASS} ] && {
echo "just do# export FTP_UPLOAD_PASS=xYz"
exit 1
}
FILE=./bins/kernel-new.elf
FAKEFNAME="linux_t1.bin"
[ "$HOST" = "127.0.0.1" ] && {
cat $FILE > /var/lib/tftpboot/$FAKEFNAME
exit 0
}
ftp -inv $HOST << EOF
user $USER $PASS
put $FILE $FAKEFNAME
bye
EOF
exit 0

View file

@ -3,18 +3,27 @@
#(C) Sergey Sergeev aka adron, 2019 #(C) Sergey Sergeev aka adron, 2019
# #
OPENWRT_DIR=/home/prog/openwrt/lede-all/2019-openwrt-all/openwrt-ipq806x OPENWRT_DIR=/home/prog/openwrt/lede-all/2019-openwrt-all/LAST/openwrt
export STAGING_DIR=$OPENWRT_DIR/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-7.4.0_musl_eabi export STAGING_DIR=$OPENWRT_DIR/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-9.2.0_glibc_eabi
TOOLCHAIN_PREFIX="arm-openwrt-linux-"
#export STAGING_DIR=$OPENWRT_DIR/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-9.2.0_musl_eabi
#TOOLCHAIN_PREFIX="arm-openwrt-linux-muslgnueabi"
#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
#TOOLCHAIN_PREFIX=arm-openwrt-linux
#OPENWRT_DIR=/home/prog/openwrt/lede-all/2019-openwrt-all/openwrt-ipq4xxx #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 #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 GCC=$STAGING_DIR/bin/${TOOLCHAIN_PREFIX}-gcc
OD=$STAGING_DIR/bin/arm-openwrt-linux-objdump OD=$STAGING_DIR/bin/${TOOLCHAIN_PREFIX}-objdump
OC=$STAGING_DIR/bin/arm-openwrt-linux-objcopy OC=$STAGING_DIR/bin/${TOOLCHAIN_PREFIX}-objcopy
LD=$STAGING_DIR/bin/arm-openwrt-linux-ld LD=$STAGING_DIR/bin/${TOOLCHAIN_PREFIX}-ld
$GCC -static ./init.c -o ../cpio-fs/init $GCC -static ./init.c -o ../cpio-fs/init
$OC --strip-all ../cpio-fs/init ../cpio-fs/init $OC --strip-all ../cpio-fs/init ../cpio-fs/init
exit 0
cd ../ cd ../
./pack.sh ./pack-kernel.sh
./ftp_upload.sh

View file

@ -2,7 +2,6 @@
* (C) Sergey Sergeev aka adron, 2019 * (C) Sergey Sergeev aka adron, 2019
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -22,20 +21,20 @@ void my_system(char *cmd, char *arg1, char *arg2){
} }
void daemonized_OWL(void){ void daemonized_OWL(void){
//int a = 0; int a = 0;
while(1){ while(1){
/*if(a++ % 10 == 0){ if(a++ % 10 == 0){
printf("OWL is here! %d\n", a); printf("OWL is here! %d\n", a);
}*/ }
my_system("/bin/busybox", "sh", "/flash/rw/disk/OWL.sh"); my_system("/bin/busybox", "sh", "/flash/rw/disk/OWL.sh");
sleep(1); sleep(1);
} }
} }
extern char** environ; extern char** environ;
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
pid_t pid; pid_t pid;
int a = 0;
//char *new_argv[] = { "/bin/busybox", "sh", "/etc/rc.d/rc.S", NULL }; //char *new_argv[] = { "/bin/busybox", "sh", "/etc/rc.d/rc.S", NULL };
argv[0] = "/oldinit"; argv[0] = "/oldinit";
@ -51,5 +50,6 @@ int main(int argc, char *argv[]){
//execvp(new_argv[0], new_argv); //execvp(new_argv[0], new_argv);
execvp(argv[0], argv); execvp(argv[0], argv);
return 0; return 0;
} }

18
init/oldinit_analiz.sh Executable file
View file

@ -0,0 +1,18 @@
#!/bin/bash
#
#(C) Sergey Sergeev aka adron, 2019
#
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
$OD ../cpio-fs/oldinit -x > ./oldinit.objdump
$OD ../cpio-fs/init -x > ./init.objdump

View file

@ -14,15 +14,14 @@ OBJDUMP=$STAGING_DIR/bin/arm-openwrt-linux-objdump
OBJCOPY=$STAGING_DIR/bin/arm-openwrt-linux-objcopy OBJCOPY=$STAGING_DIR/bin/arm-openwrt-linux-objcopy
LD=$STAGING_DIR/bin/arm-openwrt-linux-ld LD=$STAGING_DIR/bin/arm-openwrt-linux-ld
cd cpio-fs ROOT=$(pwd)
#find . 2>/dev/null | cpio --quiet -o --format='newc' > ../bins/x1.cpio cd ./cpio-fs
find . 2>/dev/null | cpio --quiet -o --format='newc' | \ find . 2>/dev/null | cpio --quiet -o --format='newc' | \
xz --check=crc32 --lzma2=dict=512KiB > ../bins/kernel.p3-new.xz xz --check=crc32 --lzma2=dict=512KiB > ${ROOT}/bins/kernel.p3-new.xz
#cat ../initramfs.cpio | xz --check=crc32 --lzma2=dict=512KiB > ../bins/kernel.p3-new.xz cd ${ROOT}
cd ..
cat ./bins/kernel.p2.xz ./bins/kernel.p3-new.xz > ./bins/kernel-new.combo 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 ./bins/kernel.p2.xz ./bins/kernel.p3.xz > ./bins/kernel-new.combo
${OBJCOPY} --update-section initrd=./bins/kernel-new.combo ./bins/kernel.elf ./bins/kernel-new.elf
cat ./kernel-new.elf > /var/lib/tftpboot/linux_t1.bin
#cat ./bins/kernel-new.elf > /var/lib/tftpboot/linux_t1.bin

View file

@ -84,6 +84,14 @@ truncate_kernel_p3(){
rm ./bins/kernel.p3-stripped.xz rm ./bins/kernel.p3-stripped.xz
} }
extract_kernel_cpiofs(){
local ROOT=$(pwd)
rm -Rf ./cpio-fs
mkdir ./cpio-fs
cd ./cpio-fs
xzcat ${ROOT}/bins/kernel.p3.xz | cpio -idv
}
unpack_kernel_bin unpack_kernel_bin
( xz -dc --single-stream > ./bins/initramfs.cpio && cat > ./bins/p3-garbage.bin ) < ./bins/kernel.p3.xz ( xz -dc --single-stream > ./bins/initramfs.cpio && cat > ./bins/p3-garbage.bin ) < ./bins/kernel.p3.xz
@ -94,9 +102,4 @@ unpack_kernel_bin
extract_kernel_elf extract_kernel_elf
exit 0 #extract_kernel_cpiofs
rm -Rf cpio-fs
mkdir cpio-fs
cd cpio-fs
cpio -idv < ../bins/initramfs.cpio

View file

@ -1,7 +1,8 @@
#!/bin/sh #!/bin/sh
TARGET=./ros/routeros-arm-6.44.npk #TARGET=./ros/routeros-arm-6.44.npk
#TARGET=./ros/routeros-7.0beta1-arm.npk #TARGET=./ros/routeros-7.0beta1-arm.npk
TARGET=${1}
FS_BEGIN_OFFSET=4096 FS_BEGIN_OFFSET=4096
get_squashfs_size(){ get_squashfs_size(){