2024年3月24日星期日

使用 lsblk 印出 emmc 每個 partition的"名字"與"size"

使用以下的command可以印出 eMMC的 partition資訊

lsblk --bytes --output name,partlabel,size 

參數說明
--bytes: partition的大小,以byte的方式輸出
--output: 後面可以指定要輸出的內容,我們可以先使用 --output-a 看看有哪資訊可以顯示


實際印出,如下圖






2024年2月29日星期四

在Yocto Project中,在還沒建立 rootfs的 image之前,刪除一些rootfs當中的 Library

 今天遇到一個問題,因為 gstreamer 執行時間過長,此過長的原因,是因為Library開啟太多

 另外不太了解 gstreamer 哪個Library是對應到哪個 plug-in(Package)

 所以打算用刪除 rootfs當中的 Library方式,來解決此問題


先找到下面這個檔案
meta/poky/meta/classes/rootfs-postcommands.bbclass

然後你可以發現,這個bbclass檔案,是被下面的檔案引用的
meta/poky/meta/classes/image.bbclass


接著就去修改,rootfs-postcommands.bbclass,加入以下內容
修改的重點就是,
1. 刪除想刪的檔案,這邊提一下,檔案中的變數 ${IMAGE_ROOTFS},會指到mtk-core-image-tiny/1.0-r0/rootfs/,並非我們要刪除的rootfs的路徑,因此這邊我們需要確定並改為指到 mtk-image-2735/1.0-r0/rootfs/
2. 必須確保刪除的檔案有存在,不然Yocto就會 build error,所以我們會加入check function,如果檔案存在,我們才做remove


最後加入以下內容,Device flash image之後,可以看到 /usr/lib64/gstreamer-1.0/ 路徑底下的 Library,該刪的都刪掉了!


### For resolving the gstreamer issue
ROOTFS_POSTPROCESS_COMMAND += "remove_gstreamer_lib ;"


# Remove gstreamer check
remove_file_if_exists() {
    local file_path="$1"
    if [ -f "$file_path" ]; then  # -e: if file_path exist, will return TRUE
        rm "$file_path"
        echo "Removed: $file_path"
    else
        echo "File does not exist: $file_path"
    fi
}


## ${IMAGE_ROOTFS} is apps/build/tmp/work/auto2735evb_ivt_vp2-poky-linux/mtk-core-image-tiny/1.0-r0/rootfs/

## But the real locate of the library is in apps/build/tmp/work/auto2735evb_ivt_vp2-poky-linux/mtk-image-2735/1.0-r0/rootfs/

# Remove gstreamer library

remove_gstreamer_lib () {
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgsta52dec.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstaccurip.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstadder.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstadpcmdec.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstadpcmenc.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstaiff.so"
}


這邊列出網路找到的一些資料
Ref: https://embeddedguruji.blogspot.com/2019/03/run-commands-after-rootfs-creation-in.html 

2023年12月26日星期二

[shell script] 計算執行時間的一個example

 #!/bin/sh

start=$(date +%s)

#The thing you want to do
echo "testing the echo duration"
sleep 3

end=$(date +%s)
duration=$(( end - start ))
echo "The total excution time is ${duration} seconds."

最後會印出執行的秒數,如下圖:







Yocto 修改 recipe (bb檔),遇到 QA Issue,編譯失敗 (以NXP9098為例)

今天我想要新增幾個檔案,到root-filesystem當中

於是我在recipe (xxx.bb)的 do_install 裡面加了以下幾行 (綠色字體)

詳細說明:
我想把兩個檔案,regulatory.db 與 regulatory.db.p7s 放到 rootfs 裡面的 /llib/firmware/ 底下
於是我就增加三行

install -d ${D}/lib/firmware

install -m 0644 ${B}/regulatory.db ${D}/lib/firmware/regulatory.db
install -m 0644 ${B}/regulatory.db.p7s ${D}/lib/firmware/regulatory.db.p7s










然後進行編譯,結果出現以下的錯誤訊息(QA Issue)

ERROR: nxp9098-fw-1.0-r0 do_package: QA Issue: nxp9098-fw: Files/directories were installed but not shipped in any package: /lib/firmware/regulatory.db.p7s /lib/firmware/regulatory.dbPlease set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install. nxp9098-fw: 2 installed and not shipped files. [installed-vs-shipped]

如下圖:





這種錯誤是因為,你install了這些檔案,到root-filesystem,但是你沒把這些檔案一起包到他的package裡面造成的,所以解決方法是,在把這幾個檔案加到FILES_${PN},就可以順利編譯成功了!

因此你需要再加入這兩行到 FILES_${PN},如下圖:
















如果遇到的錯誤訊息為:
File 'xxx.bin' was already stripped, this will prevent future debugging! [already-stripped]
ERROR: xxx do_package: QA Issue: xxx: Files/directories were installed but not shipped in any package:

Solution:
加入下面這一行,可以解決
INSANE_SKIP_${PN} += "already-stripped"

2023年12月5日星期二

如何在chroot當中,reboot 或是 shutdown 你的裝置 (/proc/sysrq-trigger 的用法)

 今天有個需求,是必須在chroot當中,執行 power-off

想當然爾,第一個想到的是使用 shutdown now

於是馬上把shutdown 這個指令,移植到 chroot,執行後出現以下的訊息,但無法 poweroff

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Failed to talk to init daemon

另外也試過,在chroot當中使用 kill -9 1 ,沒有出現錯誤訊息,但是一樣沒作用
(有在chroot當中kill某個 process,ex: kill -9 24, 是可以成功的)

google上面找到一個 /proc/sysrq-trigger 的方法,如下:

Step1:
先執行 echo 1 > /proc/sys/kernel/sysrq

Step2:
poweroff:
=>  echo "o" > /proc/sysrq-trigger

reboot:
=>  echo "b" > /proc/sysrq-trigger

更多用法可以參考
Ref: http://www.unixlinux.online/unixlinux/linuxjc/gylinux/201703/95680.html

# 立即重新啟動裝置
echo "b" > /proc/sysrq-trigger

# 立即關閉裝置
echo "o" > /proc/sysrq-trigger

# 導出內存分配的信息 (可以用/var/log/message 查看)
echo "m" > /proc/sysrq-trigger

# 導出當前CPU寄存器信息和標志位的信息
echo "p" > /proc/sysrq-trigger

# 導出線程狀態信息
echo "t" > /proc/sysrq-trigger

# 故意讓系統崩潰(kernel panic)
echo "c" > /proc/sysrq-trigger

# 立即重新掛載所有的文件系統
echo "s" > /proc/sysrq-trigger

# 立即重新掛載所有的文件系統為只讀
echo "u" > /proc/sysrq-trigger

Documentation for sysrq.c

Based on kernel version 2.6.38. Page generated on 2011-03-22 22:20 EST.

調整某個Daemon的 nice值(priority),從service 來調整 Linux Nice

當有個Daemon占據CPU太多的使用率時,我們可以透過調整nice值來降低其佔據CPU的使用率

今天我們以 mnld 這個daemon來當作範例,mnld是一個GNSS使用的Daemon

說明一下怎麼修改nice數值,也就是調整其優先順序

如下圖,我們可以在系統或是你的 Source Code 當中找到 mnld.service

然後我們可以修改如下圖,Nice值範圍為 -20 ~ 19 (高優先 ~ 低優先),default is 0









改完之後,下次重啟設備,我們可以使用指令,來觀察Nice值  =>  ps -fl -C "mnld"
command ref: 
https://www.thegeekstuff.com/2013/08/nice-renice-command-examples/







2023年11月29日星期三

編譯 Yocto SDK toochain 包含 Linux kernel 的 header 與 source (Build Yocto sdk include kernel header and source)

Step1:
我使用的
Yocto Project為2.6版,編譯SDK的指令如下: (以 MTK平台為例, xxxx 帶入自己的platform)
bitbake mtk-image-xxxx -c populate_sdk  


Step2:

用以上指令,編譯出來的Toolchain並不包含kernel header或是 kernel source,查詢網頁之後,得知需要再包含編譯這個Package “kernel-devsrc”


Step3:
接著我們在mtk-image-xxxx.bb 裡面,加上這個package,IMAGE_INSTALL_append += "kernel-devsrc"
Path: meta/meta-mediatek-mtxxxx/recipes-core/images/mtk-image-xxxx.bb
如下圖:





Step4:
接著編譯SDK,會遇到以下的錯誤訊息:

Fix kernel-devsrc package failing during install This issue is due to the upstream script hardcodes /bin/awk whereas we ship /usr/bin/awk. The installation check will break in this case. Fix it by changing the path in the script.

Step5:
從網路上,也看到有人在討論同樣的議題,有人提供patch方法,如下Link:

https://gerrit.automotivelinux.org/gerrit/c/AGL/meta-agl/+/11173/3/meta-agl-bsp/meta-ti/recipes-kernel/linux/linux-ti-staging_%2525.bbappend

於是我把這些修改加入meta/meta-mediatek-mtxxxx/recipes-kernel/linux/linux-mtk-extension_4.19.bbappend如下:





Step6:
接著繼續編譯SDK,結果出現以下的問題:
ERROR: mtk-image-xxxx-1.0-r0 do_populate_sdk: Could not invoke dnf. Command 
主要的錯誤訊息如下

Error:

 Problem: package target-sdk-provides-dummy-1.0-r0.sdk_provides_dummy_target conflicts with /bin/sh provided by busybox-1.29.3-r0.aarch64
- package kernel-devsrc-1.0-r0.autoxxxxevb_ivt_vp2 requires /usr/bin/awk, but none of the providers can be installed
- conflicting requests

Step7:
看了上面的錯誤訊息,其中一個錯誤是說,我們沒有安裝awk這個工具,因此我們試著安裝gawk. 我們接著到Yocto網站master branch底下,poky的路徑底下,搜尋awk

https://git.yoctoproject.org/poky/tree/?id=0a04692279f83637c0049cb1f91ac684f3fccf1f

於是可以看到如下的畫面,接著隨便點一個link,會到下面第二個頁面,我們可以從第二個頁面看到實際gawk的路徑為”meta/recipes-extended/gawk/”


















Step8:
接著就可以回到Yocto Tree的路徑,接著按照下圖步驟,可以找到gawk的reciepe. 

https://git.yoctoproject.org/poky/tree/meta?id=0a04692279f83637c0049cb1f91ac684f3fccf1f



















Step9:

我們選擇使用版本gawk-4.1.3,因為我們的Yocto為2.6版比較舊,選太新的recipe,有語法寫法不相同的問題(ex: gawk-5.x).於是分別把gawk_4.1.3.bb以及 gawk_4.1.3資料夾,放到我們的Yocto Project (這個網站不知道怎麼下載檔案,目前我是用複製內容,再vi gawk_4.1.3.bb 到Yocto Project當中)
path:meta/meta-mediatek-mtxxxx/recipes-extended/gawk_4.1.3.bb



Step10:

另外要記得,還要再從mtk-image-xxxx.bb那邊打開gawk,這樣才會編譯到gawk.去修改meta/meta-mediatek-mtxxxx/recipes-core/images/mtk-image-xxxx.bb






Step11:

再重新編譯一次,就可以成功編譯出包含kernel-devsrc的toolchain
*註:加入kernel-devsrc&gawk之後,整個 編譯後的 image增加了100MB

使用 lsblk 印出 emmc 每個 partition的"名字"與"size"

使用以下的command可以印出 eMMC的 partition資訊 lsblk --bytes --output name,partlabel,size   參數說明 --bytes: partition的大小,以byte的方式輸出 --output: 後面可以指定要輸出的內容...