Chuyển tới nội dung chính

Yocto & BitBake Cheatsheet

Tra cứu nhanh các lệnh BitBake, bitbake-layers, devtool và cách debug khi làm việc với Yocto Project.

Khởi tạo môi trường Build​

# Khởi tạo build directory (mặc định là build/)
source oe-init-build-env build

Các file cấu hình chính nằm trong build/conf/:

  • local.conf: Thiết lập MACHINE, DL_DIR, SSTATE_DIR, IMAGE_INSTALL:append, EXTRA_IMAGE_FEATURES.
  • bblayers.conf: Danh sách các layer tham gia build.

Lệnh BitBake thường dùng​

bitbake core-image-minimal # Build một image
bitbake <recipe> # Build một recipe cụ thể
bitbake -c listtasks <recipe> # Liệt kê tất cả task của recipe
bitbake -c menuconfig virtual/kernel # Mở menuconfig cho Linux kernel
bitbake -c compile -f <recipe> # Buộc chạy lại task compile
bitbake -c clean <recipe> # Xóa output của recipe
bitbake -c cleansstate <recipe> # Xóa output và sstate cache của recipe
bitbake -c cleanall <recipe> # Xóa output, sstate và cả source đã tải
bitbake -k <image> # Tiếp tục build dù có recipe lỗi
bitbake -c populate_sdk <image> # Xuất cross-compile SDK

Quản lý Layer (bitbake-layers)​

bitbake-layers show-layers # Xem các layer đang active và độ ưu tiên
bitbake-layers add-layer ../meta-custom
bitbake-layers remove-layer ../meta-custom
bitbake-layers create-layer ../meta-custom
bitbake-layers show-recipes "*nginx*" # Tìm recipe theo tên
bitbake-layers show-appends # Xem các file .bbappend đang áp dụng

Phát triển nhanh với devtool​

devtool modify <recipe> # Checkout source vào workspace/sources/<recipe> để sửa
devtool build <recipe> # Build recipe đang chỉnh sửa
devtool deploy-target <recipe> root@<board-ip> # Đẩy binary trực tiếp lên board qua SSH
devtool update-recipe <recipe> # Xuất thay đổi thành patch vào layer
devtool finish <recipe> <layer-path> # Cập nhật recipe và dọn workspace
devtool reset <recipe> # Hủy chỉnh sửa trong workspace

Debug Recipe & Biến môi trường​

# Xem giá trị cuối cùng và lịch sử gán của một biến trong recipe
bitbake -e <recipe> | grep "^SRC_URI="
bitbake -e <recipe> | grep "^IMAGE_INSTALL="

# Mở shell với đúng môi trường build của recipe
bitbake -c devshell <recipe>

# Kiểm tra cây phụ thuộc (tạo file task-depends.dot)
bitbake -g <image>

Log và thư mục làm việc của recipe nằm tại:

  • tmp/work/<arch>/<recipe>/<version>/temp/log.do_<task>
  • tmp/deploy/images/<machine>/ (chứa kernel, dtb, rootfs, .wic image)

Tham khảo​