blob: 07719f78ee9fb1f931f59ad3e9f1d05828523f72 [file] [log] [blame]
--
-- Copyright 2023 Google LLC
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
set_project("CHERIoT soundstream demo")
local shodan_dir = os.getenv("ROOTDIR")
if shodan_dir == nil or shodan_dir == '' then
raise("ROOTDIR not set")
end
local cheriot_out_dir = os.getenv("CHERIOT_OUT_DIR")
if cheriot_out_dir == nil or cheriot_out_dir == '' then
raise("CHERIOT_OUT_DIR not set")
end
local sdkdir = path.join(shodan_dir, "sw/cheriot-rtos/sdk")
includes(sdkdir)
set_toolchains("cheriot-clang")
option("board")
set_default("sencha")
local matcha_dir = path.join(shodan_dir, "hw/matcha")
local matcha_lib_dir = path.join(matcha_dir, "sw/device/lib")
local dif_dir = path.join(matcha_lib_dir, "dif")
local dif_autogen_dir = path.join(dif_dir, "autogen")
local opentitan_dir = path.join(shodan_dir, "hw/opentitan-upstream")
local opentitan_lib_dir = path.join(opentitan_dir, "sw/device/lib")
local opentitan_base_dir = path.join(opentitan_lib_dir, "base")
local opentitan_dif_dir = path.join(opentitan_lib_dir, "dif")
local opentitan_dif_autogen_dir = path.join(opentitan_dif_dir, "autogen")
local opentitan_runtime_dir = path.join(opentitan_lib_dir, "runtime")
local opentitan_silicon_dir = path.join(opentitan_dir, "sw/device/silicon_creator/lib")
local opentitan_silicon_drivers_dir = path.join(opentitan_silicon_dir, "drivers")
local opentitan_silicon_base_dir = path.join(opentitan_silicon_dir, "base")
local matcha_gen_dir = path.join(cheriot_out_dir, "opentitan-gen/include/opentitan")
-- Support libraries
includes(path.join(sdkdir, "lib"))
includes(path.join(sdkdir, "lib/freestanding"))
local function is_bancha()
return is_config("board", "bancha")
end
local function is_sencha()
return is_config("board", "sencha")
end
-- Each driver operates in a compartment.
compartment("i2s")
add_files("i2s.cc")
add_files(path.join(dif_dir, "dif_i2s.c"),
path.join(dif_autogen_dir, "dif_i2s_autogen.c"))
add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir)
add_defines("CHERIOT_NO_AMBIENT_MALLOC")
if is_sencha() then
compartment("mailbox")
add_files("mailbox.cc")
add_files(path.join(dif_dir, "dif_tlul_mailbox.c"),
path.join(dif_autogen_dir, "dif_tlul_mailbox_autogen.c"))
add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir)
add_defines("CHERIOT_NO_AMBIENT_MALLOC")
end
compartment("ml_top")
add_files("ml_top.cc")
add_files(path.join(dif_dir, "dif_ml_top.c"),
path.join(dif_autogen_dir, "dif_ml_top_autogen.c"))
add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir)
add_defines("CHERIOT_NO_AMBIENT_MALLOC")
if is_bancha() then
compartment("spi")
add_files("spi.cc")
add_files(path.join(matcha_lib_dir, "spi_flash.c"),
path.join(matcha_lib_dir, "eflash.c"),
path.join(opentitan_dif_dir, "dif_flash_ctrl.c"),
path.join(opentitan_dif_autogen_dir, "dif_flash_ctrl_autogen.c"),
path.join(opentitan_lib_dir, "testing/flash_ctrl_testutils.c"),
path.join(opentitan_silicon_base_dir, "sec_mmio.c"),
path.join(opentitan_silicon_drivers_dir, "flash_ctrl.c"),
path.join(opentitan_silicon_drivers_dir, "otp.c"),
path.join(matcha_lib_dir, "arch/device_sc_fpga_nexus.c"),
path.join(opentitan_dif_dir, "dif_spi_host.c"),
path.join(opentitan_dif_autogen_dir, "dif_spi_host_autogen.c"),
path.join(opentitan_base_dir, "status.c"),
path.join(opentitan_lib_dir, "testing/test_framework/status.c"),
path.join(opentitan_runtime_dir, "log.c"),
path.join(opentitan_runtime_dir, "print.c"))
add_includedirs(matcha_dir, matcha_gen_dir)
add_includedirs(opentitan_dir)
add_defines("CHERIOT_NO_AMBIENT_MALLOC")
end
-- Soundstream application.
compartment("soundstream")
add_files("soundstream.cc", "encode.cc")
add_files(path.join(matcha_dir, "hw/top_matcha/sw/autogen/top_matcha.c"));
add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir)
add_defines("CHERIOT_NO_AMBIENT_MALLOC")
-- Firmware image.
firmware("soundstream-firmware")
add_deps("i2s", "ml_top")
if is_sencha() then
add_deps("mailbox")
end
if is_bancha() then
add_deps("spi", "string")
end
add_deps("soundstream")
add_deps("freestanding", "debug")
on_load(function(target)
target:values_set("board", "$(board)")
-- NB: trusted_stack_frames is a guess; +1'd for any
-- compartment error handler usage?
local threads = {
{
compartment = "soundstream",
priority = 1,
entry_point = "entry",
stack_size = 0x1000, -- 4KB
trusted_stack_frames = 5
},
-- NB: stack sizes bumped for logging
{
compartment = "i2s",
priority = 10,
entry_point = "i2s_isr",
stack_size = 0x400, -- 512B
trusted_stack_frames = 3
},
{
compartment = "ml_top",
priority = 10,
entry_point = "ml_top_isr",
stack_size = 0x400, -- 512B
trusted_stack_frames = 3
},
}
if is_sencha() then
table.insert(threads, {
compartment = "mailbox",
priority = 10,
entry_point = "mailbox_isr",
stack_size = 0x400, -- 512B
trusted_stack_frames = 3
})
end
target:values_set("threads", threads, {expand = false})
end)