-
Notifications
You must be signed in to change notification settings - Fork 34
/
prepare_k210_cpio.sh
executable file
·65 lines (50 loc) · 1.83 KB
/
prepare_k210_cpio.sh
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
#!/usr/bin/env sh
export PATH=/opt/riscv64-uclibc/bin:$(pwd)/riscv64-nommu-buildroot/output/host/bin:$PATH
export PROJ_ROOT="$(pwd)"
export ROOTFS="$(pwd)/rootfs_k210"
export KERNEL="$(pwd)/linux-kernel"
# safe check
[ -d "rootfs_k210" ] && echo "Directory rootfs_k210 exists." || echo "Error: Directory rootfs_k210 does not exists, please cd to project root."
cd $PROJ_ROOT
if [ ! -d "rootfs_k210" ] ; then
cd "$PROJ_ROOT/busybox"
make k210_nommu_defconfig
make SKIP_STRIP=y
make SKIP_STRIP=y install
cd "$PROJ_ROOT/tinycc"
./configure --prefix=/usr --cross-prefix=riscv64-linux- --cpu=riscv64 --extra-cflags="-DCONFIG_TCC_STATIC=1" --extra-ldflags=-Wl,-elf2flt=-r
make
make DESTDIR=$(pwd)/../rootfs_k210 install
# remove data to reduce size
rm -rf $ROOTFS/usr/include/libtcc.h
rm -rf $ROOTFS/usr/lib/libtcc.a
rm -rf $ROOTFS/usr/lib/tcc
cd "$PROJ_ROOT/k210_lib"
make
make DESTDIR=$(pwd)/../rootfs_k210 install
fi
cd $PROJ_ROOT
[ -d "rootfs_k210" ] && rm -rf $KERNEL/k210.cpio || echo "Error: Please cd to project root."
[ -d "rootfs_k210" ] && rm -rf $ROOTFS/usr/share || echo "Error: Please cd to project root."
cp -rf $PROJ_ROOT/init $ROOTFS/bin/
# Begin Damien Le Moal's code:
# https://lore.kernel.org/linux-riscv/BYAPR04MB5816C1EADCEF92F1F1DE60E0E7140@BYAPR04MB5816.namprd04.prod.outlook.com/T/#t
# Prepare
cd $ROOTFS
mkdir dev sys proc tmp root etc
mkdir dev/pts dev/shm
cd dev
sudo mknod -m 622 console c 5 1
sudo mknod -m 666 null c 1 3
sudo mknod -m 666 zero c 1 5
sudo mknod -m 666 ptmx c 5 2
sudo mknod -m 666 tty c 5 0
sudo mknod -m 444 random c 1 8
sudo mknod -m 444 urandom c 1 9
sudo mknod -m 666 ttySIF0 c 4 64
sudo mknod -m 666 tty0 c 4 0
sudo chown root:tty {console,ptmx,tty}
cd ..
# Create image file
echo "Creating cpio image"
find . | cpio -H newc -o > $KERNEL/k210.cpio