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        'mmc/openpower-process-host-firmware.service',
128    ]
129endif
130
131if get_option('device-type') == 'static'
132    extra_sources += [
133        'static/item_updater_static.cpp',
134        'static/activation_static.cpp',
135    ]
136    extra_unit_files += [
137        'openpower-pnor-update@.service',
138    ]
139endif
140
141if build_verify_signature
142    extra_sources += [
143        'image_verify.cpp'
144    ]
145endif
146
147if build_vpnor
148    extra_scripts += [
149        'vpnor/obmc-vpnor-util',
150    ]
151    extra_unit_files += [
152        'vpnor/obmc-vpnor-check-clearvolatile@.service',
153        'vpnor/obmc-vpnor-enable-clearvolatile@.service',
154        'vpnor/obmc-vpnor-updatesymlinks.service',
155    ]
156endif
157
158executable(
159    'openpower-update-manager',
160    [
161        'activation.cpp',
162        'functions.cpp',
163        'version.cpp',
164        'item_updater.cpp',
165        'item_updater_main.cpp',
166        'utils.cpp',
167    ] + extra_sources,
168    dependencies: [
169        dependency('libcrypto'),
170        dependency('libsystemd'),
171        dependency('openssl'),
172        dependency('phosphor-dbus-interfaces'),
173        dependency('phosphor-logging'),
174        dependency('sdbusplus'),
175        dependency('sdeventplus'),
176    ],
177    install: true
178)
179
180executable(
181    'openpower-pnor-msl',
182    [
183        'msl_verify.cpp',
184        'msl_verify_main.cpp',
185    ],
186    dependencies: [
187        dependency('libsystemd'),
188        dependency('phosphor-dbus-interfaces'),
189        dependency('phosphor-logging'),
190        dependency('sdbusplus'),
191    ],
192    install: true
193)
194
195foreach s : extra_scripts
196    configure_file(
197        input: s,
198        copy: true,
199        install: true,
200        install_mode: 'rwxr-xr-x',
201        install_dir: get_option('bindir'),
202        output: '@BASENAME@'
203    )
204endforeach
205
206unit_files = [
207    'op-pnor-msl.service',
208    'org.open_power.Software.Host.Updater.service',
209] + extra_unit_files
210
211systemd_system_unit_dir = dependency('systemd').get_variable(
212    pkgconfig: 'systemdsystemunitdir',
213    pkgconfig_define: ['prefix', get_option('prefix')])
214foreach u : unit_files
215    configure_file(
216        input: u,
217        copy: true,
218        install: true,
219        install_dir: systemd_system_unit_dir,
220        output: '@BASENAME@.service'
221    )
222endforeach
223
224dbus_system_bus_services_dir = dependency('dbus-1').get_variable(
225    pkgconfig: 'system_bus_services_dir',
226    pkgconfig_define: ['prefix', get_option('prefix')])
227dbus_policy_dir = run_command(
228    'realpath',
229    join_paths(dbus_system_bus_services_dir, '..', 'system.d')).stdout().strip()
230
231install_data(
232    'dbus/org.open_power.Software.Host.Updater.conf',
233    install_dir: dbus_policy_dir)
234
235if not get_option('tests').disabled()
236    oe_sdk = get_option('oe-sdk')
237    if oe_sdk.enabled()
238        # Setup OE SYSROOT
239        OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
240        if OECORE_TARGET_SYSROOT == ''
241            error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
242        endif
243        message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
244        rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
245        ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
246        dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
247    else
248        dynamic_linker = []
249    endif
250
251    test(
252        'utest',
253        executable(
254            'utest',
255            'activation.cpp',
256            'version.cpp',
257            'item_updater.cpp',
258            'image_verify.cpp',
259            'utils.cpp',
260            'msl_verify.cpp',
261            'ubi/activation_ubi.cpp',
262            'ubi/item_updater_ubi.cpp',
263            'ubi/serialize.cpp',
264            'ubi/watch.cpp',
265            'static/item_updater_static.cpp',
266            'static/activation_static.cpp',
267            'test/test_signature.cpp',
268            'test/test_version.cpp',
269            'test/test_item_updater_static.cpp',
270            'msl_verify.cpp',
271            dependencies: [
272                dependency('libcrypto'),
273                dependency('gtest', main: true),
274                dependency('openssl'),
275                dependency('phosphor-logging'),
276                dependency('phosphor-dbus-interfaces'),
277            ],
278            implicit_include_directories: false,
279            include_directories: '.',
280        )
281    )
282    test(
283        'test_functions',
284        executable(
285            'test_functions',
286            'test/test_functions.cpp',
287            'functions.cpp',
288            dependencies: [
289                dependency('gtest', main: true),
290                dependency('sdbusplus'),
291                dependency('sdeventplus'),
292            ],
293        )
294    )
295endif
296