aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-bsp/firmware/firmware-qcom-nhlos.inc
blob: 7c3c2b98871e4678c7d831d73decf32f5feed7df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Handle NON-HLOS.bin unpacking in a generic way
# Include the file to be able to dissect the image using handle_nonhlos_image()
# If NHLOS_URI is defined, the image will be dissected automatically

NHLOS_URI ??= ""

# List all firmware files to be installed
FW_QCOM_LIST ??= ""

DEPENDS += "pil-squasher-native mtools-native"

# Conditionally populate SRC_URI. We have to do it here rather than in python
# script to let base.bbclass to pick up dependencies
SRC_URI += "${NHLOS_URI}"

handle_nonhlos_image() {
    mkdir -p ${B}/firmware
    mcopy -n -s -i "$1" ::/* ${B}/firmware/
    for fw in ${B}/firmware/image/*.mdt ; do
        pil-squasher ${B}/`basename $fw mdt`mbn $fw || exit 1
    done
}

# If the URL is the file:// URI, the whole local path will be duplicated in the UNPACKDIR.
# Otherwise we just need the last (filename) part of the path.
def get_nhlos_path(path):
    from urllib.parse import urlparse
    if path == "":
        return ""
    url = urlparse(path)
    if url.scheme == "file":
        return url.path
    return url.path.rsplit('/', 1)[1]

do_compile:prepend() {
    if [ -n "${NHLOS_URI}" ] ; then
        handle_nonhlos_image ${UNPACKDIR}/${@get_nhlos_path(d.getVar("NHLOS_URI"))}
    fi
}

do_install:prepend() {
    install -d ${D}${FW_QCOM_PATH}

    for fw in ${FW_QCOM_LIST} ; do
        if [ -r ${B}/$fw ] ; then
            install -m 0644 ${B}/$fw ${D}${FW_QCOM_PATH}
        fi

        if [ -r ${B}/firmware/image/$fw ] ; then
            install -m 0644 ${B}/firmware/image/$fw ${D}${FW_QCOM_PATH}
        fi
    done
}

# If firmware files are not provided, do not download/package anything
python () {
    uri = d.getVar("NHLOS_URI")
    if uri == "":
        bb.warn("%s: not packaging NHLOS firmware. Please provide HNLOS_URI" % d.getVar("PN"))
}