aboutsummaryrefslogtreecommitdiffstats
path: root/classes/xsctyaml.bbclass
blob: dd8c7cbe02f2cfccb43c96a849abfb3036251802 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
inherit python3native

DEPENDS += "python3-pyyaml-native"

# Since we're not inheriting native.bbclass, we need to set libdir to correctly point to the native libdir
PYTHON_SITEPACKAGES_DIR = "${libdir_native}/${PYTHON_DIR}/site-packages"

YAML_APP_CONFIG ?= ''
YAML_BSP_CONFIG ?= ''
YAML_FILE_PATH ?= ''
YAML_DT_BOARD_FLAGS ?= ''
YAML_SERIAL_CONSOLE_STDIN ?= ''
YAML_SERIAL_CONSOLE_STDOUT ?= ''
YAML_SERIAL_CONSOLE_BAUDRATE ?= ''
YAML_MAIN_MEMORY_CONFIG ?= ''
YAML_CONSOLE_DEVICE_CONFIG ?= ''
YAML_FLASH_MEMORY_CONFIG ?= ''
YAML_REMOVE_PL_DT ?= ''
YAML_DISABLE_DT_ZOCL ?= ''
YAML_FIRMWARE_NAME ?= ''
YAML_OVERLAY_CUSTOM_DTS ?= ''
YAML_BSP_COMPILER_FLAGS ?= ''
YAML_KERNEL_VERSION ?= ''
YAML_ENABLE_NO_ALIAS ?= ''
YAML_ENABLE_NO_LABELS ?= ''
YAML_ENABLE_DTG_ALIAS ?= ''
YAML_ENABLE_DT_VERBOSE ?= ''
YAML_PARTIAL_OVERLAY_CUSTOM_DTS ?= ''

YAML_FILE_PATH = "${WORKDIR}/${PN}.yaml"
XSCTH_MISC:append = " -yamlconf ${YAML_FILE_PATH}"

YAML_BUILD_CONFIG ?= "${@d.getVar('XSCTH_BUILD_CONFIG').lower()}"
YAML_APP_CONFIG += "${@'build-config' if d.getVar('YAML_BUILD_CONFIG') != '' else ''}"
YAML_APP_CONFIG[build-config] = "set,${YAML_BUILD_CONFIG}"

YAML_COMPILER_FLAGS ?= "${@d.getVar('XSCTH_COMPILER_DEBUG_FLAGS') if d.getVar('XSCTH_BUILD_DEBUG') != "0" else d.getVar('XSCTH_APP_COMPILER_FLAGS')}"
YAML_APP_CONFIG += "${@'compiler-misc' if d.getVar('YAML_COMPILER_FLAGS') != '' else ''}"
YAML_APP_CONFIG[compiler-misc] = "add,${YAML_COMPILER_FLAGS}"

YAML_BSP_CONFIG += "${@'extra_compiler_flags' if d.getVar('YAML_BSP_COMPILER_FLAGS') != '' else ''}"
YAML_BSP_CONFIG[extra_compiler_flags] = "add,${YAML_BSP_COMPILER_FLAGS}"

YAML_BSP_CONFIG += "${@'periph_type_overrides' if d.getVar('YAML_DT_BOARD_FLAGS') != '' else ''}"
YAML_BSP_CONFIG[periph_type_overrides] = "set,${YAML_DT_BOARD_FLAGS}"

YAML_BSP_CONFIG += "${@'kernel_version' if d.getVar('YAML_KERNEL_VERSION') != '' else ''}"
YAML_BSP_CONFIG[kernel_version] = "set,${YAML_KERNEL_VERSION}"

YAML_BSP_CONFIG += "${@'stdin' if d.getVar('YAML_SERIAL_CONSOLE_STDIN') != '' else ''}"
YAML_BSP_CONFIG[stdin] = "set,${YAML_SERIAL_CONSOLE_STDIN}"

YAML_BSP_CONFIG += "${@'stdout' if d.getVar('YAML_SERIAL_CONSOLE_STDOUT') != '' else ''}"
YAML_BSP_CONFIG[stdout] = "set,${YAML_SERIAL_CONSOLE_STDOUT}"

YAML_BSP_CONFIG += "${@'main_memory' if d.getVar('YAML_MAIN_MEMORY_CONFIG') != '' else ''}"
YAML_BSP_CONFIG[main_memory] = "set,${YAML_MAIN_MEMORY_CONFIG}"


YAML_BSP_CONFIG += "${@'flash_memory' if d.getVar('YAML_FLASH_MEMORY_CONFIG') != '' else ''}"
YAML_BSP_CONFIG[flash_memory] = "set,${YAML_FLASH_MEMORY_CONFIG}"

YAML_BSP_CONFIG += "${@'console_device' if d.getVar('YAML_CONSOLE_DEVICE_CONFIG') != '' else ''}"
YAML_BSP_CONFIG[console_device] = "set,${YAML_CONSOLE_DEVICE_CONFIG}"

YAML_BSP_CONFIG += "${@'dt_overlay' if d.getVar('YAML_ENABLE_DT_OVERLAY') == '1' else ''}"
YAML_BSP_CONFIG[dt_overlay] = "set,TRUE"

YAML_ENABLE_DT_OVERLAY ?= "${@bb.utils.contains('MACHINE_FEATURES', 'fpga-overlay', '1', '0', d)}"

YAML_BSP_CONFIG += "${@'firmware_name' if d.getVar('YAML_FIRMWARE_NAME') != '' else ''}"
YAML_BSP_CONFIG[firmware_name] = "set,${YAML_FIRMWARE_NAME}"

YAML_BSP_CONFIG += "${@'dt_zocl' if d.getVar('YAML_DISABLE_DT_ZOCL') == '1' else ''}"
YAML_BSP_CONFIG[dt_zocl] = "set,FALSE"

YAML_BSP_CONFIG += "${@'overlay_custom_dts' if d.getVar('YAML_OVERLAY_CUSTOM_DTS') != '' else ''}"
YAML_BSP_CONFIG[overlay_custom_dts] = "set,${YAML_OVERLAY_CUSTOM_DTS}"

YAML_BSP_CONFIG += "${@'remove_pl' if d.getVar('YAML_REMOVE_PL_DT') == '1' else ''}"
YAML_BSP_CONFIG[remove_pl] = "set,TRUE"

YAML_BSP_CONFIG += "${@'no_alias' if d.getVar('YAML_ENABLE_NO_ALIAS') == '1' else ''}"
YAML_BSP_CONFIG[no_alias] = "set,TRUE"

YAML_BSP_CONFIG += "${@'no_labels' if d.getVar('YAML_ENABLE_NO_LABELS') == '1' else ''}"
YAML_BSP_CONFIG[no_labels] = "set,TRUE"

YAML_BSP_CONFIG += "${@'dtg_alias' if d.getVar('YAML_ENABLE_DTG_ALIAS') == '1' else ''}"
YAML_BSP_CONFIG[dtg_alias] = "set,TRUE"

YAML_BSP_CONFIG += "${@'dt_verbose' if d.getVar('YAML_ENABLE_DT_VERBOSE') == '1' else ''}"
YAML_BSP_CONFIG[dt_verbose] = "set,TRUE"

YAML_BSP_CONFIG += "${@'dt_setbaud' if d.getVar('YAML_SERIAL_CONSOLE_BAUDRATE') != '' else ''}"
YAML_BSP_CONFIG[dt_setbaud] = "set,${YAML_SERIAL_CONSOLE_BAUDRATE}"

YAML_BSP_CONFIG += "${@'classic_soc' if d.getVar('YAML_ENABLE_CLASSIC_SOC') == '1' else ''}"
YAML_BSP_CONFIG[classic_soc] = "set,TRUE"

YAML_BSP_CONFIG += "${@'apu_as_overlay_config_master' if d.getVar('YAML_ENABLE_APU_AS_OVERLAY_CONFIG_MASTER') == '1' else ''}"
YAML_BSP_CONFIG[apu_as_overlay_config_master] = "set,TRUE"

YAML_BSP_CONFIG += "${@'partial_overlay_custom_dts' if d.getVar('YAML_PARTIAL_OVERLAY_CUSTOM_DTS') != '' else ''}"
YAML_BSP_CONFIG[partial_overlay_custom_dts] = "set,${YAML_PARTIAL_OVERLAY_CUSTOM_DTS}"

def patch_yaml(config, configflags, type, type_dict, d):
    import re
    for cfg in config:
        if cfg not in configflags:
            error_msg = "%s: invalid CONFIG" % (cfg)
            bb.error("YAML config Issue: %s " % (error_msg))
        else:
            cfgval = configflags[cfg].split(',', 1)
            val = d.expand(cfgval[1])
            type_dict[type].update({cfg: {re.sub(r'\s','',cfgval[0]): val}})

    return type_dict

python do_create_yaml() {
    import sys, os
    os.sys.path.append(os.path.join(d.getVar('RECIPE_SYSROOT_NATIVE'),d.getVar('PYTHON_SITEPACKAGES_DIR')[1::]))
    import yaml
    yaml_dict = {}

    appconfig = (d.getVar("YAML_APP_CONFIG") or "").split()
    if appconfig:
        yaml_dict.update({'app': {}})
        configflags = d.getVarFlags("YAML_APP_CONFIG") or {}
        yaml_dict = patch_yaml(appconfig, configflags, 'app', yaml_dict, d)

    bspconfig = (d.getVar("YAML_BSP_CONFIG") or "").split()
    if bspconfig:
        yaml_dict.update({'bsp': {}})
        configflags = d.getVarFlags("YAML_BSP_CONFIG") or {}
        yaml_dict = patch_yaml(bspconfig, configflags, 'bsp', yaml_dict, d)

    if len(yaml_dict) != 0:
        fp = d.getVar("YAML_FILE_PATH")
        if fp :
            yamlfile = open(fp, 'w')
            yamlfile.write(yaml.dump(yaml_dict, default_flow_style=True, width=2000))
            yamlfile.close()
}

addtask create_yaml after do_prepare_recipe_sysroot before do_configure