20171026_jeffrey - silenceuncrio/diary GitHub Wiki
review
follow 20171023_jeffrey 的步伐
當時前進到 check point 3
沒能突破 check point 4
先恢復成當天的 rc.local
echo -e "\ncheck point 3"
# ======================================================================
# | read-only remount a mounted root file system
# | attach MTD device to UBI according to the current rootfs
# ======================================================================
/bin/mkdir -p /mnt/data
/bin/mkdir -p /mnt/config
/bin/mkdir -p /home/log
if df | grep rootfs_a
then
#echo "read-only remount a mounted root file system"
#mount -t ubifs ubi0:rootfs_a / -o remount,ro
echo "attach MTD device 5 (mtd5) to UBI - ubi1:config_a"
ubiattach -m 5
mount -t ubifs ubi1:config_a /mnt/config
else
#echo "read-only remount a mounted root file system"
#mount -t ubifs ubi0:rootfs_b / -o remount,ro
echo "attach MTD device 10 (mtd10) to UBI - ubi1:config_b"
ubiattach -m 10
mount -t ubifs ubi1:config_b /mnt/config
fi
echo -e "\ncheck point 4"
exit
開機的訊息如下
Running local boot scripts (/etc/rc.local)
check point 1
check point 2
check point 3
attach MTD device 10 (mtd10) to UBI - ubi1:config_b
ubiattach: error!: cannot attach mtd10
error 19 (No such device)
error
m300e login:
if df | grep rootfs_a
的目的是要得知目前的 dual image 是跑 a
還是 b
我們目前已經無法使用 df
來區別
不過我們可以直接使用 fw_printenv
來讀取 uboot 相關的 env 獲取目前 dual image 跑的是 a
還是 b
root@m300e:~# fw_printenv image
image=zImage_a
root@m300e:~# fw_printenv fdt_file
fdt_file=imx6ul-14x14-evk_a.dtb
root@m300e:~# fw_printenv mmcroot
mmcroot=/dev/mmcblk1p2 rootwait rw
修改 rc.local
check point 4 前的內容
echo -e "\ncheck point 3"
# ======================================================================
# | read-only remount a mounted root file system
# | attach MTD device to UBI according to the current rootfs
# ======================================================================
/bin/mkdir -p /mnt/data
/bin/mkdir -p /mnt/config
/bin/mkdir -p /home/log
if fw_printenv image | grep zImage_a
then
echo "running image is a"
else
echo "running image is b"
fi
echo -e "\ncheck point 4"
exit
開機訊息如下
Running local boot scripts (/etc/rc.local)
check point 1
check point 2
check point 3
image=zImage_a
running image is a
check point 4
.
m300e login:
從 dual image b 開機
setenv mmcroot /dev/mmcblk1p3 rootwait rw
setenv image zImage_b
setenv fdt_file imx6ul-14x14-evk_b.dtb
開機訊息如下
Running local boot scripts (/etc/rc.local)
check point 1
check point 2
check point 3
running image is b
check point 4
.
m300e login:
繼續 check point 4 的路段
echo -e "\ncheck point 3"
# ======================================================================
# | prepare '/mnt/data' and '/home/log' for the application
# ======================================================================
mkdir -p /mnt/data
mkdir -p /home/log
mkdir -p /mnt/mmc
mount -t ext3 /dev/mmcblk1p4 /mnt/mmc
if fw_printenv image | grep zImage_a
then
echo "running image is a"
mkdir -p /mnt/mmc/app_a/data
mount /mnt/mmc/app_a/data /mnt/data
mkdir -p /mnt/mmc/app_a/log
mount /mnt/mmc/app_a/log /home/log
else
echo "running image is b"
mkdir -p /mnt/mmc/app_b/data
mount /mnt/mmc/app_b/data /mnt/data
mkdir -p /mnt/mmc/app_b/log
mount /mnt/mmc/app_b/log /home/log
fi
echo -e "\ncheck point 4"
exit
開機後可以透過 df
和 mount
來觀察
df
root@m300e:~# df
Filesystem 1024-blocks Used Available Use% Mounted on
/dev/root 388480 68548 299452 19% /
devtmpfs 90860 0 90860 0% /dev
tmpfs 254892 172 254720 0% /run
tmpfs 254892 28 254864 0% /var/volatile
/dev/mmcblk1p4 2728416 4260 2582232 0% /mnt/mmc
/dev/mmcblk1p4 2728416 4260 2582232 0% /mnt/data
/dev/mmcblk1p4 2728416 4260 2582232 0% /home/log
mount
root@m300e:~# mount
/dev/root on / type ext3 (rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered)
devtmpfs on /dev type devtmpfs (rw,relatime,size=90860k,nr_inodes=22715,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /var/volatile type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
/dev/mmcblk1p4 on /mnt/mmc type ext3 (rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered)
/dev/mmcblk1p4 on /mnt/data type ext3 (rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered)
/dev/mmcblk1p4 on /home/log type ext3 (rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered)
繼續前進吧
echo -e "\ncheck point 4"
# ======================================================================
# | prepare '/tmp/etc/sysinfo.txt' and backup to '/mnt/data/sysinfo.txt'
# ======================================================================
UBOOT_ENV_VER=$(fw_printenv uboot_env_ver 2>/dev/null | awk -F"=" '{ print $2 }')
if [ "$UBOOT_ENV_VER" = "" ]; then
UBOOT_ENV_VER="NA"
fi
MAC=$(fw_printenv ethaddr 2>/dev/null | awk -F"=" '{ print $2 }')
if [ "$MAC" = "" ]; then
MAC="random"
fi
HW_MCSV=$(fw_printenv hw_mcsv 2>/dev/null | awk -F"=" '{ print $2 }')
if [ "$HW_MCSV" = "" ]; then
HW_MCSV=$(cat /mnt/data/sysinfo.txt | grep HW_MCSV | awk -F"=" '{ print $2 }')
if [ $? == 0 ]
then
fw_setenv hw_mcsv "$HW_MCSV"
else
HW_MCSV="012C000000000000"
fi
fi
SERIALNO=$(fw_printenv serialno 2>/dev/null | awk -F"=" '{ print $2 }')
if [ "$SERIALNO" = "" ]; then
SERIALNO=$(cat /mnt/data/sysinfo.txt | grep SERIALNO | awk -F"=" '{ print $2 }')
if [ $? == 0 ]
then
fw_setenv serialno "$SERIALNO"
else
SERIALNO="NA"
fi
fi
/bin/mkdir -p /tmp/etc
echo "UBOOT_ENV_VER"=$UBOOT_ENV_VER > /tmp/etc/sysinfo.txt
echo "MAC"=$MAC >> /tmp/etc/sysinfo.txt
echo "HW_MCSV"=$HW_MCSV >> /tmp/etc/sysinfo.txt
echo "SERIALNO"=$SERIALNO >> /tmp/etc/sysinfo.txt
# backup to '/mnt/data/sysinfo.txt'
cp /tmp/etc/sysinfo.txt /mnt/data/sysinfo.txt
echo -e "\ncheck point 5"
exit
開機訊息如下
2-1: new high-speed USB device number 2 using ci_hdrc
Running local boot scripts (/etc/rc.local)
check point 1
check point 2
check point 3
running image is b
check point 4
cat: can't open '/mnt/data/sysinfo.txt': No such file or directory
cat: can't open '/mnt/data/sysinfo.txt': No such file or directory
check point 5
.
m300e login:
看一下 /tmp/etc/sysinfo.txt
的內容
root@m300e:~# cat /tmp/etc/sysinfo.txt
UBOOT_ENV_VER=NA
MAC=random
HW_MCSV=
SERIALNO=
趁機解了一個 bug
check point 5 的路段修正如下
echo -e "\ncheck point 4"
# ======================================================================
# | prepare '/tmp/etc/sysinfo.txt' and backup to '/mnt/data/sysinfo.txt'
# ======================================================================
UBOOT_ENV_VER=$(fw_printenv uboot_env_ver 2>/dev/null | awk -F"=" '{ print $2 }')
if [ "$UBOOT_ENV_VER" = "" ]; then
UBOOT_ENV_VER="NA"
fi
MAC=$(fw_printenv ethaddr 2>/dev/null | awk -F"=" '{ print $2 }')
if [ "$MAC" = "" ]; then
MAC="random"
fi
HW_MCSV=$(fw_printenv hw_mcsv 2>/dev/null | awk -F"=" '{ print $2 }')
if [ "$HW_MCSV" = "" ]; then
HW_MCSV=$(cat /mnt/data/sysinfo.txt | grep HW_MCSV | awk -F"=" '{ print $2 }')
if [ "$HW_MCSV" = "" ]
then
HW_MCSV="012C000000000000"
else
fw_setenv hw_mcsv "$HW_MCSV"
fi
fi
SERIALNO=$(fw_printenv serialno 2>/dev/null | awk -F"=" '{ print $2 }')
if [ "$SERIALNO" = "" ]; then
SERIALNO=$(cat /mnt/data/sysinfo.txt | grep SERIALNO | awk -F"=" '{ print $2 }')
if [ "$SERIALNO" = "" ]
then
SERIALNO="NA"
else
fw_setenv serialno "$SERIALNO"
fi
fi
/bin/mkdir -p /tmp/etc
echo "UBOOT_ENV_VER"=$UBOOT_ENV_VER > /tmp/etc/sysinfo.txt
echo "MAC"=$MAC >> /tmp/etc/sysinfo.txt
echo "HW_MCSV"=$HW_MCSV >> /tmp/etc/sysinfo.txt
echo "SERIALNO"=$SERIALNO >> /tmp/etc/sysinfo.txt
# backup to '/mnt/data/sysinfo.txt'
cp /tmp/etc/sysinfo.txt /mnt/data/sysinfo.txt
echo -e "\ncheck point 5"
exit
在燒錄完成第一次的開機時
/tmp/etc/sysinfo.txt
的資訊如下
root@m300e:~# cat /tmp/etc/sysinfo.txt
UBOOT_ENV_VER=NA
MAC=random
HW_MCSV=012C000000000000
SERIALNO=NA
這才是我們要的初始值
/mnt/data/sysinfo.txt
只是個預防措施
因為之前有傳出設定 uboot env hw_mcsv
和 serialno
後消失的災情
我應該先在 develop branch 把這個改變套用上去
直接上了
commit d1babb1ca170a869064b0c66685bd40f23a4a163
Author: jeffrey <[email protected]>
Date: Thu Oct 26 13:45:33 2017 +0800
fix the problem about init the 'HW_MCSV' and 'SERIALNO'
- if there are no 'hw_mcsv' and 'serialno' value define in uboot env, give a default at 'rc.local'
- no concern about 'hw_mcsv' and 'serialno' in 'uboot_env.sh'
proscend/base_fs/default/rootfs/etc/rc.local | 14 ++++++--------
proscend/prosrc/icos/script/uboot_env.sh | 7 -------
2 files changed, 6 insertions(+), 15 deletions(-)
繼續往 check point 6 前進
echo -e "\ncheck point 5"
# ==========================================================================
# | mkdir /mnt/data/icos for icos data storage (/etc/icos)
# | mkdir /mnt/data/etc for other app data storage
# ==========================================================================
/bin/mkdir -p /mnt/data/icos
/bin/mkdir -p /mnt/data/etc
/sbin/ifconfig eth1 0.0.0.0
/sbin/ifconfig eth0 0.0.0.0
/usr/sbin/brctl addbr lan
/usr/sbin/brctl addif lan eth0
ifconfig lan 192.168.1.1
ifconfig lan up
ethaddr=$(fw_printenv ethaddr 2>/dev/null | awk -F"=" '{ print $2 }')
if [[ "$ethaddr" =~ ^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$ ]]; then
ifconfig eth0 hw ether $ethaddr
mac=$(printf "%d" 0x`echo $ethaddr | sed -e 's/://g'`)
mac=$(expr $mac + 1)
mac=$(printf "%012x" $mac | sed -e 's/../&:/g' -e 's/:$//')
ifconfig eth1 hw ether $mac
fi
# Support 2017/01/01 12:00:00 or 2017-01-01 12:00:00
sys_time=$(fw_printenv sys_time 2>/dev/null | awk -F"=" '{ print $2 }')
sys_time=$(echo $sys_time | sed -e "s/\//-/g")
if [ ! -z "$sys_time" ]; then
temp=$(date -s "$sys_time")
fw_setenv sys_time ""
fi
echo -e "\ncheck point 6"
exit
看來沒啥問題
Running local boot scripts (/etc/rc.local)
check point 1
check point 2
check point 3
running image is b
check point 4
check point 5
check point 6
.
m300e login:
基本的 interface 設定也有了
root@m300e:~# ifconfig
eth0 Link encap:Ethernet HWaddr 66:B9:ED:AE:89:33
inet6 addr: fe80::64b9:edff:feae:8933/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:1556 (1.5 KiB)
eth1 Link encap:Ethernet HWaddr 02:C8:CF:6D:00:2E
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lan Link encap:Ethernet HWaddr 66:B9:ED:AE:89:33
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::64b9:edff:feae:8933/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:738 (738.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
接下來往 check point 7
這一趟路途最為凶險
echo -e "\ncheck point 6"
# Ariel: icospromsg need to before icosconfig for share memory init
modprobe cryptodev
/usr/sbin/seqcmdd -C /run/seqcmdd/ipt_cmd &
/usr/sbin/icospromsg &
/usr/sbin/icosconfig bootinit
/usr/sbin/rs485 --enable > /dev/null 2>&1
/usr/sbin/read_modem &
/usr/sbin/icos/gpio_button.sh \
--click "reboot" \
--debounce 500 \
--time 5 \
--hold "heartbeat_all_led.sh; icosconfig reset ; reboot" \
--active-low 1 \
--hold-exit 5 0 &
# Ariel: make icos watch dog to be the last one.Max timeout is 128 seconds.
/usr/sbin/icoswdog -T 120 &
echo -e "\ncheck point 7"
exit
看來是有驚無險
Running local boot scripts (/etc/rc.local)
check point 1
check point 2
check point 3
running image is b
check point 4
check point 5
check point 6
### module <system> init
### module <syslog> init
### module <switch> init
### module <wanst> init
### module <lan> init
### module <dhcpc> init
### module <firewall> init
### module <firewall6> init
### module <urlfilter> init
### module <macfilter> init
### module <ipFilter> init
### module <dns> init
### module <cwmp> init
### module <web> init
### module <virtual-server> init
### module <nat> init
### module <dhcp> init
### module <rip> init
### module <sntp> init
### module <snmp> init
### module <ssh> init
### module <upnp> init
### module <ipsec> init
### module <pppoe_client> init
### module <ddns> init
### module <ipv6lan> init
### module <dhcp6c> init
### module <alarm> init
### module <lte> init
### module <com> init
### module <vcom> init
### module <openvpn> init
### module <netmon> init
### module <connmgr> init
### module <dmz> init
### module <wan_select> init
### module <cli> init
### module <lan_control> init
### module <modbus> init
### module <mqtt> init
### module <vrrp> init
### module <route> init
### module <zebra> init
### module <rip> init
### module <smtp> init
check point 7
.
M300-S-E login:
索性一次跑到底吧
echo -e "\ncheck point 7"
# ======================================================================
# | reset the uboot env no_good counter
# | we think our applicaion is good at this moment
# ======================================================================
# Replaced by wdog,John
# fw_setenv no_good .
# Ariel: start telnetd
telnetd &
# John: delay 1s to prevent the wdog infomation be treated as login name and password
sleep 1
echo -e "\ncheck point 8"
log 的寫入也沒問題
web page 也開起來了
目前發現我正在跑的都是 'rootfs_a'
uboot env 還需要好好整理一下
不然無法解釋目前遇到的靈異現象
目前要重現靈異現象的 SOP 如下
利用 env default -a
先將 uboot env 恢復成預設值
=> env default -a
## Resetting to default environment
利用 printenv
觀察 fdt_file
, image
與 mmcroot
=> printenv
fdt_file=imx6ul-14x14-evk.dtb
image=zImage
mmcroot=/dev/mmcblk1p2 rootwait rw
Environment size: 2045/8188 bytes
修改成要從 dual image b 開機的配置
setenv mmcroot /dev/mmcblk1p3 rootwait rw
setenv image zImage_b
setenv fdt_file imx6ul-14x14-evk_b.dtb
save
起來
=> save
Saving Environment to MMC...
Writing to MMC(1)... done
再利用 printenv
觀察 fdt_file
, image
與 mmcroot
=> printenv
fdt_file=imx6ul-14x14-evk_b.dtb
image=zImage_b
mmcroot=/dev/mmcblk1p3 rootwait rw
Environment size: 2049/8188 bytes
reset
=> reset
resetting ...
U-Boot 2015.04imx_v2015.04_4.1.15_1.2.0_ga+gede7538 (Sep 28 2017 - 03:21:56)
CPU: Freescale i.MX6UL rev1.2 at 396 MHz
CPU: Temperature 49 C
Reset cause: WDOG
Board: MX6UL 14x14 EVK
I2C: ready
DRAM: 512 MiB
MMC: FSL_SDHC: 0, FSL_SDHC: 1
Display: TFT43AB (480x272)
Video: 480x272x24
In: serial
Out: serial
Err: serial
switch to partitions #0, OK
mmc1(part 0) is current device
Net: FEC1
Error: FEC1 address not set.
Normal Boot
Hit any key to stop autoboot: 0
=>
再利用 printenv
觀察 fdt_file
, image
與 mmcroot
=> printenv
fdt_file=imx6ul-14x14-evk_b.dtb
image=zImage_b
mmcroot=/dev/mmcblk1p2 rootwait rw
Environment size: 2063/8188 bytes
發現 mmcroot
的值又跑回來了
事出必有因
請參考 u-boot-imx
的 source code
board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c
void board_late_mmc_init(void)
{
char cmd[32];
char mmcblk[32];
u32 dev_no = mmc_get_env_devno();
if (!check_mmc_autodetect())
return;
setenv_ulong("mmcdev", dev_no);
/* Set mmcblk env */
sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
mmc_map_to_kernel_blk(dev_no));
setenv("mmcroot", mmcblk);
sprintf(cmd, "mmc dev %d", dev_no);
run_command(cmd, 0);
}
就是這該死的 setenv("mmcroot", mmcblk)
會在 uboot init 時去寫 mmcroot
的值
mmcroot
真正影響到的是 bootargs
=> printenv mmcargs
mmcargs=setenv bootargs console=${console},${baudrate} root=${mmcroot}
只要 run mmcargs
就會產生 bootargs
這重要的 uboot env
因為這可是 uboot 傳遞參數給 linux 的方式
Starting kernel ...
Booting Linux on physical CPU 0x0
Linux version 4.1.15-1.2.0+g77f6154 (build@2f192722794e) (gcc version 5.2.0 (GCC) ) #2 SMP PREEMPT Thu Sep 28 07:53:27 UTC 2017
CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c53c7d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
Machine model: Freescale i.MX6 UltraLite 14x14 EVK Board
cma: Reserved 320 MiB at 0x8c000000
Memory policy: Data cache writealloc
PERCPU: Embedded 12 pages/cpu @8bb35000 s17216 r8192 d23744 u49152
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 130048
Kernel command line: console=ttymxc0,115200 root=/dev/mmcblk1p2 rootwait rw
...
參考的文件如下
我可以不去修改 board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c
也就是讓 bootargs
擺脫 mmcroot
的影響即可