Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/build-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# fail immediately on any errors
set -e

SOF_TOP=$(cd "$(dirname "$0")/.." && pwd)
export ALSA_CONFIG_DIR="${SOF_TOP}"/tools/topology/topology2

print_usage()
{
cat <<EOFUSAGE
Expand Down
11 changes: 11 additions & 0 deletions tools/topology/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ macro(add_alsatplg_command)
)
endmacro()

macro(add_alsatplg2_command)
add_custom_command(
MAIN_DEPENDENCY ${ARGV0}
OUTPUT ${ARGV1}
# -p to pre-process Topology2.0 conf file
COMMAND alsatplg \$\${VERBOSE:+-v 1} -I ${ARGV2} -D ${ARGV3} -p -c ${ARGV0} -o ${ARGV1}
USES_TERMINAL
)
endmacro()


add_custom_target(topologies ALL)
add_dependencies(topologies topologies1)

add_subdirectory(topology1)
add_subdirectory(topology2)
32 changes: 32 additions & 0 deletions tools/topology/topology2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-License-Identifier: BSD-3-Clause
add_custom_target(topologies2
COMMAND ${CMAKE_COMMAND} -E copy_directory cavs ${SOF_TOPOLOGY_BINARY_DIRECTORY}
)

# generate ABI
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/get_abi.sh ${SOF_ROOT_SOURCE_DIRECTORY}
OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/abi.conf
)

# check alsatplg version and built topology2 if alsatplg version is 1.2.6 or greater
# This will override any common topologies built with topology1
execute_process(COMMAND alsatplg --version RESULT_VARIABLE STATUS OUTPUT_VARIABLE ALSA_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
if(STATUS AND NOT STATUS EQUAL 0)
message(WARNING "alsatplg error: ${STATUS}, topology2 will be skipped")
else()
string(REPLACE "\n" ";" ALSA_VERSION_LIST ${ALSA_VERSION})
list(GET ALSA_VERSION_LIST 0 ALSATPLG_VERSION)
string(REGEX MATCH "[0-9]\.[0-9]\.*[0-9]*" ALSATPLG_VERSION_NUMBER ${ALSATPLG_VERSION})
if(${ALSATPLG_VERSION_NUMBER} VERSION_LESS "1.2.6")
message(WARNING "topology2 will be skipped. Minimum required version for alsatplg: 1.2.6")
else()
add_dependencies(topologies topologies2)

# make sure topology1 always builds first so that the installed binaries from v2 override the ones from v1
add_dependencies(topologies2 topologies1)

endif()
endif()

add_subdirectory(cavs)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to omit the entire subdirectory, instead omit only the edge in the dependency graph and don't add this target to the default ALL target. In other words, only this line needs to be conditional:

add_dependencies(topologies2 topology2_cavs)

So everyone is aligned and runs the exact same CMake code at configuration time no matter what their ALSA version is. The difference comes later only at build time.

This is also more flexible for any adventurer who has multiple ALSA versions installed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but as far as topology2 goes everything in the topology2 folder should be conditionally built based on version right? its not just topology2_cavs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorry, hasty review and copy/paste. The point is to use a scalpel to conditionally cut only the topology2 dependency in the graph, then all v2 dependency "leaves" will be configured and available but not built by default.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this look good?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, instead of return() here use:

add_dependencies(ALL topologies2)

+ remove ALL above

43 changes: 43 additions & 0 deletions tools/topology/topology2/cavs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-License-Identifier: BSD-3-Clause

# Array of "input-file-name;output-file-name;comma separated pre-processor variables"
set(TPLGS
# CAVS HDMI only topology with passthrough pipelines
"cavs-passthrough-hdmi\;cavs-passthrough-hdmi"
# CAVS HDA topology with passthrough pipelines
"cavs-passthrough-hdmi\;cavs-passthrough-hda\;HDA_CONFIG=passthrough"
# CAVS HDMI only topology with gain-based pipelines
"cavs-gain-hdmi\;cavs-gain-hdmi"
# CAVS HDA topology with gain-based pipelines
"cavs-gain-hdmi\;cavs-gain-hda\;HDA_CONFIG=gain"
# CAVS HDA topology with mixer-based pipelines
"cavs-passthrough-hdmi\;cavs-mixin-mixout-hda\;HDA_CONFIG=mix"
)

# This will override the topology1 binaries with topology2 binaries
add_custom_target(topology2_cavs)
add_dependencies(topologies2 topology2_cavs)

foreach(tplg ${TPLGS})
set(defines "")
list(LENGTH tplg length)
list(GET tplg 0 input)
list(GET tplg 1 output)

math(EXPR last_index "${length}-1")

# Get the pre-processor definitions from the 3rd item in the list for each topology
# ex: "hda-generic\;hda-generic-2ch\;HDA_CONFIG=gain,DMIC_CH=2", "defines" would contain "HDA_CONFIG=gain,DMIC_CH=2"
if (${last_index} EQUAL 2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would GREATER be more future-proof?

Suggested change
if (${last_index} EQUAL 2)
if (${length} GREATER 2)
math(EXPR last_index "${length}-1")

In any case I think testing ${length} would be slightly more readable.

list(GET tplg ${last_index} defines)
Comment thread
ranj063 marked this conversation as resolved.
Outdated
endif()

# copy ABI and input conf file contents
configure_file(${CMAKE_CURRENT_BINARY_DIR}/../abi.conf ${CMAKE_CURRENT_BINARY_DIR}/${output}.conf)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/${input}.conf CONTENTS)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${output}.conf "${CONTENTS}")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general ${CMAKE_CURRENT_BINARY_DIR} is not required. You haven't used it below. Quick enough to try.


add_alsatplg2_command(${output}.conf ${output}.tplg ${CMAKE_CURRENT_SOURCE_DIR} ${defines})
add_custom_target(topology2_${output} DEPENDS ${output}.tplg)
add_dependencies(topology2_cavs topology2_${output})
endforeach()
16 changes: 16 additions & 0 deletions tools/topology/topology2/get_abi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2019 Intel Corporation. All rights reserved.
set -e

ABI_MAJOR=$(awk '/^ *# *define *SOF_ABI_MAJOR / { print $3 }' $1/src/include/kernel/abi.h)
ABI_MINOR=$(awk '/^ *# *define *SOF_ABI_MINOR / { print $3 }' $1/src/include/kernel/abi.h)
ABI_PATCH=$(awk '/^ *# *define *SOF_ABI_PATCH / { print $3 }' $1/src/include/kernel/abi.h)

cat <<EOF_HEADER
Object.Base.manifest."sof_manifest" {
Object.Base.data."SOF ABI" {
EOF_HEADER
printf '\t\tbytes\t"0x%02x,' "$ABI_MAJOR"
printf "0x%02x," "$ABI_MINOR"
printf '0x%02x\"\n\t}\n}' "$ABI_PATCH"