forked from kendryte/k510_buildroot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·138 lines (110 loc) · 3.86 KB
/
run.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
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
#!/bin/sh
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
if ! cat /proc/partitions | grep mmcblk0p[1-9] > /dev/null ; then
echo "emmc first use "
(parted /dev/mmcblk0 mklabel msdos;emmcsize=$(parted /dev/mmcblk0 print free | grep Free | awk '{print $2}');\
parted -a minimal /dev/mmcblk0 mkpart primary 1049kB 2097kB; \
parted -a minimal /dev/mmcblk0 mkpart primary 2098kB 33.6MB;\
parted -a minimal /dev/mmcblk0 mkpart primary 33.6MB 570MB;\
parted -a minimal /dev/mmcblk0 mkpart primary 570MB ${emmcsize}; \
yes | mkfs.vfat /dev/mmcblk0p2; \
yes | mkfs.ext2 /dev/mmcblk0p3; \
yes | mkfs.vfat /dev/mmcblk0p4;) > /dev/null 2>&1
fi
if [ -f /first_run_flag_file ];then
#set -x
bootddev=$(cat /proc/cmdline | sed -n "s#root=\(\/dev\/mmcblk[0-9]\).*#\1#p" )
if [ -n "${bootddev}" ];then
rootpart=$(cat /proc/cmdline | sed -n "s/root=\/dev\/mmcblk[0-9]\p\([0-9]\).*/\1/p" )
datapart=$(($rootpart+1))
if $( cat /proc/partitions | grep ${bootddev:5}p${datapart} > /dev/null ) ;then
echo "${bootddev}p${datapart} /root/data auto" >>/etc/fstab
echo "${bootddev}p${datapart} exist"
rm -f /first_run_flag_file;
else #不存在分区
parted ${bootddev} rm $datapart 2>/dev/null
( parted ${bootddev} print free | awk \
"function partsd(start, end){a=\" parted -a minimal ${bootddev} mkpart primary fat32 \" start \" \" end \" ;\";print(a); system(a);}\
function mkfspart(part){dp=\"${bootddev}p\" part; fs_cmd=\"/sbin/mkfs.vfat \" dp; print(fs_cmd);system(fs_cmd);}\
function add_fstab(part){dp=\"${bootddev}p\" part;cmd=\"echo \" dp \" /root/data auto >>/etc/fstab\"; print(cmd);system(cmd);}\
function mount_part(part){dp=\"${bootddev}p\" part;cmd=\"mount \" dp \" /root/data \"; print(cmd);system(cmd);}\
BEGIN {i=0; s[i]=0;e[i]=0;}\
/Free Space/ { i++; print \$1,\$2; s[i]=\$1;e[i]=\$2;} \
END {partsd( s[i], e[i]); mkfspart($datapart);add_fstab($datapart); mount_part($datapart);}" ;
rm -f /first_run_flag_file; ) >/dev/null 2>&1
fi
fi
#set +x
fi
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
mkdir -p /dev/shm
mount -a
#产生coredump文件,coredump文件在/root/data/coredump/目录下面
[ -d /root/data/coredump ] || mkdir -p /root/data/coredump
echo "|/etc/core_dump_gzip.sh %e %s %p" > /proc/sys/kernel/core_pattern
ulimit -c unlimited
export hostname0=
export mnt_path0=
export hostname1=
export mnt_path1=
export auto=
#
dmesg > dmesg_boot.log
echo $(grep Machine /dmesg_boot.log| sed 's/^.*canaan //g') > platform.log
linux_ver=`uname -r`
if [ -d /lib/modules/$linux_ver/ ]; then
depmod -a
while read module
do
if [ "$auto" == "1" ]; then
module_name=`basename $module .ko`
rmmod $module_name
fi
#insmod /lib/modules/$linux_ver/$module
module_name=`basename $module .ko`
modprobe $module_name
done</lib/modules/$linux_ver/modules.order
fi
sleep 0.5
ifconfig wlan0 up
wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf -B
#change SHELL default version
#if [ -f /bin/bash ]; then
# ln -sf /bin/bash /bin/sh
#fi
if [ "$auto" != "1" ]; then
exit 1
fi
#for i in $drvs
#do
#drv=$(dmesg | grep "$i")
#if [ "$?" == "1" ]; then
# echo "$i NOT exist"
# exit
#fi
#done
#exit
test -z $hostname1
if [ "$?" == "1" ]; then
echo "mount hastname1 = $hostname1"
mount -t nfs -o nolock,rsize=1024,wsize=1024 $hostname1:$mnt_path1 mnt
else
echo "mount hastname0 = $hostname0"
mount -t nfs -o nolock,rsize=1024,wsize=1024 $hostname0:$mnt_path0 mnt
fi
if [ "$?" != "0" ]; then
echo "mount mnt fail"
exit 1
fi
lsmod 2>&1 | tee mnt/log/lsmod.log
cp dmesg_boot.log mnt/log/
mount /dev/mmcblk0p1 /tmp
if [ "$?" != "0" ]; then
echo "mount tmp fail"
exit 1
fi
cd
cd mnt
dmesg > log/dmesg_run.log
sh test_drivers.sh