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