summaryrefslogtreecommitdiff
path: root/dtb-to-device.py
blob: 59b982f22bcf8f1965b1ba2dc1d36faeb3f13937 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/python

import argparse
import os
import re
import subprocess
import xmlrpclib

# mapping device tree blob - device type
device = {
    'am335x-boneblack.dtb': 'beaglebone-black',
    'apm-mustang.dtb': 'mustang',
    'axm5516-amarillo.dtb': 'lng-amarillo',
    'bcm28155-ap.dtb': 'capri',
    'ecx-2000.dtb': 'midway',
    'exynos5250-arndale.dtb': 'arndale',
    'exynos5420-arndale-octa.dtb': 'arndale-octa',
    'hi3620-hi4511.dtb': 'k3v2',
    'highbank.dtb': 'highbank',
    'hip04-d01.dtb': 'd01',
    'hisi-x5hd2-dkb.dtb': 'hi3716cv200',
    'hix5hd2-dkb.dtb': 'hi3716cv200',
    'juno.dtb': 'juno',
    'k2hk-evm.dtb': 'lng-keystone',
    'mb8ac0300eb.dtb': 'aa9',
    'omap4-panda-es.dtb': 'panda-es',
    'omap4-panda.dtb': 'panda',
    'qcom-apq8064-ifc6410.dtb': 'ifc6410',
    'qcom-apq8074-dragonboard.dtb': 'dragonboard-8074',
    'stih407-b2120.dtb': 'b2120stxh407',
    'stih410-b2120.dtb': 'b2120stxh410',
    'vexpress-v2p-ca15_a7.dtb': 'vexpress-tc2',
    'vexpress-v2p-ca5s.dtb': 'vexpress-a5',
    'vexpress-v2p-ca9.dtb': 'vexpress-a9',
}


def obfuscate_credentials(s):
    return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)


def lava_submit(config, lava_server):
    print config

    skip_lava = os.environ.get('SKIP_LAVA')
    if skip_lava is None:
        # LAVA user
        lava_user = os.environ.get('LAVA_USER')
        if lava_user is None:
            with open('/var/run/lava/lava-user') as f:
                lava_user = f.read().strip()

        # LAVA token
        lava_token = os.environ.get('LAVA_TOKEN')
        if lava_token is None:
            with open('/var/run/lava/lava-token') as f:
                lava_token = f.read().strip()

        # LAVA server base URL
        lava_server_root = lava_server.rstrip('/')
        if lava_server_root.endswith('/RPC2'):
            lava_server_root = lava_server_root[:-len('/RPC2')]

        lava_job_id = None
        try:
            server_url = \
                'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
            server = \
                xmlrpclib.ServerProxy(server_url.format(
                    lava_user=lava_user,
                    lava_token=lava_token,
                    lava_server=lava_server))
            lava_job_id = server.scheduler.submit_job(config)
        except xmlrpclib.ProtocolError, e:
            print 'Error making a LAVA request:', obfuscate_credentials(str(e))
            return
        except xmlrpclib.Fault, f:
            print 'Fault making a LAVA request:', obfuscate_credentials(str(f))
            return

        if lava_job_id is not None:
            print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
                  (lava_job_id, lava_server_root, lava_job_id)
    else:
        print 'INFO: LAVA job submission skipped.'


def main():
    parser = argparse.ArgumentParser(
        description='Generate LAVA job definition')
    parser.add_argument('--dtbs-path', default='out/dtbs',
                        help='device tree blobs location')

    arguments = parser.parse_args()
    dtbs_path = arguments.dtbs_path

    # LAVA server URL
    lava_server = os.environ.get('LAVA_SERVER',
                                 'validation.linaro.org/RPC2/')

    for root, dirs, files in os.walk('out'):
        for file in files:
            if 'Image' in file:
                kernel = file

    for root, dirs, files in os.walk(dtbs_path):
        for dtb in files:
            device_type = device.get(dtb, None)
            definitions_path = 'configs/linux-kernel-ci/lava-job-definitions'
            devices = os.listdir(definitions_path)
            definition = '%s/generic/template.yaml' % definitions_path
            if device_type in devices:
                definition = '%s/%s/template.yaml' % (definitions_path, device_type)
            if device_type is None:
                print 'INFO: %s is not mapped to a device' % dtb
            else:
                env = os.environ
                env['DTB'] = dtb
                env['KERNEL'] = kernel
                env['DEVICE_TYPE'] = device_type
                env['LAVA_SERVER'] = lava_server

                config = subprocess.check_output(['./lci-build-tools/yaml-to-json.py', definition],
                                                 env=env)
                lava_submit(config, lava_server)


if __name__ == '__main__':
    main()