1project('phosphor-bmc-code-mgmt', 'cpp',
2    default_options: [
3        'buildtype=debugoptimized',
4        'cpp_std=c++17',
5        'warning_level=3',
6        'werror=true'
7    ],
8    license: 'Apache-2.0',
9    version: '1.0')
10
11conf = configuration_data()
12
13# DBus information
14conf.set_quoted('BMC_INVENTORY_INTERFACE', 'xyz.openbmc_project.Inventory.Item.Bmc')
15conf.set_quoted('BUSNAME_UPDATER', 'xyz.openbmc_project.Software.BMC.Updater')
16conf.set_quoted('DOWNLOAD_BUSNAME', 'xyz.openbmc_project.Software.Download')
17conf.set_quoted('FILEPATH_IFACE', 'xyz.openbmc_project.Common.FilePath')
18conf.set_quoted('INVENTORY_PATH', '/xyz/openbmc_project/inventory/')
19conf.set_quoted('MAPPER_BUSNAME', 'xyz.openbmc_project.ObjectMapper')
20conf.set_quoted('MAPPER_INTERFACE', 'xyz.openbmc_project.ObjectMapper')
21conf.set_quoted('MAPPER_PATH', '/xyz/openbmc_project/object_mapper')
22conf.set_quoted('SOFTWARE_OBJPATH', '/xyz/openbmc_project/software')
23conf.set_quoted('SYSTEMD_BUSNAME', 'org.freedesktop.systemd1')
24conf.set_quoted('SYSTEMD_PATH', '/org/freedesktop/systemd1')
25conf.set_quoted('SYSTEMD_INTERFACE', 'org.freedesktop.systemd1.Manager')
26conf.set_quoted('VERSION_BUSNAME', 'xyz.openbmc_project.Software.Version')
27conf.set_quoted('VERSION_IFACE', 'xyz.openbmc_project.Software.Version')
28
29# Names of the forward and reverse associations
30conf.set_quoted('ACTIVATION_FWD_ASSOCIATION', 'inventory')
31conf.set_quoted('ACTIVATION_REV_ASSOCIATION', 'activation')
32conf.set_quoted('ACTIVE_FWD_ASSOCIATION', 'active')
33conf.set_quoted('ACTIVE_REV_ASSOCIATION', 'software_version')
34conf.set_quoted('FUNCTIONAL_FWD_ASSOCIATION', 'functional')
35conf.set_quoted('FUNCTIONAL_REV_ASSOCIATION', 'software_version')
36conf.set_quoted('UPDATEABLE_FWD_ASSOCIATION', 'updateable')
37conf.set_quoted('UPDATEABLE_REV_ASSOCIATION', 'software_version')
38
39# Filesystem files and directories
40# The path of the alt rwfs overlay
41conf.set_quoted('ALT_RWFS', '/media/alt/var/persist')
42# The prefix path for the versioned read-only bmc partitions
43conf.set_quoted('BMC_ROFS_PREFIX', get_option('media-dir') + '/rofs-')
44# The name of the BMC table of contents file
45conf.set_quoted('OS_RELEASE_FILE', '/etc/os-release')
46# The dir where activation data is stored in files
47conf.set_quoted('PERSIST_DIR', '/var/lib/phosphor-bmc-code-mgmt/')
48
49# Supported BMC layout types
50conf.set('STATIC_LAYOUT', get_option('bmc-layout').contains('static'))
51conf.set('UBIFS_LAYOUT', get_option('bmc-layout').contains('ubi'))
52conf.set('MMC_LAYOUT', get_option('bmc-layout').contains('mmc'))
53
54# Configurable features
55conf.set('HOST_BIOS_UPGRADE', get_option('host-bios-upgrade').enabled())
56conf.set('WANT_SIGNATURE_VERIFY', get_option('verify-signature').enabled())
57conf.set('WANT_SIGNATURE_FULL_VERIFY', get_option('verify-full-signature').enabled())
58
59# Configurable variables
60conf.set('ACTIVE_BMC_MAX_ALLOWED', get_option('active-bmc-max-allowed'))
61conf.set_quoted('HASH_FILE_NAME', get_option('hash-file-name'))
62conf.set_quoted('IMG_UPLOAD_DIR', get_option('img-upload-dir'))
63conf.set_quoted('MANIFEST_FILE_NAME', get_option('manifest-file-name'))
64conf.set_quoted('MEDIA_DIR', get_option('media-dir'))
65optional_array = get_option('optional-images')
66optional_images = ''
67foreach optiona_image : optional_array
68    optional_images = ' '.join([optional_images, optiona_image])
69endforeach
70conf.set_quoted('OPTIONAL_IMAGES', optional_images)
71conf.set_quoted('PUBLICKEY_FILE_NAME', get_option('publickey-file-name'))
72conf.set_quoted('SIGNATURE_FILE_EXT', get_option('signature-file-ext'))
73conf.set_quoted('SIGNED_IMAGE_CONF_PATH', get_option('signed-image-conf-path'))
74conf.set_quoted('SYNC_LIST_DIR_PATH', get_option('sync-list-dir-path'))
75conf.set_quoted('SYNC_LIST_FILE_NAME', get_option('sync-list-file-name'))
76conf.set_quoted('BMC_MSL', get_option('bmc-msl'))
77conf.set_quoted('REGEX_BMC_MSL', get_option('regex-bmc-msl'))
78
79
80configure_file(output: 'config.h', configuration: conf)
81
82deps = [
83    dependency('phosphor-dbus-interfaces'),
84    dependency('phosphor-logging'),
85    dependency('sdbusplus')
86]
87
88ssl = dependency('openssl')
89
90systemd = dependency('systemd')
91systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
92
93unit_files = [
94    'obmc-flash-bmc-setenv@.service.in',
95    'reboot-guard-disable.service.in',
96    'reboot-guard-enable.service.in',
97    'force-reboot.service.in',
98    'usr-local.mount.in',
99    'xyz.openbmc_project.Software.BMC.Updater.service.in',
100    'xyz.openbmc_project.Software.Download.service.in',
101    'xyz.openbmc_project.Software.Sync.service.in',
102    'xyz.openbmc_project.Software.Version.service.in'
103]
104
105sdbuspp = find_program('sdbus++')
106subdir('xyz/openbmc_project/Software/Image')
107
108image_updater_sources = files(
109    'activation.cpp',
110    'images.cpp',
111    'item_updater.cpp',
112    'item_updater_main.cpp',
113    'serialize.cpp',
114    'version.cpp',
115    'utils.cpp',
116    'msl_verify.cpp'
117)
118
119if get_option('bmc-layout').contains('static')
120    image_updater_sources += files(
121        'static/flash.cpp',
122        'static/item_updater_helper.cpp'
123    )
124elif get_option('bmc-layout').contains('ubi')
125    image_updater_sources += files(
126        'ubi/flash.cpp',
127        'ubi/item_updater_helper.cpp'
128    )
129
130    unit_files += [
131        'ubi/obmc-flash-bmc-cleanup.service.in',
132        'ubi/obmc-flash-bmc-mirroruboot.service.in',
133        'ubi/obmc-flash-bmc-ubiremount.service.in',
134        'ubi/obmc-flash-bmc-ubiro@.service.in',
135        'ubi/obmc-flash-bmc-ubiro-remove@.service.in',
136        'ubi/obmc-flash-bmc-ubirw.service.in',
137        'ubi/obmc-flash-bmc-ubirw-remove.service.in',
138        'ubi/obmc-flash-bmc-updateubootvars@.service.in'
139    ]
140elif get_option('bmc-layout').contains('mmc')
141    image_updater_sources += files(
142        'mmc/flash.cpp',
143        'mmc/item_updater_helper.cpp'
144    )
145
146    unit_files += [
147        'mmc/obmc-flash-mmc@.service.in',
148        'mmc/obmc-flash-mmc-mount.service.in',
149        'mmc/obmc-flash-mmc-remove@.service.in',
150        'mmc/obmc-flash-mmc-setprimary@.service.in',
151        'mmc/obmc-flash-mmc-umount.service.in',
152    ]
153endif
154
155if get_option('host-bios-upgrade').enabled()
156    unit_files += 'obmc-flash-host-bios@.service.in'
157endif
158
159if get_option('sync-bmc-files').enabled()
160    executable(
161        'phosphor-sync-software-manager',
162        'sync_manager.cpp',
163        'sync_manager_main.cpp',
164        'sync_watch.cpp',
165        dependencies: deps,
166        install: true
167    )
168
169    install_data('synclist',
170        install_dir:  get_option('sysconfdir')
171    )
172endif
173
174if get_option('verify-signature').enabled()
175    image_updater_sources += files(
176        'utils.cpp',
177        'image_verify.cpp',
178        'openssl_alloc.cpp'
179    )
180endif
181
182executable(
183    'phosphor-download-manager',
184    'download_manager.cpp',
185    'download_manager_main.cpp',
186    dependencies: deps,
187    install: true
188)
189
190executable(
191    'phosphor-image-updater',
192    image_error_cpp,
193    image_error_hpp,
194    image_updater_sources,
195    dependencies: [deps, ssl],
196    install: true
197)
198
199executable(
200    'phosphor-version-software-manager',
201    image_error_cpp,
202    image_error_hpp,
203    'image_manager.cpp',
204    'image_manager_main.cpp',
205    'version.cpp',
206    'watch.cpp',
207    dependencies: [deps, ssl],
208    install: true
209)
210
211install_data('obmc-flash-bmc',
212    install_mode: 'rwxr-xr-x',
213    install_dir: get_option('bindir')
214)
215
216install_data('software.conf',
217    install_dir: '/usr/lib/tmpfiles.d/'
218)
219
220foreach u : unit_files
221    configure_file(
222        input: u,
223        output: '@BASENAME@',
224        configuration: conf,
225        install: true,
226        install_dir: systemd_system_unit_dir,
227    )
228endforeach
229
230# If test coverage of source files within the root directory are wanted,
231# need to define and build the tests from here
232build_tests = get_option('tests')
233if not build_tests.disabled()
234    oe_sdk = get_option('oe-sdk')
235    if oe_sdk.enabled()
236        # Setup OE SYSROOT
237        OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
238        if OECORE_TARGET_SYSROOT == ''
239            error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
240        endif
241        message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
242        rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
243        ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
244        dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
245    else
246        dynamic_linker = []
247    endif
248
249    gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
250    include_srcs = declare_dependency(sources: [
251        'utils.cpp',
252        'image_verify.cpp',
253        'images.cpp',
254        'version.cpp']
255    )
256
257    test('utest',
258        executable(
259            'utest',
260            './test/utest.cpp',
261            link_args: dynamic_linker,
262            build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
263            dependencies: [deps, gtest, include_srcs, ssl]
264        )
265)
266endif
267