Skip to content

Commit

Permalink
add pack.sh for packing the basic rootfs.img
Browse files Browse the repository at this point in the history
  • Loading branch information
jialeicui committed Jan 26, 2024
1 parent efb6aa4 commit e391aae
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ https://github.com/jialeicui/open-lx01/assets/3217223/b5e0a511-1a28-42c8-9462-f9

### 刷自己的第一个固件

这步我们的目的可能是让音箱默认开 ssh, 也可能是因为我们不知道密码, 想进 shell, 这里一起搞定
这步我们的目的可能是让音箱默认开 ssh, 也可能是因为我们不知道密码, 想进 shell, 这里一起搞定
(下面几个步骤的自动化脚本参考 [打包](./src/pack/))

1. 下载官方固件,
- [1.56.1](https://cdn.cnbj1.fds.api.mi-img.com/xiaoqiang/rom/lx01/mico_firmware_c1cac_1.56.1.bin)
Expand Down Expand Up @@ -138,7 +139,7 @@ https://github.com/jialeicui/open-lx01/assets/3217223/b5e0a511-1a28-42c8-9462-f9
说明: 1 是计算方式 MD5, 具体可以 `man openssl-passwd` 查看更多帮助

修改 `squashfs-root/etc/shadow` 的 root 那一行, 改成
`root:$1$xiaoai$803hWklCcQwX7v5gYP6pB0:18128:0:99999:7::` 保存
`root:$1$xiaoai$803hWklCcQwX7v5gYP6pB0:18128:0:99999:7:::` 保存

这样就把 root 的密码修改成了 root, 如果前面我们尝试登陆的时候发现是 dsa 校验, 那么我们还需要修改校验方式为默认, 修改方法如下:

Expand All @@ -149,10 +150,9 @@ https://github.com/jialeicui/open-lx01/assets/3217223/b5e0a511-1a28-42c8-9462-f9
- #### enable sshd

说明: 固件里使用 dropbear 作为 ssh server (轻量)
修改 etc/init.d/dropbear 启动脚本(较复杂, 可参考 [patch](./src/pack/patches/001.patch))

```sh
# 创建工作目录, 具体原因可以查看 squashfs-root/etc/init.d/dropbear
sudo mkdir squashfs-root/data/etc/dropbear/
# 自动启动
sudo ln -s ../init.d/dropbear squashfs-root/etc/rc.d/S96dropbear
```
Expand Down
3 changes: 3 additions & 0 deletions src/pack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.bin
rootfs.img
tmp
13 changes: 13 additions & 0 deletions src/pack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 打包基础固件脚本

- uart 免密登录
- ssh 自动开启
- root 密码设置成 root

需要安装 squashfs 相关的工具

```sh
sudo ./pack.sh
```

执行成功后会在本目录下生成一个 rootfs.img
39 changes: 39 additions & 0 deletions src/pack/pack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e

BASE_DIR=`pwd`
WORK_DIR=`pwd`/tmp
#MD5SUM="1ae7eb1bdbb764b946654a08dfec1cac"
URL="https://cdn.cnbj1.fds.api.mi-img.com/xiaoqiang/rom/lx01/mico_firmware_c1cac_1.56.1.bin"

# if firmware.bin exists, skip download
if [ -f mico_firmware_c1cac_1.56.1.bin ]; then
echo "firmware.bin exists, skip download"
else
wget -c $URL
fi

rm -rf $WORK_DIR && mkdir -pv $WORK_DIR && ln -sf $BASE_DIR/mico_firmware_c1cac_1.56.1.bin $WORK_DIR/firmware.bin
pushd $WORK_DIR

dd if=firmware.bin bs=8 skip=524409 of=rootfs.img
unsquashfs rootfs.img && rm -rf rootfs.img

pushd squashfs-root

PATCH_DIR=$BASE_DIR/patches
PATCHES=`ls $PATCH_DIR/*.patch | sort -n`

for patch in $PATCHES; do
patch -p1 < $patch
done

popd

mksquashfs squashfs-root rootfs.img -comp xz -b 256K -noappend && mv rootfs.img $BASE_DIR/rootfs.img

popd

rm -rf $WORK_DIR

90 changes: 90 additions & 0 deletions src/pack/patches/001.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
diff --git a/etc/init.d/dropbear b/etc/init.d/dropbear
index b2d2719..45eeb4f 100755
--- a/etc/init.d/dropbear
+++ b/etc/init.d/dropbear
@@ -53,8 +53,7 @@ dropbear_instance()
MaxAuthTries mdns ipaddrs

validate_section_dropbear "${1}" || {
- echo "validation failed"
+ echo "validation failed and skip"
- return 1
}

[ -n "${Interface}" ] && {
@@ -64,7 +62,6 @@ dropbear_instance()
}
}

- [ "${enable}" = "0" ] && return 1
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
local pid_file="/var/run/${NAME}.${PIDCOUNT}.pid"

@@ -111,20 +108,12 @@ keygen()
load_interfaces()
{
config_get interface "$1" Interface
- config_get enable "$1" enable 1
-
- [ "${enable}" = "1" ] && interfaces=" ${interface} ${interfaces}"
+ interfaces=" ${interface} ${interfaces}"
}

start_service()
{
- ssh_en=`cat /data/ssh_en 2>/dev/null`
- ssh_en_bind=`cat /data/.ssh_en 2>/dev/null`
- ssh_en_tmp=`cat /tmp/ssh_en 2>/dev/null`
- channel=`micocfg_channel 2>/dev/null`
- if [ "$ssh_en" != "1" -a "$ssh_en_bind" != "1" -a "$ssh_en_tmp" != "1" -a "$channel" = "release" ]; then
- return 0
- fi
+ mkdir -p /data/etc/dropbear
[ -s /data/etc/dropbear/dropbear_rsa_host_key ] || keygen

. /lib/functions.sh
diff --git a/etc/inittab b/etc/inittab
index 7a6c352..94276b8 100644
--- a/etc/inittab
+++ b/etc/inittab
@@ -1,3 +1,3 @@
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
-::askconsole:/bin/login
+::askconsole:/bin/sh --login
diff --git a/etc/pam.d/common-auth b/etc/pam.d/common-auth
index 111e32a..c610144 100644
--- a/etc/pam.d/common-auth
+++ b/etc/pam.d/common-auth
@@ -8,10 +8,10 @@
# traditional Unix authentication mechanisms.
#

-auth sufficient libmico-pam.so
-account sufficient libmico-pam.so
+#auth sufficient libmico-pam.so
+#account sufficient libmico-pam.so
# here are the per-package modules (the "Primary" block)
-# auth [success=1 default=ignore] pam_unix.so nullok_secure
+ auth [success=1 default=ignore] pam_unix.so nullok_secure
# here's the fallback if no module succeeds
auth requisite pam_deny.so
# prime the stack with a positive return value if there isn't one already;
diff --git a/etc/rc.d/S99dropbear b/etc/rc.d/S99dropbear
new file mode 120000
index 0000000..44af88d
--- /dev/null
+++ b/etc/rc.d/S99dropbear
@@ -0,0 +1 @@
+../init.d/dropbear
\ No newline at end of file
diff --git a/etc/shadow b/etc/shadow
index 9383c5d..058f9df 100644
--- a/etc/shadow
+++ b/etc/shadow
@@ -1,4 +1,4 @@
-root:$1$6QTE6j6z$lVroJsorN7M7F2h1mrdIS0:18128:0:99999:7:::
+root:$1$xiaoai$803hWklCcQwX7v5gYP6pB0:18128:0:99999:7:::
daemon:*:0:0:99999:7:::
ftp:*:0:0:99999:7:::
network:*:0:0:99999:7:::

0 comments on commit e391aae

Please sign in to comment.