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