-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathmkramdisk
executable file
·156 lines (135 loc) · 4.47 KB
/
mkramdisk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#! /usr/bin/env bash
# $1=model $2=version $3=config
MODEL="$1"
VER="$2"
CONFIG="$3"
shift 3
MV=${MODEL}_${VER}
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT=$(dirname ${SCRIPT_DIR})
OUTDIR=$ROOT/build/$MV
PREFIX_PATH=$ROOT/install/$MV
SRCDIR=$ROOT/linux
WORKDIR=$ROOT/$MV
NEWRD=$WORKDIR/ramdisk
mkdir -p $OUTDIR
mkdir -p $PREFIX_PATH
mkdir -p $WORKDIR
mkdir -p $NEWRD
# 3rd party prebuilt modules
UPDATE_MOD_PATH=$ROOT/3rdparty/$MV/modules
UPDATE_FW_PATH=$ROOT/3rdparty/$MV/firmware
# from synology rootfs
RELEASE_MOD_PATH=$ROOT/rootfs/$MV/lib/modules
RELEASE_FW_PATH=$ROOT/rootfs/$MV/lib/firmware
# synology rd.gz
RAMDISK_MOD_PATH=$ROOT/ramdisk/$MV/lib/modules
RAMDISK_FW_PATH=$ROOT/ramdisk/$MV/lib/firmware
# built with beta source
BETA_MOD_PATH=$ROOT/install/$MV/lib/modules
BETA_FW_PATH=$ROOT/install/$MV/lib/firmware
TOOL_PATH=$ROOT/tool
TOOLCHAIN=$ROOT/toolchain/$MV/x86_64-pc-linux-gnu
cat $SRCDIR/synoconfigs/$CONFIG $WORKDIR/config.override > $OUTDIR/.config
export CROSS_COMPILE=${TOOLCHAIN}/bin/x86_64-pc-linux-gnu-
#cat $WORKDIR/config.override >> $OUTDIR/.config
if [ "x$1" = "xmenuconfig" ]; then
make -C $SRCDIR O=$OUTDIR menuconfig
exit 0
fi
if [ "x$1" = "xsavedefconfig" ]; then
make -C $SRCDIR O=$OUTDIR savedefconfig
cp $OUTDIR/defconfig .
exit 0
fi
make -C $SRCDIR O=$OUTDIR oldconfig
if [ "x$1" = "xpass" ]; then
shift
make -C $SRCDIR O=$OUTDIR $@
exit 0
fi
if [ "x$1" = "xsymbol" ]; then
make -C $SRCDIR O=$OUTDIR -j5 bzImage EXTRA_CFLAGS=-g
exit 0
fi
if [ "x$1" = "xkernel" -o "x$1" = "xall" ]; then
make -C $SRCDIR O=$OUTDIR -j5 bzImage
exit 0
fi
mkdir -p $NEWRD/usr/sbin
mkdir -p $NEWRD/usr/bin
mkdir -p $NEWRD/etc
InstallFirmware()
{
local fw="$1"
local fwbase=$(basename $fw)
local update=$(find $UPDATE_FW_PATH -name $fwbase -type f | fgrep "$fw")
local release=$(find $RELEASE_FW_PATH -name $fwbase -type f | fgrep "$fw")
local ramdisk=$(find $RAMDISK_FW_PATH -name $fwbase -type f | fgrep "$fw")
local beta=$(find $BETA_FW_PATH -name $fwbase -type f | fgrep "$fw")
local src=""
[ -z "$src" -a -n "$update" ] && src="$update"
[ -z "$src" -a -n "$release" -a -z "$ramdisk" ] && src="$release";
[ -z "$src" -a -n "$ramdisk" ] && src="nop";
[ -z "$src" -a -n "$beta" ] && src="$beta";
[ -z "$src" ] && echo "$fw not found any where"
if [ -n "$src" -a "x$src" != "xnop" ]; then
install -DTm 0755 "$src" "$NEWRD/usr/lib/firmware/$fw"
else
return 1
fi
}
InstallModule()
{
local mod="$1"
local update=$(find $UPDATE_MOD_PATH -name ${mod}.ko)
local release=$(find $RELEASE_MOD_PATH -name ${mod}.ko)
local ramdisk=$(find $RAMDISK_MOD_PATH -name ${mod}.ko)
local beta=$(find $BETA_MOD_PATH -name ${mod}.ko)
local src=""
[ -z "$src" -a -n "$update" ] && src="$update"
[ -z "$src" -a -n "$release" -a -z "$ramdisk" ] && src="$release";
[ -z "$src" -a -n "$ramdisk" ] && src="nop";
[ -z "$src" -a -n "$beta" ] && src="$beta";
[ -z "$src" ] && echo "$mod not found any where"
if [ -n "$src" -a "x$src" != "xnop" ]; then
install -DTm 0644 "$src" "$NEWRD/usr/lib/modules/${mod}.ko"
for fw in $(modinfo $src |grep ^firmware | cut -d: -f2); do
if InstallFirmware $fw; then
[ -n "$firmwares" ] && firmwares="$firmwares "
firmwares="$firmwares$fw"
fi
done
fi
}
if [ "x$1" = "xmodule" -o "x$1" = "xall" -o "x$1" = "x" ]; then
make -C $SRCDIR O=$OUTDIR -j5 modules
make -C $SRCDIR INSTALL_MOD_PATH=$PREFIX_PATH O=$OUTDIR -j5 modules_install
make -C $SRCDIR INSTALL_MOD_PATH=$PREFIX_PATH O=$OUTDIR -j5 firmware_install
firmwares=""
source $WORKDIR/modules.conf
#disk modules are loaded early
for mod in $DISK_MODULES $EXTRA_MODULES $OPTIONAL_MODULES; do
InstallModule $mod
done
echo 'EXTRA_MODULES="'$EXTRA_MODULES'"' > $NEWRD/etc/rc.modules
echo 'DISK_MODULES="'$DISK_MODULES'"' >> $NEWRD/etc/rc.modules
echo 'EXTRA_FIRMWARES="'$firmwares'"' >> $NEWRD/etc/rc.modules
fi
if [ "x$1" = "xtool" -o "x$1" = "xall" -o "x$1" = "x" ]; then
make -C $SRCDIR O=$OUTDIR M=$TOOL_PATH
make -C $TOOL_PATH
cp -a $TOOL_PATH/modprobe $NEWRD/usr/sbin/
fi
if [ "x$1" = "xoverlay" ]; then
cp $WORKDIR/vmlinux.bin ${OUTDIR}/arch/x86/boot/compressed/vmlinux.bin
$SCRIPT_DIR/genzImage
exit 0
fi
cp $SCRIPT_DIR/patch $NEWRD/usr/bin/
cp $SCRIPT_DIR/init $NEWRD/
git -C $ROOT/ramdisk/$MV diff baseline > $NEWRD/etc/jun.patch
#single core machine may suffer a text busy issue due to fd lazy close during initramfs populating
pushd $NEWRD
(find . -name modprobe && find . \! -name modprobe) | cpio --owner root:root -oH newc | lzma -9 > $WORKDIR/jun.lzma
popd