20170206_jeffrey - silenceuncrio/diary GitHub Wiki
- 0920 - review
-
1140 - 目前
FirmwareUpgrade.sh
如下 -
1300 - 再來要套 proscend 既有的
MCSV Upgrade Rule
-
1415 - 看來有必要調整一下
FirmwareUpgrade.sh
輸出 log 的方式 -
1425 - 目前考慮的方案是採用
jq
這個工具 -
1800 - 明天要好好地來整理一下
FirmwareUpgrade.sh
review
上禮拜為了 檔案的完整性檢查
修改了 FirmwareUpgrade.sh
...
if [ -e "/tmp/firmware/firmware.md5" ]
then
cd /tmp/firmware
if md5sum -c firmware.md5
then
cd -
echo "md5sum -c firmware.md5 succeeded" >> /tmp/FirmwareUpgrade.log
exit 1
else
echo "md5sum -c firmware.md5 failed" >> /tmp/FirmwareUpgrade.log
exit 1
fi
else
echo "no need to do md5sum" >> /tmp/FirmwareUpgrade.log
exit 1
fi
...
繼續 比對 MCSV 資訊
的部分
目前 FirmwareUpgrade.sh
如下
#!/bin/bash
# firmware upgrade shell script
echo "firmware upgrade shell script start..." > /tmp/FirmwareUpgrade.log
if [ -n "$1" ]
then
echo "Extract all files from $1" >> /tmp/FirmwareUpgrade.log
# if tar -C /tmp -xf $1
# then
# echo "tar -C /tmp -xf $1 succeeded" >> /tmp/FirmwareUpgrade.log
# else
# echo "tar -C /tmp -xf $1 failed" >> /tmp/FirmwareUpgrade.log
# echo "finished" >> /tmp/FirmwareUpgrade.log
# exit 1
# fi
else
echo "Please offer the firmware" >> /tmp/FirmwareUpgrade.log
echo "finished" >> /tmp/FirmwareUpgrade.log
exit 1
fi
cd /tmp/firmware
echo -e "\nMD5 sums check..." >> /tmp/FirmwareUpgrade.log
if [ -e "firmware.md5" ]
then
echo "firmware.md5 exit, read MD5 sums from it and check them" >> /tmp/FirmwareUpgrade.log
md5sum -c firmware.md5
if [ $? == 0 ]; then
echo "MD5 sums check succeeded" >> /tmp/FirmwareUpgrade.log
else
echo "MD5 sums check failed" >> /tmp/FirmwareUpgrade.log
exit 1
fi
else
echo "firmware.md5 not exit, bypass the MD5 sums check" >> /tmp/FirmwareUpgrade.log
fi
echo -e "\nMCSV check..." >> /tmp/FirmwareUpgrade.log
if [ -e "mcsv.enc" ]
then
echo "mcsv.enc exit, decrypt it and check with hardware MCSV" >> /tmp/FirmwareUpgrade.log
echo "decrypt mcsv.en" >> /tmp/FirmwareUpgrade.log
openssl des3 -d -salt -in mcsv.enc -out mcsv -k 2wsx#EDC
if [ $? != 0 ]; then
echo "decrypt mcsv.enc failed" >> /tmp/FirmwareUpgrade.log
exit 1
fi
sw_mcsv=$(cat mcsv)
echo "software MCSV: ${sw_mcsv}"
sw_mcsv_mmmm=$(echo ${sw_mcsv} | cut -c 1-4)
echo "software MCSV-MMMM: ${sw_mcsv_mmmm}"
sw_mcsv_cccc=$(echo ${sw_mcsv} | cut -c 5-8)
echo "software MCSV-CCCC: ${sw_mcsv_cccc}"
hw_mcsv=$(cat /tmp/etc/sysinfo.txt | grep HW_MCSV | cut -c 9-24)
if [ -z "${hw_mcsv}" ]; then
echo "hw_mcsv not exit, MCSV check failed" >> /tmp/FirmwareUpgrade.log
exit 1
fi
echo "hardware MCSV: ${hw_mcsv}"
hw_mcsv_mmmm=$(echo ${hw_mcsv} | cut -c 1-4)
echo "hardware MCSV-MMMM: ${hw_mcsv_mmmm}"
hw_mcsv_cccc=$(echo ${hw_mcsv} | cut -c 5-8)
echo "hardware MCSV-CCCC: ${hw_mcsv_cccc}"
else
echo "mcsv.enc not exit, bypass MCSV check" >> /tmp/FirmwareUpgrade.log
fi
cd -
exit 1
...
再來要套 proscend 既有的 MCSV Upgrade Rule
- Reject if the Upgrade Image with different Model ID with HW MCSV
- If HW MCSV’s and SW MCSV’s custom ID=0000/0001 (i.e. Proscend)
- allow to upgrade the image with all custom ID
- If HW MCSV’s custom ID=0000/0001 (i.e. Proscend) and SW MCSV’s custom ID!=0000/0001
- allow upgrade the image with the same CID as SW MCSV’s CID
- reject other mcsv
- If HW MCSV’s CID!=0000/0001 (i.e. Proscend)
- reject the upgrade image with different CID
目前 FirmwareUpgrade.sh
如下
#!/bin/bash
# firmware upgrade shell script
echo "firmware upgrade shell script start..." > /tmp/FirmwareUpgrade.log
if [ -n "$1" ]
then
echo "Extract all files from $1" >> /tmp/FirmwareUpgrade.log
# if tar -C /tmp -xf $1
# then
# echo "tar -C /tmp -xf $1 succeeded" >> /tmp/FirmwareUpgrade.log
# else
# echo "tar -C /tmp -xf $1 failed" >> /tmp/FirmwareUpgrade.log
# echo "finished" >> /tmp/FirmwareUpgrade.log
# exit 1
# fi
else
echo "Please offer the firmware" >> /tmp/FirmwareUpgrade.log
echo "finished" >> /tmp/FirmwareUpgrade.log
exit 1
fi
cd /tmp/firmware
echo -e "\nMD5 sums check..." >> /tmp/FirmwareUpgrade.log
if [ -e "firmware.md5" ]
then
echo "firmware.md5 exit, read MD5 sums from it and check them" >> /tmp/FirmwareUpgrade.log
md5sum -c firmware.md5
if [ $? == 0 ]; then
echo "MD5 sums check succeeded" >> /tmp/FirmwareUpgrade.log
else
echo "MD5 sums check failed" >> /tmp/FirmwareUpgrade.log
exit 1
fi
else
echo "firmware.md5 not exit, bypass the MD5 sums check" >> /tmp/FirmwareUpgrade.log
fi
echo -e "\nMCSV check..." >> /tmp/FirmwareUpgrade.log
if [ -e "mcsv.enc" ]
then
echo "mcsv.enc exit, decrypt it and check with hardware MCSV" >> /tmp/FirmwareUpgrade.log
echo "decrypt mcsv.en" >> /tmp/FirmwareUpgrade.log
openssl des3 -d -salt -in mcsv.enc -out mcsv -k 2wsx#EDC
if [ $? != 0 ]; then
echo "decrypt mcsv.enc failed" >> /tmp/FirmwareUpgrade.log
exit 1
fi
sw_mcsv=$(cat mcsv)
echo "software MCSV: ${sw_mcsv}" >> /tmp/FirmwareUpgrade.log
sw_mcsv_mmmm=$(echo ${sw_mcsv} | cut -c 1-4)
echo "software MCSV-MMMM: ${sw_mcsv_mmmm}" >> /tmp/FirmwareUpgrade.log
sw_mcsv_cccc=$(echo ${sw_mcsv} | cut -c 5-8)
echo "software MCSV-CCCC: ${sw_mcsv_cccc}" >> /tmp/FirmwareUpgrade.log
hw_mcsv=$(cat /tmp/etc/sysinfo.txt | grep HW_MCSV | cut -c 9-24)
if [ -z "${hw_mcsv}" ]; then
echo "hw_mcsv not exit, MCSV check failed" >> /tmp/FirmwareUpgrade.log
exit 1
fi
echo "hardware MCSV: ${hw_mcsv}" >> /tmp/FirmwareUpgrade.log
hw_mcsv_mmmm=$(echo ${hw_mcsv} | cut -c 1-4)
echo "hardware MCSV-MMMM: ${hw_mcsv_mmmm}" >> /tmp/FirmwareUpgrade.log
hw_mcsv_cccc=$(echo ${hw_mcsv} | cut -c 5-8)
echo "hardware MCSV-CCCC: ${hw_mcsv_cccc}" >> /tmp/FirmwareUpgrade.log
# Reject if the Upgrade Image with different Model ID with HW MCSV
if [ "${sw_mcsv_mmmm}" != "${hw_mcsv_mmmm}" ]; then
echo "Model ID not match, MCSV check failed" >> /tmp/FirmwareUpgrade.log
exit 1
fi
# - If HW MCSV’s and SW MCSV’s custom ID=0000/0001 (i.e. Proscend)
# - allow to upgrade the image with all custom ID
# - If HW MCSV’s custom ID=0000/0001 (i.e. Proscend) and SW MCSV’s custom ID!=0000/0001
# - allow upgrade the image with the same CID as SW MCSV’s CID
# - reject other mcsv
# - If HW MCSV’s CID!=0000/0001 (i.e. Proscend)
# - reject the upgrade image with different CID
if [ "${hw_mcsv_cccc}" == "0000" ] || [ "${hw_mcsv_cccc}" == "0001" ]
then
echo "Hardware customer ID is '0000' or '0001'" >> /tmp/FirmwareUpgrade.log
if [ "${sw_mcsv_cccc}" == "0000" ] || [ "${sw_mcsv_cccc}" == "0001" ]
then
echo "Software Customer ID is '0000' or '0001'" >> /tmp/FirmwareUpgrade.log
echo "allow to upgrade" >> /tmp/FirmwareUpgrade.log
else
echo "Software Customer ID is not '0000' or '0001'" >> /tmp/FirmwareUpgrade.log
echo "Allow to upgrade" >> /tmp/FirmwareUpgrade.log
echo "Reject other Customer ID" >> /tmp/FirmwareUpgrade.log
fw_setenv hw_mcsv ${sw_mcsv}
fi
else
echo "Hardware customer ID is not '0000' or '0001'" >> /tmp/FirmwareUpgrade.log
if [ "${sw_mcsv_cccc}" != "${hw_mcsv_cccc}" ]; then
echo "Customer ID not match, MCSV check failed" >> /tmp/FirmwareUpgrade.log
exit 1
fi
fi
else
echo "mcsv.enc not exit, bypass MCSV check" >> /tmp/FirmwareUpgrade.log
fi
cd -
...
假設 MCSV check failed 的情況
/tmp/FirmwareUpgrade.log
的內容如下
root@Mobile Router:/tmp/images# cat /tmp/FirmwareUpgrade.log
firmware upgrade shell script start...
Extract all files from m300.tar
MD5 sums check...
firmware.md5 exit, read MD5 sums from it and check them
MD5 sums check succeeded
MCSV check...
mcsv.enc exit, decrypt it and check with hardware MCSV
decrypt mcsv.en
software MCSV: 012C0088001298DA
software MCSV-MMMM: 012C
software MCSV-CCCC: 0088
hardware MCSV: 012C008956789012
hardware MCSV-MMMM: 012C
hardware MCSV-CCCC: 0089
Hardware customer ID is not '0000' or '0001'
Customer ID not match, MCSV check failed
目前網頁端 firmware.js
必須去 parser 整個 /tmp/FirmwareUpgrade.log
的內容來判斷 firmware upgrade 的狀況
function firmwareController($scope, $timeout, $location, icos, Upload) {
var vm = this;
vm.progress = "";
/*
- Firmware Upload - 12
- Firmware Upgrade Progress Start - 15
- Burn the kernel to NAND - 18
- Burn the rootfs to NAND - 21
- Writting rootfs - 84
- Unmount - 96
- finished - 100
*/
vm.progress_valuenow = 0;
vm.progress_css = "progress-bar progress-bar-info";
vm.progress_ing = false;
vm.progress_summary = "";
vm.upgrade = function(_file) {
if (_file) {
var data = {};
data._file = _file;
console.log("vm.upgrade()");
vm.progress = "Firmware Upload...";
vm.progress_summary = "Firmware Upload... Please wait";
vm.progress_ing = true;
vm.progress_valuenow = 3;
Upload.upload({ url: 'api/firmwareUpload', data: data })
.then(function(resp) {
vm.progress = resp.data.info;
return icos.firmware.upgrade();
})
.then(function(resp) {
vm.progress = "Firmware Upgrade Progress Start...";
vm.progress_summary = "Firmware Upgrade Progress Start";
vm.progress_valuenow = 12;
vm.timeout_3sec();
});
}
}
var timer_3sec;
var _progress_valuenow = 0;
vm.timeout_3sec = function () {
timer_3sec = $timeout(3000);
timer_3sec.then(function () {
icos.firmware.progress()
.then(function(response) {
vm.progress = response.data.progress.content;
if (vm.progress.indexOf('finished') != -1) {
vm.progress_ing = false;
if (vm.progress.indexOf('failed') == -1) {
vm.progress_valuenow = 100;
vm.progress_summary = "Success";
vm.progress_css = "progress-bar progress-bar-success";
} else {
vm.progress_summary = "Failed";
vm.progress_css = "progress-bar progress-bar-danger";
}
} else {
if (vm.progress.indexOf('Burn the kernel to NAND') != -1) {
if (_progress_valuenow < 15) {
_progress_valuenow = 15;
vm.progress_summary = "Burn the kernel to NAND";
}
}
if (vm.progress.indexOf('Burn the rootfs to NAND') != -1) {
if (_progress_valuenow < 18) {
_progress_valuenow = 18;
vm.progress_summary = "Burn the rootfs to NAND";
}
}
if (vm.progress.indexOf('Writting rootfs') != -1) {
if (_progress_valuenow < 84) {
_progress_valuenow += 3;
vm.progress_summary = "Writting rootfs";
}
}
if (vm.progress.indexOf('Unmount') != -1) {
if (_progress_valuenow < 99) {
_progress_valuenow += 3;
vm.progress_summary = "Unmount";
}
}
vm.progress_valuenow = _progress_valuenow;
vm.timeout_3sec();
}
});
});
}
...
}
看來有必要調整一下 FirmwareUpgrade.sh
輸出 log 的方式
不然 firmware.js
會越來越難維護
目前考慮的方案是採用 jq
這個工具
root@Mobile Router:/tmp/images# jq --help
jq - commandline JSON processor [version ]
Usage: jq [options] <jq filter> [file...]
For a description of the command line options and
how to write jq filters (and why you might want to)
see the jq manpage, or the online documentation at
http://stedolan.github.com/jq
FirmwareUpgrade.sh
利用 jq
來輸出 json 格式的 log
firmware.js
直接讀取到一個 json 格式的內容... 完全不需要再 parser
明天要好好地來整理一下 FirmwareUpgrade.sh
就算是 shell script 也要寫一些 function 來 refactoring 一下