20190703_jeffrey - silenceuncrio/diary GitHub Wiki
0840
繼續 M330 - feature/lighttpd
1000
目前 firmware upgrade 遇到怪現象
file upload 已經沒問題了就不予考慮
就以 /tmp/firmware.upload
已經存在為前提
root@M330:/tmp# ls -al /tmp/firmware.upload
-rw------- 1 root root 22348461 Jan 1 17:49 /tmp/firmware.upload
直接在 shell 下敲 command
root@M330:/tmp# /usr/sbin/icos/FirmwareUpgrade.sh /tmp/firmware.upload
UPGRADE_BIN is /tmp/firmware.upload ....
[main 841]mage_hdr(512)+firmware.md5(133)+mcsv.enc(40)+kernel.bin(1507328)+rootfs.bin(20840448)+uboot.bin(0) = 22348461
d47035bc372801fc6708619ab0a13103 mcsv.enc in firmware.md5(check ok)
c898fad29820882e48feb555e0a162bd kernel.bin in firmware.md5(check ok)
3d69876c896d7b351e56528e13b112c8 rootfs.bin in firmware.md5(check ok)
sw_mcsv = [014A00000022E8EE], hw_mcsv = [014A000000000000]
sw_mcsv_mmmm = [014A], hw_mcsv_mmmm = [014A]
sw_mcsv_cccc = [0000], hw_mcsv_cccc = [0000]
Unlocking /dev/mtd12 ...
Erasing /dev/mtd12 ...
Unlocking /dev/mtd6 ...
Unlocking /dev/mtd7 ...
current active_image[b]
write active_image (a) kernel_mtd->(/dev/mtd6) rootfs_mtd->(/dev/mtd7)
Writing from 'kernel.bin' to MTD '/dev/mtd6' ... [ok]
Writing from 'rootfs.bin' to MTD '/dev/mtd7' ... [ok]
順利做完
此時的 log - /tmp/FirmwareUpgrade.log
firmware upgrade shell script start...
Upgrading the firmware ...
Write the firmware image to MTD device ...
Write the firmware image to MTD device succeeded
Upgrading the firmware succeeded
firmware upgrade shell script succeeded
finished
finished
finished
改用 iweb 的 cgi 觸發 - http://192.168.1.1/cgi-bin/firmware.cgi?act=upgrade
相關的 process 如下
root@M330:/tmp# ps
PID USER VSZ STAT COMMAND
30955 root 1844 S {FirmwareUpgrade} /bin/bash /usr/sbin/icos/FirmwareU
30986 root 22880 D mtd writeimage /tmp/firmware.upload
log - /tmp/FirmwareUpgrade.log
如下
firmware upgrade shell script start...
Upgrading the firmware ...
Write the firmware image to MTD device ...
Write the firmware image to MTD device succeeded
Upgrading the firmware succeeded
firmware upgrade shell script succeeded
finished
finished
finished
不過如果從 lighttpd 的 cgi 觸發 - http://192.168.1.1:3000/cgi-bin/firmware.cgi?act=upgrade
馬上敲 ps 並沒有看到相關的 process - 也許瞬間就以失敗告終了
log - /tmp/FirmwareUpgrade.log
如下
root@M330:/tmp# cat FirmwareUpgrade.log
firmware upgrade shell script start...
Upgrading the firmware ...
Write the firmware image to MTD device ...
Write the firmware image to MTD device failed
1015
目前 CGI 的寫法如下
static void _upgrade()
{
char cmd[256];
pid_t pid;
pid = fork();
if (pid != 0)
{
jweb.out.json.ok();
}
fclose (stdin);
fclose (stdout);
sprintf(cmd, "/usr/sbin/icos/FirmwareUpgrade.sh /tmp/firmware.upload &");
system(cmd);
cgiFree (cgi);
exit(0);
}
1045
CGI 改用以下更單純的方式也一樣
static void _upgrade()
{
char cmd[256];
sprintf(cmd, "/usr/sbin/icos/FirmwareUpgrade.sh /tmp/firmware.upload");
system(cmd);
jweb.out.json.ok();
}
1050
CGI 改成最原始的去呼叫 mtd writeimage /tmp/firmware.upload
static void _upgrade()
{
system("mtd writeimage /tmp/firmware.upload");
jweb.out.json.ok();
}
iweb 可以
lighttpd 還是不行
難道又是 mtd 沒給 full path 的問題
CGI 改成以下
static void _upgrade()
{
system("/sbin/mtd writeimage /tmp/firmware.upload");
jweb.out.json.ok();
}
iweb 可以
lighttpd 也可以了
1100
修改 FirmwareUpgrade.sh
diff --git a/proscend/prosrc/icos/script/FirmwareUpgrade.sh b/proscend/prosrc/icos/script/FirmwareUpgrade.sh
index a352499..d87a231 100755
--- a/proscend/prosrc/icos/script/FirmwareUpgrade.sh
+++ b/proscend/prosrc/icos/script/FirmwareUpgrade.sh
@@ -255,7 +255,7 @@ function write_to_mtd {
log "\nWrite the firmware image to MTD device ..."
progress_status "Write the firmware image to MTD device ..."
- mtd write "$UPGRADE_BIN" "$UPGRADE_DEV"
+ /sbin/mtd write "$UPGRADE_BIN" "$UPGRADE_DEV"
log "Write the firmware image to MTD device succeeded"
progress_status "Write the firmware image to MTD device succeeded"
@@ -281,7 +281,7 @@ function write_image_to_mtd {
log "\nWrite the firmware image to MTD device ..."
progress_status "Write the firmware image to MTD device ..."
- mtd writeimage "$UPGRADE_BIN"
+ /sbin/mtd writeimage "$UPGRADE_BIN"
case $? in
0)
log "Write the firmware image to MTD device succeeded"
還原 firmware.cgi
1130
firmware upgrade 終於成功了
有驚無險
其實問題之前都遇過
只是並無法第一眼就看到問題的現象
而是被其他的現象蓋住了
耐心 謙虛 真的是王道
雖然很苦
整理一下方便 commit
記得要在 commit log 提醒自己 lighttpd config-file 裡要有 server.upload-dirs = ( "/tmp" )
不然超過 64KB 的 file 在 upload 時會得到 lighttpd 413 - Request Entity Too Large
的回應
1325
M330 - feature/lighttpd - 'Management > Firmware'
commit 69f7ac20f5748be66f17b2f676eeac03272a733c
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date: Wed Jul 3 13:23:42 2019 +0800
feature/lighttpd - 'Management > Firmware'
api.cgi
- jweb.api.upload_file(UPLOAD_PATH_FIRMWARE);
firmware.cgi
- jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _upgrade);
- jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _progress);
- jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);
icos_config.cgi
- jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _coldreboot);
- jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _load_factory_and_reboot);
- jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);
at firmware.cgi, use the full path '/usr/sbin/icos/FirmwareProgress.sh' instead of 'FirmwareProgress.sh'
at FirmwareProgress.sh, no echo at progress_update() or http header will be a problem
at FirmwareUpgrade.sh, use the full path `/sin/mtd` instead of 'mtd'
offer CGI for firmware upload - POST /cgi-bin/api/cgi?act=firmwareUpload
- lighttpd rewrite will rewrite `/api/firmwareUpload` to `/cgi-bin/api/cgi?act=firmwareUpload`
- jweb need further handle when REQUEST_METHOD="POST" and QUERY_STRING="act=firmwareUpload"
- cgilib parse QUERY_STRING only when REQUEST_METHOD="GET"
at reboot page, use 'cgi-bin/icos_config.cgi?act=help' as the resolver of angular routeProvider
- make sure user have been login
note that in the config-file for lighttpd, we need put `server.upload-dirs = ( "/tmp" )`,
or upload file with size more than 64KB will get 413 - `Request Entity Too Large` from lighttpd
proscend/prosrc/icos/script/FirmwareProgress.sh | 2 +-
proscend/prosrc/icos/script/FirmwareUpgrade.sh | 4 +-
proscend/prosrc/webcgi/api.c | 4 ++
proscend/prosrc/webcgi/firmware.c | 10 ++--
proscend/prosrc/webcgi/icos_config.c | 8 +--
proscend/prosrc/webcgi/jweb.c | 75 ++++++++++++++++++++++--
proscend/prosrc/webcgi/jweb.h | 22 +++++++
proscend/prosrc/www/app/feature/reboot.js | 11 +++-
proscend/prosrc/www/app/services/icos.service.js | 3 +
9 files changed, 121 insertions(+), 18 deletions(-)
reboot 之後須手動啟動 lighttpd
搭配 tftp 使用的紀錄如下
root@M330:~# cp -r /www/ /tmp/
root@M330:~# cd /tmp/
root@M330:/tmp# tftp -g -r lighttpd.conf 192.168.1.113
root@M330:/tmp# tftp -g -r web_x509_lighttpd.sh 192.168.1.113
root@M330:/tmp# chmod 755 web_x509_lighttpd.sh
root@M330:/tmp# ./web_x509_lighttpd.sh
Generating a 2048 bit RSA private key
................................................+++
..............................................................+++
writing new private key to '/tmp/icos/web/lighttpd.pem'
-----
root@M330:/tmp# lighttpd -f /tmp/lighttpd.conf
root@M330:/tmp# 1970-01-01 01:56:59: (log.c.166) server started
root@M330:/tmp#
目前的 lighttpd.conf
server.document-root = "/tmp/www/"
server.bind = "0.0.0.0"
server.port = 3000
$SERVER["socket"] == "[::]:3000" { }
$SERVER["socket"] == "0.0.0.0:3443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/icos/web/lighttpd.pem"
}
$SERVER["socket"] == "[::]:3443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/icos/web/lighttpd.pem"
}
server.modules = ( "mod_rewrite", "mod_cgi" )
index-file.names = ( "index.html" )
mimetype.assign = (
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".txt" => "text/plain",
)
cgi.assign = ( ".cgi" => "" )
url.rewrite = (
"^/api/([a-zA-Z]+)[0-9a-zA-Z=.?]*$" => "/cgi-bin/api.cgi?act=$1",
)
server.upload-dirs = ( "/tmp" )
M330 - feature/lighttpd - 'Management > Configuartion'
commit 2f389804b216602fe03a840ce32b3d002df1c717
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date: Wed Jul 3 14:20:26 2019 +0800
feature/lighttpd - 'Management > Configuartion'
api.cgi
- jweb.api.upload_file(UPLOAD_PATH_CONFIGURATION);
offer CGI for configuration upload - POST /cgi-bin/api/cgi?act=configurationUpload
- lighttpd rewrite will rewrite `/api/configurationUpload` to `/cgi-bin/api/cgi?act=configurationUpload`
- jweb need further handle when REQUEST_METHOD="POST" and QUERY_STRING="act=configurationUpload"
- cgilib parse QUERY_STRING only when REQUEST_METHOD="GET"
proscend/prosrc/webcgi/api.c | 4 ++++
1 file changed, 4 insertions(+)
M330 - feature/lighttpd - 'Management > Load Factory'
commit 3f2681a489181278d1600c2f98adc59f5bdc8468
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date: Wed Jul 3 14:27:14 2019 +0800
feature/lighttpd - 'Management > Load Factory'
- use 'cgi-bin/configuration.cgi?act=help' as the resolver of angular routeProvider
- make sure user have been login
proscend/prosrc/www/app/feature/factory_and_reboot.js | 13 +++++++++++--
proscend/prosrc/www/app/feature/load_factory.js | 11 ++++++++++-
2 files changed, 21 insertions(+), 3 deletions(-)
M330 - feature/lighttpd - 'Management > Restart'
commit 785aff60cf0f4df1e31bddb36bc2cec9a2cd777a
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date: Wed Jul 3 14:30:49 2019 +0800
feature/lighttpd - 'Management > Restart'
- use 'cgi-bin/configuration.cgi?act=help' as the resolver of angular routeProvider
- make sure user have been login
proscend/prosrc/www/app/feature/restart.js | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
M330 - feature/lighttpd - 'Management > Schedule Reboot'
commit feb72ba111114bcadd3938b4d8271df69a82b36f
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date: Wed Jul 3 14:47:16 2019 +0800
feature/lighttpd - 'Management > Schedule Reboot'
schedule_reboot.cgi
- jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
- jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
- jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);
proscend/prosrc/webcgi/schedule_reboot.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
1455
以 web ui menu 為主已經掃過一次
再以 M300 - feature/lighttpd 的 commit 紀錄為輔盤一下還有什麼
M330 - feature/lighttpd - offer CGI for upload
commit 2bad551cdcdb9c692a93f0e52f8b890b846daf51
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date: Wed Jul 3 14:52:37 2019 +0800
feature/lighttpd - offer CGI for upload
- openvpnUpload - POST /cgi-bin/api/cgi?act=openvpnUpload
- before rewrite - /api/openvpnUpload
- jweb need further handle when REQUEST_METHOD="POST" and QUERY_STRING="act=openvpnUpload"
- ipsecUpload - POST /cgi-bin/api/cgi?act=ipsecUpload
- before rewrite - /api/ipsecUpload
- jweb need further handle when REQUEST_METHOD="POST" and QUERY_STRING="act=ipsecUpload"
proscend/prosrc/webcgi/api.c | 8 ++++++++
1 file changed, 8 insertions(+)
再來就是 icos module 了
一樣是參考 M300 的作法
1520
M360 克服掉 bad block 的問題的版本已經 release 了
利用手上這兩片有 bad block 的板子
已經確認該版本的確克服了 bad block 的問題
趕緊將 firmware mail 給 mistrastar 相關人士
1715
看到 M330 的以下兩個用來作 firmware upgrade 的 shell script
- m330/proscend/prosrc/icos/script/FirmwareUpgrade.sh
- m330/proscend/prosrc/icos/script/FirmwareProgress.sh
FirmwareUpgrade.sh
透過 cgi 呼叫一次就開始做事 - 兩分鐘以上吧
FirmwareProgress.sh
也是透過 cgi 呼叫
不過是在呼叫完 FirmwareUpgrade.sh
後
才會頻繁的呼叫
目的是要知道 firmware upgrade 目前的狀態來達成 ui 上的進度展示
這兩個 shell script 都會去讀寫同一個 file - /tmp/FirmwareUpgrade.progress.json
神奇的是
FirmwareProgress.sh
有對該 file 的讀寫動作作類似 mutex 的保護
#!/bin/bash
# firmware progress shell script
TMP=/tmp/FirmwareProgress.tmp
PROGRESS=/tmp/FirmwareUpgrade.progress.json
...
PROGRESS_MUTEX=/tmp/FirmwareUpgrade.progress.mutex
function progress_mutex_lock_wait {
while true
do
if mkdir "$PROGRESS_MUTEX" 2>/dev/null
then
return
fi
done
}
function progress_mutex_unlock {
rmdir "$PROGRESS_MUTEX"
}
# update the status for the firmware upgrade progress
# use jq - command-line JSON processor
function progress_update {
filter=.$CURR_TIME=\"$(cut -f 1 -d ' ' /proc/uptime)\"
# echo $filter
progress_mutex_lock_wait
cat $PROGRESS | jq "$filter" > $TMP
mv $TMP $PROGRESS
progress_mutex_unlock
}
但 FirmwareUpgrade.sh
卻沒有
以下為例
function write_image_to_mtd {
log "\nWrite the firmware image to MTD device ..."
progress_status "Write the firmware image to MTD device ..."
/sbin/mtd writeimage "$UPGRADE_BIN"
case $? in
0)
log "Write the firmware image to MTD device succeeded"
progress_status "Write the firmware image to MTD device succeeded"
;;
1)
log "Error: Write the firmware image to MTD device failed"
progress_fail "Write the firmware image to MTD device failed"
exit 1
;;
...
*)
log "Write the firmware image to MTD device failed"
progress_fail "Write the firmware image to MTD device failed"
exit 1
esac
}
progress_status
或 progress_fail
都有可能會失敗
1745
作以下修改
diff --git a/proscend/prosrc/icos/script/FirmwareUpgrade.sh b/proscend/prosrc/icos/script/FirmwareUpgrade.sh
old mode 100755
new mode 100644
index dea26d5..88b6182
--- a/proscend/prosrc/icos/script/FirmwareUpgrade.sh
+++ b/proscend/prosrc/icos/script/FirmwareUpgrade.sh
@@ -50,6 +50,27 @@ function log {
+PROGRESS_MUTEX=/tmp/FirmwareUpgrade.progress.mutex
+
+function progress_mutex_lock_wait {
+ while true
+ do
+ if mkdir "$PROGRESS_MUTEX" 2>/dev/null
+ then
+ return
+ fi
+ done
+}
+
+function progress_mutex_unlock {
+ rmdir "$PROGRESS_MUTEX"
+}
+
+
+
+
+
+
# init the information of the firmware upgrade progress
# use json format
function progress_init {
@@ -63,20 +84,35 @@ function progress_init {
function progress_status {
filter=".status=\"$1\""
+
+ progress_mutex_lock_wait
+
cat $PROGRESS | jq "$filter" > $TMP
mv $TMP $PROGRESS
+
+ progress_mutex_unlock
}
function progress_fail {
filter=".state=\"$STATE_FAIL\" | .status=\"$1\""
+
+ progress_mutex_lock_wait
+
cat $PROGRESS | jq "$filter" > $TMP
mv $TMP $PROGRESS
+
+ progress_mutex_unlock
}
function progress_ok {
filter=".state=\"$STATE_OK\" | .status=\"$1\""
+
+ progress_mutex_lock_wait
+
cat $PROGRESS | jq "$filter" > $TMP
mv $TMP $PROGRESS
+
+ progress_mutex_unlock
}
使用 web ui 作 firmware upgrade 觀察
第一次成功
明天繼續多作個幾次
確認沒任何副作用之後再 commit