1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【yocto】rootfs生成後、任意の処理を実行する方法

Last updated at Posted at 2022-06-08

はじめに

  • rootfs生成後、rootfsのあるファイルを削除したい等の要望がある人向け

方法

  • rootfsを生成するレシピ(.bb/.bbappend)に以下のような文を追記する
    • myfunctionは任意の関数名でOK
    • 実行したい処理にシェルスクリプトを記載する
    • yoctoの御作法的には、do_xxx等に処理を記載してrootfsに変更を加えるべき
    • 何かしらの理由でyoctoの御作法が守れない場合の苦肉の策
myfunction() {
    実行したい処理
}

ROOTFS_POSTPROCESS_COMMAND += "myfunction; "

動作確認

rootfsの/bin/viを削除してみる

  • 通常ビルドでは、rootfsに/bin/viがあることを確認する
takeshi@X250:~/yocto/poky$ source oe-init-build-env 
(略)
takeshi@X250:~/yocto/poky/build$ bitbake -k core-image-minimal
(略)
NOTE: Tasks Summary: Attempted 2654 tasks of which 2424 didn't need to be rerun and all succeeded.

Summary: There was 1 WARNING message shown.
takeshi@X250:~/yocto/poky/build$ mkdir rootfs
takeshi@X250:~/yocto/poky/build$ tar xvf tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.tar.bz2 -C rootfs/
(略)
takeshi@X250:~/yocto/poky/build$ ls rootfs/bin/
ash                  cpio                 fgrep                mkdir                pidof.sysvinit       sleep                uname
busybox              date                 getopt               mknod                ping                 start_getty          usleep
busybox.nosuid       dd                   grep                 mktemp               ping6                stat                 vi
busybox.suid         df                   gunzip               more                 ps                   stty                 watch
cat                  dmesg                gzip                 mount                pwd                  su                   zcat
chattr               dnsdomainname        hostname             mountpoint           rm                   sync                 
chgrp                dumpkmap             kill                 mountpoint.sysvinit  rmdir                tar                  
chmod                echo                 ln                   mv                   run-parts            touch                
chown                egrep                login                netstat              sed                  true                 
cp                   false                ls                   pidof                sh                   umount  
  • core-image-minimal.bbに以下のような修正を加える
    • yoctoの御作法的にはbbファイルに直接変更を加えるのはNG。core-image-minimal.bbappendを作成して修正すべき。
    • 簡単化のために、今回はbbファイルを直接修正した
takeshi@X250:~/yocto/poky/build$ cat ../meta/recipes-core/images/core-image-minimal.bb  | tail -n 5
rm_vi() {
    rm ${IMAGE_ROOTFS}/bin/vi
}

ROOTFS_POSTPROCESS_COMMAND += "rm_vi; "
  • ROOTFS_POSTPROCESS_COMMANDを追記したビルドでは、rootfsに/bin/viが無いことを確認する
takeshi@X250:~/yocto/poky/build$ bitbake -k core-image-minimal
(略)
takeshi@X250:~/yocto/poky/build$ rm -rf rootfs/
takeshi@X250:~/yocto/poky/build$ mkdir rootfs
takeshi@X250:~/yocto/poky/build$ tar xvf tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.tar.bz2 -C rootfs/
(略)
takeshi@X250:~/yocto/poky/build$ ls rootfs/bin/
ash             chattr  cpio   dnsdomainname  fgrep   hostname  mkdir   mountpoint           pidof.sysvinit  rm         sleep        sync    uname
busybox         chgrp   date   dumpkmap       getopt  kill      mknod   mountpoint.sysvinit  ping            rmdir      start_getty  tar     usleep
busybox.nosuid  chmod   dd     echo           grep    ln        mktemp  mv                   ping6           run-parts  stat         touch   watch
busybox.suid    chown   df     egrep          gunzip  login     more    netstat              ps              sed        stty         true    zcat
cat             cp      dmesg  false          gzip    ls        mount   pidof                pwd             sh         su           umount
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?