xref: /openbmc/openpower-pnor-code-mgmt/meson.build (revision 9df0f3f141ffa918483bd79fe1c0e57a618550fe)
1project(
2    'openpower-pnor-code-mgmt',
3    'cpp',
4    default_options: [
5        'warning_level=3',
6        'werror=true',
7        'cpp_std=c++23',
8        'buildtype=debugoptimized',
9        'b_ndebug=if-release',
10        'b_lto=true',
11    ],
12    license: 'Apache-2.0',
13    version: '1.0',
14    meson_version: '>=1.1.1',
15)
16
17if (get_option('buildtype') == 'minsize')
18    add_project_arguments('-DNDEBUG', language: 'cpp')
19endif
20
21# Disable lto when compiling with no optimization
22if (get_option('optimization') == '0')
23    add_project_arguments('-fno-lto', language: 'cpp')
24    message('Disabling lto because optimization is disabled')
25endif
26
27cxx = meson.get_compiler('cpp')
28
29extra_sources = []
30extra_unit_files = []
31extra_scripts = []
32
33build_vpnor = get_option('vpnor').allowed()
34build_pldm = get_option('pldm').allowed()
35build_verify_signature = get_option('verify-signature').allowed()
36
37if not cxx.has_header('CLI/CLI.hpp')
38    error('Could not find CLI.hpp')
39endif
40
41summary('building for device type', '@0@'.format(get_option('device-type')))
42summary('building vpnor', build_vpnor)
43summary('building pldm', build_pldm)
44summary('building signature verify', build_verify_signature)
45
46subs = configuration_data()
47subs.set_quoted('ACTIVATION_FWD_ASSOCIATION', 'inventory')
48subs.set_quoted('ACTIVATION_REV_ASSOCIATION', 'activation')
49subs.set_quoted('ACTIVE_FWD_ASSOCIATION', 'active')
50subs.set('ACTIVE_PNOR_MAX_ALLOWED', 2)
51subs.set_quoted('ACTIVE_REV_ASSOCIATION', 'software_version')
52subs.set_quoted(
53    'ASSOCIATIONS_INTERFACE',
54    'xyz.openbmc_project.Association.Definitions',
55)
56subs.set_quoted('BUSNAME_UPDATER', 'org.open_power.Software.Host.Updater')
57subs.set_quoted('CHASSIS_STATE_OBJ', 'xyz.openbmc_project.State.Chassis')
58subs.set_quoted(
59    'CHASSIS_STATE_OFF',
60    'xyz.openbmc_project.State.Chassis.PowerState.Off',
61)
62subs.set_quoted('CHASSIS_STATE_PATH', '/xyz/openbmc_project/state/chassis0')
63subs.set_quoted('FILEPATH_IFACE', 'xyz.openbmc_project.Common.FilePath')
64subs.set_quoted('FUNCTIONAL_FWD_ASSOCIATION', 'functional')
65subs.set_quoted('FUNCTIONAL_REV_ASSOCIATION', 'software_version')
66subs.set_quoted('HASH_FILE_NAME', 'hashfunc')
67subs.set_quoted(
68    'HOST_INVENTORY_PATH',
69    '/xyz/openbmc_project/inventory/system/chassis',
70)
71subs.set_quoted('IMG_DIR', '/tmp/images')
72subs.set_quoted('MANIFEST_FILE', 'MANIFEST')
73subs.set_quoted('MAPPER_BUSNAME', 'xyz.openbmc_project.ObjectMapper')
74subs.set_quoted('MAPPER_INTERFACE', 'xyz.openbmc_project.ObjectMapper')
75subs.set_quoted('MAPPER_PATH', '/xyz/openbmc_project/object_mapper')
76subs.set_quoted('MEDIA_DIR', '/media/')
77subs.set('MMC_LAYOUT', get_option('device-type') == 'mmc')
78subs.set_quoted('PERSIST_DIR', '/var/lib/obmc/openpower-pnor-code-mgmt/')
79subs.set_quoted('PNOR_ACTIVE_PATH', '/var/lib/phosphor-software-manager/pnor/')
80subs.set_quoted('PNOR_MSL', get_option('msl'))
81subs.set_quoted('PNOR_PRSV', '/media/pnor-prsv')
82subs.set_quoted(
83    'PNOR_PRSV_ACTIVE_PATH',
84    '/var/lib/phosphor-software-manager/pnor/prsv',
85)
86subs.set_quoted(
87    'PNOR_RO_ACTIVE_PATH',
88    '/var/lib/phosphor-software-manager/pnor/ro',
89)
90subs.set_quoted('PNOR_RO_PREFIX', '/media/pnor-ro-')
91subs.set_quoted(
92    'PNOR_RW_ACTIVE_PATH',
93    '/var/lib/phosphor-software-manager/pnor/rw',
94)
95subs.set_quoted('PNOR_RW_PREFIX', '/media/pnor-rw-')
96subs.set_quoted('PNOR_SIGNED_IMAGE_CONF_PATH', '/etc/activationdata/')
97subs.set_quoted('PNOR_TOC_FILE', 'pnor.toc')
98subs.set_quoted('PNOR_VERSION_PARTITION', 'VERSION')
99subs.set_quoted('PUBLICKEY_FILE_NAME', 'publickey')
100subs.set_quoted('SIGNATURE_FILE_EXT', '.sig')
101subs.set_quoted('SOFTWARE_OBJPATH', '/xyz/openbmc_project/software')
102subs.set_quoted('SYSTEMD_BUSNAME', 'org.freedesktop.systemd1')
103subs.set_quoted('SYSTEMD_INTERFACE', 'org.freedesktop.systemd1.Manager')
104subs.set_quoted('SYSTEMD_PATH', '/org/freedesktop/systemd1')
105subs.set_quoted('SYSTEMD_PROPERTY_INTERFACE', 'org.freedesktop.DBus.Properties')
106subs.set('UBIFS_LAYOUT', get_option('device-type') == 'ubi')
107subs.set_quoted('UPDATEABLE_FWD_ASSOCIATION', 'updateable')
108subs.set_quoted('UPDATEABLE_REV_ASSOCIATION', 'software_version')
109subs.set_quoted('VERSION_IFACE', 'xyz.openbmc_project.Software.Version')
110subs.set('WANT_SIGNATURE_VERIFY', build_verify_signature)
111configure_file(output: 'config.h', configuration: subs)
112
113if get_option('device-type') == 'ubi'
114    extra_sources += [
115        'ubi/activation_ubi.cpp',
116        'ubi/item_updater_ubi.cpp',
117        'ubi/serialize.cpp',
118        'ubi/watch.cpp',
119    ]
120    extra_scripts += ['ubi/obmc-flash-bios']
121    extra_unit_files += [
122        'ubi/obmc-flash-bios-cleanup.service',
123        'ubi/obmc-flash-bios-ubiattach.service',
124        'ubi/obmc-flash-bios-ubimount@.service',
125        'ubi/obmc-flash-bios-ubipatch.service',
126        'ubi/obmc-flash-bios-ubiremount.service',
127        'ubi/obmc-flash-bios-ubiumount-ro@.service',
128        'ubi/obmc-flash-bios-ubiumount-rw@.service',
129    ]
130endif
131
132if get_option('device-type') == 'mmc'
133    extra_sources += ['mmc/activation_mmc.cpp', 'mmc/item_updater_mmc.cpp']
134    extra_scripts += ['mmc/obmc-flash-bios', 'mmc/recover_pnor_files']
135    extra_unit_files += [
136        'mmc/obmc-flash-bios-init.service',
137        'mmc/obmc-flash-bios-patch.service',
138        'mmc/openpower-bios-factory-reset.service',
139        'mmc/obmc-recover-pnor.service',
140    ]
141endif
142
143if build_pldm
144    extra_unit_files += [
145        'mmc/openpower-process-host-firmware.service',
146        'mmc/openpower-update-bios-attr-table.service',
147    ]
148endif
149
150if get_option('device-type') == 'static'
151    extra_sources += [
152        'static/item_updater_static.cpp',
153        'static/activation_static.cpp',
154    ]
155    extra_unit_files += ['openpower-pnor-update@.service']
156endif
157
158if build_verify_signature
159    extra_sources += ['image_verify.cpp']
160endif
161
162if build_vpnor
163    extra_scripts += ['vpnor/obmc-vpnor-util']
164    extra_unit_files += [
165        'vpnor/obmc-vpnor-check-clearvolatile@.service',
166        'vpnor/obmc-vpnor-enable-clearvolatile@.service',
167        'vpnor/obmc-vpnor-updatesymlinks.service',
168    ]
169endif
170
171executable(
172    'openpower-update-manager',
173    [
174        'activation.cpp',
175        'functions.cpp',
176        'version.cpp',
177        'item_updater.cpp',
178        'item_updater_main.cpp',
179        'utils.cpp',
180    ] + extra_sources,
181    dependencies: [
182        dependency('libcrypto'),
183        dependency('libsystemd'),
184        dependency('openssl'),
185        dependency('phosphor-dbus-interfaces'),
186        dependency('phosphor-logging'),
187        dependency('sdbusplus'),
188        dependency('sdeventplus'),
189    ],
190    install: true,
191)
192
193executable(
194    'openpower-pnor-msl',
195    ['msl_verify.cpp', 'msl_verify_main.cpp'],
196    dependencies: [
197        dependency('libsystemd'),
198        dependency('phosphor-dbus-interfaces'),
199        dependency('phosphor-logging'),
200        dependency('sdbusplus'),
201    ],
202    install: true,
203)
204
205fs = import('fs')
206foreach s : extra_scripts
207    fs.copyfile(
208        s,
209        install: true,
210        install_mode: 'rwxr-xr-x',
211        install_dir: get_option('bindir'),
212    )
213endforeach
214
215unit_files = [
216    'op-pnor-msl.service',
217    'org.open_power.Software.Host.Updater.service',
218] + extra_unit_files
219
220systemd_system_unit_dir = dependency('systemd').get_variable(
221    'systemdsystemunitdir',
222    pkgconfig_define: ['prefix', get_option('prefix')],
223)
224foreach u : unit_files
225    fs.copyfile(u, install: true, install_dir: systemd_system_unit_dir)
226endforeach
227
228dbus_system_bus_services_dir = dependency('dbus-1').get_variable(
229    'system_bus_services_dir',
230    pkgconfig_define: ['prefix', get_option('prefix')],
231)
232dbus_policy_dir = run_command(
233    'realpath',
234    join_paths(dbus_system_bus_services_dir, '..', 'system.d'),
235).stdout().strip()
236
237install_data(
238    'dbus/org.open_power.Software.Host.Updater.conf',
239    install_dir: dbus_policy_dir,
240)
241
242if get_option('tests').allowed()
243    oe_sdk = get_option('oe-sdk')
244    if oe_sdk.allowed()
245        # Setup OE SYSROOT
246        OECORE_TARGET_SYSROOT = run_command(
247            'sh',
248            '-c',
249            'echo $OECORE_TARGET_SYSROOT',
250        ).stdout().strip()
251        if OECORE_TARGET_SYSROOT == ''
252            error(
253                'Unable to get $OECORE_TARGET_SYSROOT, check your environment.',
254            )
255        endif
256        message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
257        rpath = ':'.join(
258            [OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'],
259        )
260        ld_so = run_command(
261            'sh',
262            '-c',
263            'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1',
264        ).stdout().strip()
265        dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
266    else
267        dynamic_linker = []
268    endif
269
270    test(
271        'utest',
272        executable(
273            'utest',
274            'activation.cpp',
275            'version.cpp',
276            'item_updater.cpp',
277            'image_verify.cpp',
278            'utils.cpp',
279            'msl_verify.cpp',
280            'ubi/activation_ubi.cpp',
281            'ubi/item_updater_ubi.cpp',
282            'ubi/serialize.cpp',
283            'ubi/watch.cpp',
284            'static/item_updater_static.cpp',
285            'static/activation_static.cpp',
286            'test/test_signature.cpp',
287            'test/test_version.cpp',
288            'test/test_item_updater_static.cpp',
289            'msl_verify.cpp',
290            dependencies: [
291                dependency('libcrypto'),
292                dependency('gtest', main: true),
293                dependency('openssl'),
294                dependency('phosphor-logging'),
295                dependency('phosphor-dbus-interfaces'),
296            ],
297            implicit_include_directories: false,
298            include_directories: '.',
299        ),
300    )
301    test(
302        'test_functions',
303        executable(
304            'test_functions',
305            'test/test_functions.cpp',
306            'functions.cpp',
307            dependencies: [
308                dependency('gtest', main: true),
309                dependency('phosphor-dbus-interfaces'),
310                dependency('sdbusplus'),
311                dependency('sdeventplus'),
312            ],
313        ),
314    )
315endif
316