xref: /OK3568_Linux_fs/yocto/poky/meta/classes/rootfsdebugfiles.bbclass (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# This class installs additional files found on the build host
2*4882a593Smuzhiyun# directly into the rootfs.
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun# One use case is to install a constant ssh host key in
5*4882a593Smuzhiyun# an image that gets created for just one machine. This
6*4882a593Smuzhiyun# solves two issues:
7*4882a593Smuzhiyun# - host key generation on the device can stall when the
8*4882a593Smuzhiyun#   kernel has not gathered enough entropy yet (seen in practice
9*4882a593Smuzhiyun#   under qemu)
10*4882a593Smuzhiyun# - ssh complains by default when the host key changes
11*4882a593Smuzhiyun#
12*4882a593Smuzhiyun# For dropbear, with the ssh host key store along side the local.conf:
13*4882a593Smuzhiyun# 1. Extend local.conf:
14*4882a593Smuzhiyun#    INHERIT += "rootfsdebugfiles"
15*4882a593Smuzhiyun#    ROOTFS_DEBUG_FILES += "${TOPDIR}/conf/dropbear_rsa_host_key ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ;"
16*4882a593Smuzhiyun# 2. Boot the image once, copy the dropbear_rsa_host_key from
17*4882a593Smuzhiyun#    the device into your build conf directory.
18*4882a593Smuzhiyun# 3. A optional parameter can be used to set file mode
19*4882a593Smuzhiyun#    of the copied target, for instance:
20*4882a593Smuzhiyun#    ROOTFS_DEBUG_FILES += "${TOPDIR}/conf/dropbear_rsa_host_key ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key 0600;"
21*4882a593Smuzhiyun#    in case they might be required to have a specific mode. (Shoundn't be too open, for example)
22*4882a593Smuzhiyun#
23*4882a593Smuzhiyun# Do not use for production images! It bypasses several
24*4882a593Smuzhiyun# core build mechanisms (updating the image when one
25*4882a593Smuzhiyun# of the files changes, license tracking in the image
26*4882a593Smuzhiyun# manifest, ...).
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunROOTFS_DEBUG_FILES ?= ""
29*4882a593SmuzhiyunROOTFS_DEBUG_FILES[doc] = "Lists additional files or directories to be installed with 'cp -a' in the format 'source1 target1;source2 target2;...'"
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunROOTFS_POSTPROCESS_COMMAND += "rootfs_debug_files;"
32*4882a593Smuzhiyunrootfs_debug_files () {
33*4882a593Smuzhiyun   #!/bin/sh -e
34*4882a593Smuzhiyun   echo "${ROOTFS_DEBUG_FILES}" | sed -e 's/;/\n/g' | while read source target mode; do
35*4882a593Smuzhiyun      if [ -e "$source" ]; then
36*4882a593Smuzhiyun         mkdir -p $(dirname $target)
37*4882a593Smuzhiyun         cp -a $source $target
38*4882a593Smuzhiyun         [ -n "$mode" ] && chmod $mode $target
39*4882a593Smuzhiyun      fi
40*4882a593Smuzhiyun   done
41*4882a593Smuzhiyun}
42