刷机有风险,操作需谨慎,本文仅用于学习交流,请勿用于任何非法用途
本文适合将openwrt安装到mtd12中,原厂固件在mtd13中
刷机步骤
准备ubi固件
准备原厂固件1.0.17版本 并登录路由器回滚 下载地址
在路由器后台页面,打开浏览器F12,在console输入一下命令获取ssh,并设置ssh密码
function getSTOK() { let match = location.href.match(/;stok=(.*?)\//); if (!match) { return null; } return match[1]; } function execute(stok, command) { command = encodeURIComponent(command); let path = `/cgi-bin/luci/;stok=${stok}/api/misystem/set_config_iotdev?bssid=SteelyWing&user_id=SteelyWing&ssid=-h%0A${command}%0A`; console.log(path); return fetch(new Request(location.origin + path)); } function enableSSH() { stok = getSTOK(); if (!stok) { console.error('stok not found in URL'); return; } console.log(`stok = "${stok}"`); password = prompt('Input new SSH password'); if (!password) { console.error('You must input password'); return; } execute(stok, ` nvram set ssh_en=1 nvram commit sed -i 's/channel=.*/channel=\\"debug\\"/g' /etc/init.d/dropbear /etc/init.d/dropbear start ` ) .then((response) => response.text()) .then((text) => console.log(text)); console.log('New SSH password: ' + password); execute(stok, `echo -e "${password}\\n${password}" | passwd root`) .then((response) => response.text()) .then((text) => console.log(text)); } enableSSH();
终端输入以下代码测试
nc -v 192.168.31.1 22
终端输入登录ssh
ssh root@192.168.31.1
在ssh中输入
nvram set uart_en=1 nvram set boot_wait=on nvram commit
查看分区
cat /proc/mtd
ssh中输入 nvram get flag_boot_rootfs 查看官方固件所在分区 0 是在mtd12 / 1 是在mtd13
ssh中上传ubi固件到路由器tmp目录
scp Desktop/openwrt......ubi root@192.168.31.1:/tmp
刷写固件
ubiformat /dev/mtd12 -y -f /tmp/openwrt....ubi
设置启动分区
nvram set flag_last_success=0
备注
切换固件 原厂固件>>>>>>Openwrt,登录原厂固件的ssh,输入以下命令
nvram set flag_last_success=0
nvram set flag_boot_rootfs=0
nvram commit
reboot
切换固件 Openwrt>>>>>>原厂固件,登录openwrt的ssh,输入以下命令
fw_setenv flag_last_success 1
fw_setenv flag_boot_rootfs 1
reboot
评论区