1*4882a593SmuzhiyunDESCRIPTION = "Different utilities from Android"
2*4882a593SmuzhiyunSECTION = "console/utils"
3*4882a593SmuzhiyunLICENSE = "Apache-2.0 & GPL-2.0-only & BSD-2-Clause & BSD-3-Clause"
4*4882a593SmuzhiyunLIC_FILES_CHKSUM = " \
5*4882a593Smuzhiyun    file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \
6*4882a593Smuzhiyun    file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6 \
7*4882a593Smuzhiyun    file://${COMMON_LICENSE_DIR}/BSD-2-Clause;md5=cb641bc04cda31daea161b1bc15da69f \
8*4882a593Smuzhiyun    file://${COMMON_LICENSE_DIR}/BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \
9*4882a593Smuzhiyun"
10*4882a593SmuzhiyunDEPENDS = "libbsd libpcre zlib libcap"
11*4882a593SmuzhiyunDEPENDS:append:class-target = " openssl"
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunANDROID_MIRROR = "android.googlesource.com"
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun# matches with android-5.1.1_r37
16*4882a593SmuzhiyunSRCREV_core = "2314b110bdebdbfd2d94c502282f9e57c849897e"
17*4882a593SmuzhiyunSRCREV_extras = "3ecbe8d841df96127d7855661293e5ab6ba6c205"
18*4882a593SmuzhiyunSRCREV_libhardware = "be55eb1f4d840c82ffaf7c47460df17ff5bc4d9b"
19*4882a593SmuzhiyunSRCREV_libselinux = "07e9e1339ad1ba608acfba9dce2d0f474b252feb"
20*4882a593SmuzhiyunSRCREV_build = "16e987def3d7d8f7d30805eb95cef69e52a87dbc"
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunSRCREV_FORMAT = "core_extras_libhardware_libselinux_build"
23*4882a593SmuzhiyunSRC_URI = " \
24*4882a593Smuzhiyun    git://${ANDROID_MIRROR}/platform/system/core;name=core;protocol=https;nobranch=1;destsuffix=git/system/core \
25*4882a593Smuzhiyun    git://${ANDROID_MIRROR}/platform/system/extras;name=extras;protocol=https;nobranch=1;destsuffix=git/system/extras \
26*4882a593Smuzhiyun    git://${ANDROID_MIRROR}/platform/hardware/libhardware;name=libhardware;protocol=https;nobranch=1;destsuffix=git/hardware/libhardware \
27*4882a593Smuzhiyun    git://${ANDROID_MIRROR}/platform/external/libselinux;name=libselinux;protocol=https;nobranch=1;destsuffix=git/external/libselinux \
28*4882a593Smuzhiyun    git://${ANDROID_MIRROR}/platform/build;name=build;protocol=https;nobranch=1;destsuffix=git/build \
29*4882a593Smuzhiyun    file://core/0001-adb-remove-selinux-extensions.patch;patchdir=system/core \
30*4882a593Smuzhiyun    file://core/0002-adb-Use-local-sockets-where-appropriate.patch;patchdir=system/core \
31*4882a593Smuzhiyun    file://core/0003-adb-define-shell-command.patch;patchdir=system/core \
32*4882a593Smuzhiyun    file://core/0004-adb-Fix-build-on-big-endian-systems.patch;patchdir=system/core \
33*4882a593Smuzhiyun    file://core/0005-adb-add-base64-implementation.patch;patchdir=system/core \
34*4882a593Smuzhiyun    file://core/0006-adb-Musl-fixes.patch;patchdir=system/core \
35*4882a593Smuzhiyun    file://core/0007-adb-usb_linux.c-fix-build-with-glibc-2.28.patch;patchdir=system/core \
36*4882a593Smuzhiyun    file://core/0008-adb-Allow-adbd-to-be-ran-as-root.patch;patchdir=system/core \
37*4882a593Smuzhiyun    file://core/0009-mkbootimg-Add-dt-parameter-to-specify-DT-image.patch;patchdir=system/core \
38*4882a593Smuzhiyun    file://core/0010-Use-linux-capability.h-on-linux-systems-too.patch;patchdir=system/core \
39*4882a593Smuzhiyun    file://core/0011-Remove-bionic-specific-calls.patch;patchdir=system/core \
40*4882a593Smuzhiyun    file://core/0012-Fix-implicit-declaration-of-stlcat-strlcopy-function.patch;patchdir=system/core \
41*4882a593Smuzhiyun    file://core/adb_libssl_11.diff;patchdir=system/core \
42*4882a593Smuzhiyun    file://core/0013-adb-Support-riscv64.patch;patchdir=system/core \
43*4882a593Smuzhiyun    file://core/0014-add-u3-ss-descriptor-support-for-adb.patch;patchdir=system/core \
44*4882a593Smuzhiyun    file://extras/0001-ext4_utils-remove-selinux-extensions.patch;patchdir=system/extras \
45*4882a593Smuzhiyun    file://extras/0002-ext4_utils-add-o-argument-to-preserve-ownership.patch;patchdir=system/extras \
46*4882a593Smuzhiyun    file://libselinux/0001-Remove-bionic-specific-calls.patch;patchdir=external/libselinux \
47*4882a593Smuzhiyun    file://libselinux/0001-libselinux-Do-not-define-gettid-if-glibc-2.30-is-use.patch;patchdir=external/libselinux \
48*4882a593Smuzhiyun    file://android-tools-adbd.service \
49*4882a593Smuzhiyun    file://build/0001-Riscv-Add-risc-v-Android-config-header.patch;patchdir=build \
50*4882a593Smuzhiyun    file://gitignore \
51*4882a593Smuzhiyun    file://adb.mk;subdir=${BPN} \
52*4882a593Smuzhiyun    file://adbd.mk;subdir=${BPN} \
53*4882a593Smuzhiyun    file://ext4_utils.mk;subdir=${BPN} \
54*4882a593Smuzhiyun    file://fastboot.mk;subdir=${BPN} \
55*4882a593Smuzhiyun    file://mkbootimg.mk;subdir=${BPN} \
56*4882a593Smuzhiyun"
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunS = "${WORKDIR}/git"
60*4882a593SmuzhiyunB = "${WORKDIR}/${BPN}"
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun# http://errors.yoctoproject.org/Errors/Details/133881/
63*4882a593SmuzhiyunARM_INSTRUCTION_SET:armv4 = "arm"
64*4882a593SmuzhiyunARM_INSTRUCTION_SET:armv5 = "arm"
65*4882a593Smuzhiyun
66*4882a593SmuzhiyunCOMPATIBLE_HOST:powerpc = "(null)"
67*4882a593SmuzhiyunCOMPATIBLE_HOST:powerpc64 = "(null)"
68*4882a593SmuzhiyunCOMPATIBLE_HOST:powerpc64le = "(null)"
69*4882a593Smuzhiyun
70*4882a593Smuzhiyuninherit systemd
71*4882a593Smuzhiyun
72*4882a593SmuzhiyunSYSTEMD_PACKAGES = "${PN}-adbd"
73*4882a593SmuzhiyunSYSTEMD_SERVICE:${PN}-adbd = "android-tools-adbd.service"
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun# Find libbsd headers during native builds
76*4882a593SmuzhiyunCC:append:class-native = " -I${STAGING_INCDIR}"
77*4882a593SmuzhiyunCC:append:class-nativesdk = " -I${STAGING_INCDIR}"
78*4882a593Smuzhiyun
79*4882a593SmuzhiyunTOOLS = "adb fastboot ext4_utils mkbootimg adbd"
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun# Adb needs sys/capability.h, which is not available for native*
82*4882a593SmuzhiyunTOOLS:class-native = "fastboot ext4_utils mkbootimg"
83*4882a593SmuzhiyunTOOLS:class-nativesdk = "fastboot ext4_utils mkbootimg"
84*4882a593Smuzhiyun
85*4882a593Smuzhiyundo_compile() {
86*4882a593Smuzhiyun    cp ${WORKDIR}/gitignore ${S}/.gitignore
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun    # Setting both variables below causing our makefiles to not work with
89*4882a593Smuzhiyun    # implicit make rules
90*4882a593Smuzhiyun    unset CFLAGS
91*4882a593Smuzhiyun    unset CPPFLAGS
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun    export SRCDIR=${S}
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun    case "${HOST_ARCH}" in
96*4882a593Smuzhiyun      arm)
97*4882a593Smuzhiyun        export android_arch=linux-arm
98*4882a593Smuzhiyun      ;;
99*4882a593Smuzhiyun      aarch64)
100*4882a593Smuzhiyun        export android_arch=linux-arm64
101*4882a593Smuzhiyun      ;;
102*4882a593Smuzhiyun      riscv64)
103*4882a593Smuzhiyun        export android_arch=linux-riscv64
104*4882a593Smuzhiyun      ;;
105*4882a593Smuzhiyun      mips|mipsel)
106*4882a593Smuzhiyun        export android_arch=linux-mips
107*4882a593Smuzhiyun      ;;
108*4882a593Smuzhiyun      mips64|mips64el)
109*4882a593Smuzhiyun        export android_arch=linux-mips64
110*4882a593Smuzhiyun      ;;
111*4882a593Smuzhiyun      powerpc|powerpc64)
112*4882a593Smuzhiyun        export android_arch=linux-ppc
113*4882a593Smuzhiyun      ;;
114*4882a593Smuzhiyun      i586|i686|x86_64)
115*4882a593Smuzhiyun        export android_arch=linux-x86
116*4882a593Smuzhiyun      ;;
117*4882a593Smuzhiyun    esac
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun    for tool in ${TOOLS}; do
120*4882a593Smuzhiyun      mkdir -p ${B}/${tool}
121*4882a593Smuzhiyun      oe_runmake -f ${B}/${tool}.mk -C ${B}/${tool}
122*4882a593Smuzhiyun    done
123*4882a593Smuzhiyun}
124*4882a593Smuzhiyun
125*4882a593Smuzhiyundo_install() {
126*4882a593Smuzhiyun    if echo ${TOOLS} | grep -q "ext4_utils" ; then
127*4882a593Smuzhiyun        install -D -p -m0755 ${S}/system/core/libsparse/simg_dump.py ${D}${bindir}/simg_dump
128*4882a593Smuzhiyun        install -D -p -m0755 ${S}/system/extras/ext4_utils/mkuserimg.sh ${D}${bindir}/mkuserimg
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun        install -m0755 ${B}/ext4_utils/ext2simg ${D}${bindir}
131*4882a593Smuzhiyun        install -m0755 ${B}/ext4_utils/ext4fixup ${D}${bindir}
132*4882a593Smuzhiyun        install -m0755 ${B}/ext4_utils/img2simg ${D}${bindir}
133*4882a593Smuzhiyun        install -m0755 ${B}/ext4_utils/make_ext4fs ${D}${bindir}
134*4882a593Smuzhiyun        install -m0755 ${B}/ext4_utils/simg2img ${D}${bindir}
135*4882a593Smuzhiyun        install -m0755 ${B}/ext4_utils/simg2simg ${D}${bindir}
136*4882a593Smuzhiyun    fi
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun    if echo ${TOOLS} | grep -q "adb\>" ; then
139*4882a593Smuzhiyun        install -d ${D}${bindir}
140*4882a593Smuzhiyun        install -m0755 ${B}/adb/adb ${D}${bindir}
141*4882a593Smuzhiyun    fi
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun    if echo ${TOOLS} | grep -q "adbd" ; then
144*4882a593Smuzhiyun        install -d ${D}${bindir}
145*4882a593Smuzhiyun        install -m0755 ${B}/adbd/adbd ${D}${bindir}
146*4882a593Smuzhiyun    fi
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun    # Outside the if statement to avoid errors during do_package
149*4882a593Smuzhiyun    install -D -p -m0644 ${WORKDIR}/android-tools-adbd.service \
150*4882a593Smuzhiyun      ${D}${systemd_unitdir}/system/android-tools-adbd.service
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun    if echo ${TOOLS} | grep -q "fastboot" ; then
153*4882a593Smuzhiyun        install -d ${D}${bindir}
154*4882a593Smuzhiyun        install -m0755 ${B}/fastboot/fastboot ${D}${bindir}
155*4882a593Smuzhiyun    fi
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun    if echo ${TOOLS} | grep -q "mkbootimg" ; then
158*4882a593Smuzhiyun        install -d ${D}${bindir}
159*4882a593Smuzhiyun        install -m0755 ${B}/mkbootimg/mkbootimg ${D}${bindir}
160*4882a593Smuzhiyun    fi
161*4882a593Smuzhiyun}
162*4882a593Smuzhiyun
163*4882a593SmuzhiyunPACKAGES =+ "${PN}-fstools ${PN}-adbd"
164*4882a593Smuzhiyun
165*4882a593SmuzhiyunRDEPENDS:${PN}-adbd = "${PN}-conf"
166*4882a593SmuzhiyunRDEPENDS:${PN}-fstools = "bash"
167*4882a593Smuzhiyun
168*4882a593SmuzhiyunFILES:${PN}-adbd = "\
169*4882a593Smuzhiyun    ${bindir}/adbd \
170*4882a593Smuzhiyun    ${systemd_unitdir}/system/android-tools-adbd.service \
171*4882a593Smuzhiyun"
172*4882a593Smuzhiyun
173*4882a593SmuzhiyunFILES:${PN}-fstools = "\
174*4882a593Smuzhiyun    ${bindir}/ext2simg \
175*4882a593Smuzhiyun    ${bindir}/ext4fixup \
176*4882a593Smuzhiyun    ${bindir}/img2simg \
177*4882a593Smuzhiyun    ${bindir}/make_ext4fs \
178*4882a593Smuzhiyun    ${bindir}/simg2img \
179*4882a593Smuzhiyun    ${bindir}/simg2simg \
180*4882a593Smuzhiyun    ${bindir}/simg_dump \
181*4882a593Smuzhiyun    ${bindir}/mkuserimg \
182*4882a593Smuzhiyun"
183*4882a593Smuzhiyun
184*4882a593SmuzhiyunBBCLASSEXTEND = "native"
185*4882a593Smuzhiyun
186*4882a593Smuzhiyunandroid_tools_enable_devmode() {
187*4882a593Smuzhiyun    touch ${IMAGE_ROOTFS}/var/usb-debugging-enabled
188*4882a593Smuzhiyun}
189*4882a593Smuzhiyun
190*4882a593SmuzhiyunROOTFS_POSTPROCESS_COMMAND_${PN}-adbd += "${@bb.utils.contains("USB_DEBUGGING_ENABLED", "1", "android_tools_enable_devmode;", "", d)}"
191