1project('phosphor-bmc-code-mgmt', 'cpp',
2    default_options: [
3        'buildtype=debugoptimized',
4        'cpp_std=c++20',
5        'warning_level=3',
6        'werror=true'
7    ],
8    meson_version: '>= 0.57.0',
9    license: 'Apache-2.0',
10    version: '1.0')
11
12add_project_arguments(
13    '-DBOOST_SYSTEM_NO_DEPRECATED',
14    '-DBOOST_ERROR_CODE_HEADER_ONLY',
15    '-DBOOST_NO_RTTI',
16    '-DBOOST_NO_TYPEID',
17    '-DBOOST_ALL_NO_LIB',
18    '-DBOOST_ASIO_DISABLE_THREADS',
19    '-DBOOST_ASIO_NO_DEPRECATED',
20    language: 'cpp',
21)
22
23cpp = meson.get_compiler('cpp')
24
25conf = configuration_data()
26
27# DBus information
28conf.set_quoted('BMC_INVENTORY_INTERFACE', 'xyz.openbmc_project.Inventory.Item.Bmc')
29conf.set_quoted('BUSNAME_UPDATER', 'xyz.openbmc_project.Software.BMC.Updater')
30conf.set_quoted('DOWNLOAD_BUSNAME', 'xyz.openbmc_project.Software.Download')
31conf.set_quoted('FILEPATH_IFACE', 'xyz.openbmc_project.Common.FilePath')
32conf.set_quoted('INVENTORY_PATH', '/xyz/openbmc_project/inventory/')
33conf.set_quoted('MAPPER_BUSNAME', 'xyz.openbmc_project.ObjectMapper')
34conf.set_quoted('MAPPER_INTERFACE', 'xyz.openbmc_project.ObjectMapper')
35conf.set_quoted('MAPPER_PATH', '/xyz/openbmc_project/object_mapper')
36conf.set_quoted('SOFTWARE_OBJPATH', '/xyz/openbmc_project/software')
37conf.set_quoted('SYSTEMD_BUSNAME', 'org.freedesktop.systemd1')
38conf.set_quoted('SYSTEMD_PATH', '/org/freedesktop/systemd1')
39conf.set_quoted('SYSTEMD_INTERFACE', 'org.freedesktop.systemd1.Manager')
40conf.set_quoted('VERSION_BUSNAME', 'xyz.openbmc_project.Software.Version')
41conf.set_quoted('VERSION_IFACE', 'xyz.openbmc_project.Software.Version')
42conf.set_quoted('EXTENDED_VERSION_IFACE', 'xyz.openbmc_project.Software.ExtendedVersion')
43
44# Names of the forward and reverse associations
45conf.set_quoted('ACTIVATION_FWD_ASSOCIATION', 'inventory')
46conf.set_quoted('ACTIVATION_REV_ASSOCIATION', 'activation')
47conf.set_quoted('ACTIVE_FWD_ASSOCIATION', 'active')
48conf.set_quoted('ACTIVE_REV_ASSOCIATION', 'software_version')
49conf.set_quoted('FUNCTIONAL_FWD_ASSOCIATION', 'functional')
50conf.set_quoted('FUNCTIONAL_REV_ASSOCIATION', 'software_version')
51conf.set_quoted('UPDATEABLE_FWD_ASSOCIATION', 'updateable')
52conf.set_quoted('UPDATEABLE_REV_ASSOCIATION', 'software_version')
53
54# Filesystem files and directories
55# The prefix path for the versioned read-only bmc partitions
56conf.set_quoted('BMC_ROFS_PREFIX', get_option('media-dir') + '/rofs-')
57# The name of the BMC table of contents file
58conf.set_quoted('OS_RELEASE_FILE', '/etc/os-release')
59# The dir where activation data is stored in files
60conf.set_quoted('PERSIST_DIR', '/var/lib/phosphor-bmc-code-mgmt/')
61
62# Supported BMC layout types
63conf.set('STATIC_LAYOUT', get_option('bmc-layout').contains('static'))
64conf.set('UBIFS_LAYOUT', get_option('bmc-layout').contains('ubi'))
65conf.set('MMC_LAYOUT', get_option('bmc-layout').contains('mmc'))
66
67# Configurable features
68conf.set('HOST_BIOS_UPGRADE', get_option('host-bios-upgrade').enabled())
69conf.set('WANT_SIGNATURE_VERIFY', \
70    get_option('verify-signature').enabled() or \
71    get_option('verify-full-signature').enabled())
72conf.set('WANT_SIGNATURE_FULL_VERIFY', get_option('verify-full-signature').enabled())
73
74# Configurable variables
75conf.set('ACTIVE_BMC_MAX_ALLOWED', get_option('active-bmc-max-allowed'))
76conf.set_quoted('HASH_FILE_NAME', get_option('hash-file-name'))
77conf.set_quoted('IMG_UPLOAD_DIR', get_option('img-upload-dir'))
78conf.set_quoted('MANIFEST_FILE_NAME', get_option('manifest-file-name'))
79conf.set_quoted('MEDIA_DIR', get_option('media-dir'))
80optional_array = get_option('optional-images')
81optional_images = ''
82foreach optiona_image : optional_array
83    optional_images = ' '.join([optional_images, optiona_image])
84endforeach
85conf.set_quoted('OPTIONAL_IMAGES', optional_images)
86conf.set_quoted('PUBLICKEY_FILE_NAME', get_option('publickey-file-name'))
87conf.set_quoted('SIGNATURE_FILE_EXT', get_option('signature-file-ext'))
88conf.set_quoted('SIGNED_IMAGE_CONF_PATH', get_option('signed-image-conf-path'))
89conf.set_quoted('SYNC_LIST_DIR_PATH', get_option('sync-list-dir-path'))
90conf.set_quoted('SYNC_LIST_FILE_NAME', get_option('sync-list-file-name'))
91conf.set_quoted('BMC_MSL', get_option('bmc-msl'))
92conf.set_quoted('REGEX_BMC_MSL', get_option('regex-bmc-msl'))
93
94if get_option('host-bios-upgrade').enabled()
95    conf.set_quoted('BIOS_OBJPATH', get_option('bios-object-path'))
96endif
97
98if get_option('bmc-static-dual-image').enabled()
99  conf.set('BMC_STATIC_DUAL_IMAGE', get_option('bmc-static-dual-image').enabled())
100  conf.set_quoted('ALT_ROFS_DIR', get_option('alt-rofs-dir'))
101  conf.set_quoted('ALT_RWFS', get_option('alt-rwfs-dir'))
102else
103  conf.set_quoted('ALT_RWFS', '/media/alt/var/persist')
104endif
105
106configure_file(output: 'config.h', configuration: conf)
107
108sdbusplus_dep = dependency('sdbusplus', required: false)
109sdbusplus_proj = dependency('', required: false)
110if not sdbusplus_dep.found() or sdbusplus_dep.type_name() == 'internal'
111    sdbusplus_proj = subproject('sdbusplus')
112endif
113if not sdbusplus_dep.found()
114    sdbusplus_dep = sdbusplus_proj.get_variable('sdbusplus_dep')
115endif
116
117if sdbusplus_proj.found()
118    sdbusplusplus_prog = sdbusplus_proj.get_variable('sdbusplusplus_prog')
119    sdbuspp_gen_meson_prog = sdbusplus_proj.get_variable(
120        'sdbuspp_gen_meson_prog')
121else
122    sdbusplusplus_prog = find_program('sdbus++', native: true)
123    sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson', native: true)
124endif
125
126cereal_dep = dependency('cereal', required: false)
127has_cereal = cpp.has_header_symbol(
128    'cereal/cereal.hpp',
129    'cereal::specialize',
130    dependencies: cereal_dep,
131    required: false)
132if not has_cereal
133    cereal_opts = import('cmake').subproject_options()
134    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
135    cereal_proj = import('cmake').subproject(
136        'cereal',
137        options: cereal_opts,
138        required: false)
139    assert(cereal_proj.found(), 'cereal is required')
140    cereal_dep = cereal_proj.dependency('cereal')
141endif
142
143deps = [
144    dependency(
145        'phosphor-dbus-interfaces',
146        fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep'],
147    ),
148    dependency(
149        'phosphor-logging',
150        fallback: ['phosphor-logging', 'phosphor_logging_dep'],
151    ),
152    sdbusplus_dep,
153    cereal_dep,
154]
155
156ssl = dependency('openssl')
157
158systemd = dependency('systemd')
159systemd_system_unit_dir = systemd.get_variable(pkgconfig : 'systemdsystemunitdir')
160
161unit_files = [
162    'obmc-flash-bmc-setenv@.service.in',
163    'reboot-guard-disable.service.in',
164    'reboot-guard-enable.service.in',
165    'force-reboot.service.in',
166    'usr-local.mount.in',
167    'xyz.openbmc_project.Software.BMC.Updater.service.in',
168    'xyz.openbmc_project.Software.Download.service.in',
169    'xyz.openbmc_project.Software.Sync.service.in',
170    'xyz.openbmc_project.Software.Version.service.in'
171]
172
173subdir('xyz/openbmc_project/Software/Image')
174
175image_updater_sources = files(
176    'activation.cpp',
177    'images.cpp',
178    'item_updater.cpp',
179    'item_updater_main.cpp',
180    'serialize.cpp',
181    'version.cpp',
182    'utils.cpp',
183    'msl_verify.cpp'
184)
185
186if get_option('bmc-layout').contains('static')
187    image_updater_sources += files(
188        'static/flash.cpp',
189        'static/item_updater_helper.cpp'
190    )
191elif get_option('bmc-layout').contains('ubi')
192    image_updater_sources += files(
193        'ubi/flash.cpp',
194        'ubi/item_updater_helper.cpp'
195    )
196
197    unit_files += [
198        'ubi/obmc-flash-bmc-cleanup.service.in',
199        'ubi/obmc-flash-bmc-mirroruboot.service.in',
200        'ubi/obmc-flash-bmc-ubiremount.service.in',
201        'ubi/obmc-flash-bmc-ubiro@.service.in',
202        'ubi/obmc-flash-bmc-ubiro-remove@.service.in',
203        'ubi/obmc-flash-bmc-ubirw.service.in',
204        'ubi/obmc-flash-bmc-ubirw-remove.service.in',
205        'ubi/obmc-flash-bmc-updateubootvars@.service.in'
206    ]
207elif get_option('bmc-layout').contains('mmc')
208    image_updater_sources += files(
209        'mmc/flash.cpp',
210        'mmc/item_updater_helper.cpp'
211    )
212
213    unit_files += [
214        'mmc/obmc-flash-mmc@.service.in',
215        'mmc/obmc-flash-mmc-mount.service.in',
216        'mmc/obmc-flash-mmc-remove@.service.in',
217        'mmc/obmc-flash-mmc-setprimary@.service.in',
218        'mmc/obmc-flash-mmc-umount.service.in',
219    ]
220endif
221
222if get_option('host-bios-upgrade').enabled()
223    unit_files += 'obmc-flash-host-bios@.service.in'
224endif
225
226if get_option('bmc-static-dual-image').enabled()
227    unit_files += [
228        'static/obmc-flash-bmc-static-mount-alt.service.in',
229        'static/obmc-flash-bmc-prepare-for-sync.service.in',
230    ]
231endif
232
233if get_option('sync-bmc-files').enabled()
234    executable(
235        'phosphor-sync-software-manager',
236        'sync_manager.cpp',
237        'sync_manager_main.cpp',
238        'sync_watch.cpp',
239        dependencies: deps,
240        install: true
241    )
242
243    install_data('synclist',
244        install_dir:  get_option('sysconfdir')
245    )
246
247    install_data('sync-once.sh',
248        install_mode: 'rwxr-xr-x',
249        install_dir: get_option('bindir')
250    )
251endif
252
253if (get_option('verify-signature').enabled() or \
254    get_option('verify-full-signature').enabled())
255    image_updater_sources += files(
256        'utils.cpp',
257        'image_verify.cpp',
258        'openssl_alloc.cpp'
259    )
260endif
261
262executable(
263    'phosphor-download-manager',
264    'download_manager.cpp',
265    'download_manager_main.cpp',
266    dependencies: deps,
267    install: true
268)
269
270executable(
271    'phosphor-image-updater',
272    image_error_cpp,
273    image_error_hpp,
274    image_updater_sources,
275    dependencies: [deps, ssl],
276    install: true
277)
278
279executable(
280    'phosphor-version-software-manager',
281    image_error_cpp,
282    image_error_hpp,
283    'image_manager.cpp',
284    'image_manager_main.cpp',
285    'version.cpp',
286    'watch.cpp',
287    dependencies: [deps, ssl],
288    install: true
289)
290
291install_data('obmc-flash-bmc',
292    install_mode: 'rwxr-xr-x',
293    install_dir: get_option('bindir')
294)
295
296install_data('detect-slot-aspeed',
297    install_mode: 'rwxr-xr-x',
298    install_dir: get_option('bindir')
299)
300
301install_data('software.conf',
302    install_dir: '/usr/lib/tmpfiles.d/'
303)
304
305foreach u : unit_files
306    configure_file(
307        input: u,
308        output: '@BASENAME@',
309        configuration: conf,
310        install: true,
311        install_dir: systemd_system_unit_dir,
312    )
313endforeach
314
315# If test coverage of source files within the root directory are wanted,
316# need to define and build the tests from here
317build_tests = get_option('tests')
318if not build_tests.disabled()
319    oe_sdk = get_option('oe-sdk')
320    if oe_sdk.enabled()
321        # Setup OE SYSROOT
322        OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
323        if OECORE_TARGET_SYSROOT == ''
324            error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
325        endif
326        message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
327        rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
328        ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
329        dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
330    else
331        dynamic_linker = []
332    endif
333
334    gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
335    include_srcs = declare_dependency(sources: [
336        'utils.cpp',
337        'image_verify.cpp',
338        'images.cpp',
339        'version.cpp']
340    )
341
342    test('utest',
343        executable(
344            'utest',
345            './test/utest.cpp',
346            link_args: dynamic_linker,
347            build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
348            dependencies: [deps, gtest, include_srcs, ssl]
349        )
350)
351endif
352
353if get_option('usb-code-update').enabled()
354    subdir('usb')
355endif
356