xref: /OK3568_Linux_fs/yocto/meta-openembedded/meta-oe/recipes-kernel/usbip-tools/usbip-tools.bb (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# Recipe for building userspace part of USB/IP
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# Started with work from chuck kamas - 2021-11-05
4*4882a593Smuzhiyun# https://lists.yoctoproject.org/g/yocto/topic/86249103?p=,,,20,0,0,0::recentpostdate/sticky,,,20,0,0,86249103
5*4882a593Smuzhiyun# Though have rewritten all the logic to be much simpler
6*4882a593Smuzhiyun#
7*4882a593Smuzhiyun# SPDX-License-Identifier: MIT
8*4882a593Smuzhiyun#
9*4882a593Smuzhiyun# Author(s)
10*4882a593Smuzhiyun#   clst@ambu.com (Claus Stovgaard)
11*4882a593Smuzhiyun#
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunSUMMARY = "userspace usbip from Linux kernel tools"
14*4882a593SmuzhiyunDESCRIPTION = " USB/IP protocol allows to pass USB device from server to \
15*4882a593Smuzhiyunclient over the network. Server is a machine which provides (shares) a \
16*4882a593SmuzhiyunUSB device. Client is a machine which uses USB device provided by server \
17*4882a593Smuzhiyunover the network. The USB device may be either physical device connected \
18*4882a593Smuzhiyunto a server or software entity created on a server using USB gadget subsystem."
19*4882a593Smuzhiyun
20*4882a593SmuzhiyunLICENSE = "GPL-2.0-only"
21*4882a593SmuzhiyunLIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6"
22*4882a593SmuzhiyunDEPENDS = "virtual/kernel udev"
23*4882a593SmuzhiyunPROVIDES = "virtual/usbip-tools"
24*4882a593Smuzhiyun
25*4882a593Smuzhiyuninherit kernelsrc autotools-brokensep
26*4882a593Smuzhiyun
27*4882a593Smuzhiyundo_configure[depends] += "virtual/kernel:do_shared_workdir"
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun# We need to set S, for not being set to STAGING_KERNEL_DIR, and by that
30*4882a593Smuzhiyun# be wiped when we prune dest below. We just set it to usbip-tools-1.0
31*4882a593SmuzhiyunS = "${WORKDIR}/${BP}"
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun# Copy the source files from KERNEL/tools/usb/usbip to ${S}
34*4882a593Smuzhiyundo_configure[prefuncs] += "copy_usbip_source_from_kernel"
35*4882a593Smuzhiyunpython copy_usbip_source_from_kernel() {
36*4882a593Smuzhiyun    dir_in_kernel = "tools/usb/usbip"
37*4882a593Smuzhiyun    src_dir = d.getVar("STAGING_KERNEL_DIR")
38*4882a593Smuzhiyun    src = oe.path.join(src_dir, dir_in_kernel)
39*4882a593Smuzhiyun    dest = d.getVar("S")
40*4882a593Smuzhiyun    bb.utils.mkdirhier(dest)
41*4882a593Smuzhiyun    bb.utils.prunedir(dest)
42*4882a593Smuzhiyun    # copy src to dest folder
43*4882a593Smuzhiyun    if not os.path.exists(src):
44*4882a593Smuzhiyun        bb.fatal("Path does not exist: %s. Maybe dir_in_kernel does not match the kernel version." % src)
45*4882a593Smuzhiyun    if os.path.isdir(src):
46*4882a593Smuzhiyun        oe.path.copyhardlinktree(src, dest)
47*4882a593Smuzhiyun    else:
48*4882a593Smuzhiyun        src_path = os.path.dirname(src)
49*4882a593Smuzhiyun        os.makedirs(os.path.join(dest,src_path),exist_ok=True)
50*4882a593Smuzhiyun        bb.utils.copyfile(src, dest)
51*4882a593Smuzhiyun}
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun# Use local scripts before relying on inherited autotools
54*4882a593Smuzhiyundo_configure () {
55*4882a593Smuzhiyun    # We are in ${B} - equal to ${S}, so just run the scripts
56*4882a593Smuzhiyun    ./cleanup.sh || bbnote "${PN} failed to cleanup.sh"
57*4882a593Smuzhiyun    ./autogen.sh || bbnote "${PN} failed to autogen.sh"
58*4882a593Smuzhiyun    oe_runconf
59*4882a593Smuzhiyun}
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun# As usbip integrate with the kernel module, we set this package to be build specific for
62*4882a593Smuzhiyun# this machine, and not generally for the architecture
63*4882a593SmuzhiyunPACKAGE_ARCH = "${MACHINE_ARCH}"
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun# Even though the libusbip is set to version 0.0.1, set the package version to match kernel
66*4882a593Smuzhiyun# e.g. usbip-tools-5.14.21-r0.qemux86_64.rpm for qemu package using kernel 5.14.21
67*4882a593Smuzhiyunpython do_package:prepend() {
68*4882a593Smuzhiyun    d.setVar('PKGV', d.getVar("KERNEL_VERSION", True).split("-")[0])
69*4882a593Smuzhiyun}