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 

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

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