192b42cb3SPatrick Williams# 292b42cb3SPatrick Williams# Copyright OpenEmbedded Contributors 392b42cb3SPatrick Williams# 492b42cb3SPatrick Williams# SPDX-License-Identifier: MIT 592b42cb3SPatrick Williams# 692b42cb3SPatrick Williams 792b42cb3SPatrick Williams# This class installs additional files found on the build host 892b42cb3SPatrick Williams# directly into the rootfs. 992b42cb3SPatrick Williams# 1092b42cb3SPatrick Williams# One use case is to install a constant ssh host key in 1192b42cb3SPatrick Williams# an image that gets created for just one machine. This 1292b42cb3SPatrick Williams# solves two issues: 1392b42cb3SPatrick Williams# - host key generation on the device can stall when the 1492b42cb3SPatrick Williams# kernel has not gathered enough entropy yet (seen in practice 1592b42cb3SPatrick Williams# under qemu) 1692b42cb3SPatrick Williams# - ssh complains by default when the host key changes 1792b42cb3SPatrick Williams# 1892b42cb3SPatrick Williams# For dropbear, with the ssh host key store along side the local.conf: 1992b42cb3SPatrick Williams# 1. Extend local.conf: 2092b42cb3SPatrick Williams# INHERIT += "rootfsdebugfiles" 2192b42cb3SPatrick Williams# ROOTFS_DEBUG_FILES += "${TOPDIR}/conf/dropbear_rsa_host_key ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ;" 2292b42cb3SPatrick Williams# 2. Boot the image once, copy the dropbear_rsa_host_key from 2392b42cb3SPatrick Williams# the device into your build conf directory. 2492b42cb3SPatrick Williams# 3. A optional parameter can be used to set file mode 2592b42cb3SPatrick Williams# of the copied target, for instance: 2692b42cb3SPatrick Williams# ROOTFS_DEBUG_FILES += "${TOPDIR}/conf/dropbear_rsa_host_key ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key 0600;" 2792b42cb3SPatrick Williams# in case they might be required to have a specific mode. (Shoundn't be too open, for example) 2892b42cb3SPatrick Williams# 2992b42cb3SPatrick Williams# Do not use for production images! It bypasses several 3092b42cb3SPatrick Williams# core build mechanisms (updating the image when one 3192b42cb3SPatrick Williams# of the files changes, license tracking in the image 3292b42cb3SPatrick Williams# manifest, ...). 3392b42cb3SPatrick Williams 3492b42cb3SPatrick WilliamsROOTFS_DEBUG_FILES ?= "" 3592b42cb3SPatrick WilliamsROOTFS_DEBUG_FILES[doc] = "Lists additional files or directories to be installed with 'cp -a' in the format 'source1 target1;source2 target2;...'" 3692b42cb3SPatrick Williams 37*5082cc7fSAndrew GeisslerROOTFS_POSTPROCESS_COMMAND += "rootfs_debug_files" 3892b42cb3SPatrick Williamsrootfs_debug_files () { 3992b42cb3SPatrick Williams #!/bin/sh -e 4092b42cb3SPatrick Williams echo "${ROOTFS_DEBUG_FILES}" | sed -e 's/;/\n/g' | while read source target mode; do 4192b42cb3SPatrick Williams if [ -e "$source" ]; then 4292b42cb3SPatrick Williams mkdir -p $(dirname $target) 4392b42cb3SPatrick Williams cp -a $source $target 4492b42cb3SPatrick Williams [ -n "$mode" ] && chmod $mode $target 4592b42cb3SPatrick Williams fi 4692b42cb3SPatrick Williams done 4792b42cb3SPatrick Williams} 48