You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Yocto中install -m与install -d用法的困惑及相关疑问

Understanding the install Command and Directory Path in Your Yocto Recipe

Great question—let’s break this down into two key parts to clear up your confusion.

1. What does combining -m and -d in the install command do?

You’re right that -m is commonly linked to setting permissions for files, but it works perfectly with directories when paired with -d! Here’s the breakdown:

  • The -d flag tells install to create the specified directory (it can also create parent directories automatically if needed, though that’s not required here since each path is explicit).
  • The -m 0755 flag sets the permission mode of the newly created directory to 0755 directly.

When you create a directory with plain mkdir, its final permissions depend on the system’s umask (usually 022, which results in 755 by default). But explicitly using -m guarantees the directory gets exactly the permissions you want, no matter what umask settings are active in the build environment. This is super important in Yocto builds, where consistent permissions prevent runtime headaches—like an app failing to access its own directory because permissions are too restrictive.

Your code is explicitly enforcing that each app/ subdirectory has read/execute access for all users, and write access only for the owner—ideal for most application directory structures.

2. Why isn’t ${D} used here instead of ${DEPLOY_DIR_IMAGE}?

This is where the code deviates from typical Yocto best practices. Let’s clarify what these variables mean:

  • ${D} is the destination directory for a recipe’s files during the do_install step. It points to a subdirectory under tmp/work/<machine>/<recipe>/<version>/image/, which becomes part of the root filesystem (or a package) that Yocto manages as part of its standard build pipeline.
  • ${DEPLOY_DIR_IMAGE} is the folder where final images (like .rootfs.tar.gz, .wic, etc.) are stored, usually located at tmp/deploy/images/<machine>/.

By writing directly to ${DEPLOY_DIR_IMAGE}, this recipe skips Yocto’s standard root filesystem build process. Instead of adding directories to the root filesystem that gets packaged into the image, it creates directories directly in the final image deployment location. This might be intentional if the recipe is meant to add extra structure for files that aren’t part of a standard package—like external config files or scripts that get added post-build before the image is finalized.

That said, this isn’t the usual approach. Normally, you’d use ${D}/app, ${D}/app/apiary, etc., which adds the directories to the recipe’s image root. Yocto would then include these directories in the final root filesystem automatically, which is more maintainable and aligns with Yocto’s designed workflow.

To sum up: The install -m 0755 -d combo ensures consistent, predictable directory permissions, and the use of ${DEPLOY_DIR_IMAGE} is a non-standard choice to modify the final deployment directory directly instead of leveraging Yocto’s standard root filesystem setup.

内容的提问来源于stack exchange,提问作者Engineer999

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:54:46