Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch-axel-10] improve CPIO creation flexibility #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions cmake-tool/helpers/application_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include_guard(GLOBAL)
function(ApplyData61ElfLoaderSettings kernel_platform kernel_sel4_arch)
set(
binary_list
"tx1;hikey;odroidc2;odroidc4;imx8mq-evk;imx8mm-evk;hifive;tqma8xqp1gb;bcm2711;rocketchip"
"tx1;hikey;odroidc2;odroidc4;imx8mq-evk;imx8mm-evk;imx8mp-evk;hifive;tqma8xqp1gb;bcm2711;rocketchip;star64"
)
set(efi_list "tk1;rockpro64;quartz64")
set(uimage_list "tx2;am335x")
Expand All @@ -36,9 +36,12 @@ function(ApplyData61ElfLoaderSettings kernel_platform kernel_sel4_arch)
set(ElfloaderMode "hypervisor" CACHE STRING "" FORCE)
set(ElfloaderMonitorHook ON CACHE BOOL "" FORCE)
endif()
if((KernelPlatformImx8mm-evk OR KernelPlatImx8mq) AND KernelSel4ArchAarch32)
if(
(KernelPlatformImx8mm-evk OR KernelPlatImx8mq OR KernelPlatformImx8mp-evk)
AND KernelSel4ArchAarch32
)
set(ElfloaderArmV8LeaveAarch64 ON CACHE BOOL "" FORCE)
# This applies to imx8mm, imx8mq (EVK and MaaXBoard) when in aarch32 configuration
# This applies to imx8mm, imx8mq (EVK and MaaXBoard), imx8mp when in aarch32 configuration
# It should be possible to use a uimage format but when tried nothing
# runs after uboot.
set(IMAGE_START_ADDR 0x41000000 CACHE INTERNAL "" FORCE)
Expand All @@ -59,6 +62,9 @@ function(ApplyData61ElfLoaderSettings kernel_platform kernel_sel4_arch)
endif()
set(IMAGE_START_ADDR 0x10000000 CACHE INTERNAL "" FORCE)
endif()
if(KernelPlatformStar64)
set(IMAGE_START_ADDR 0x60000000 CACHE INTERNAL "" FORCE)
endif()
endfunction()

function(ApplyCommonSimulationSettings kernel_sel4_arch)
Expand Down
111 changes: 82 additions & 29 deletions cmake-tool/helpers/cpio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,101 @@ function(MakeCPIO output_name input_files)
if(NOT "${MAKE_CPIO_UNPARSED_ARGUMENTS}" STREQUAL "")
message(FATAL_ERROR "Unknown arguments to MakeCPIO")
endif()

set(archive_symbol "_cpio_archive")
if(NOT "${MAKE_CPIO_CPIO_SYMBOL}" STREQUAL "")
set(archive_symbol ${MAKE_CPIO_CPIO_SYMBOL})
endif()
# Check that the reproducible flag is available. Don't use it if it isn't.

set(cpio_archive "${output_name}.cpio")

# CMake wants absolute paths when calling file(WRITE ...)
get_filename_component(
output_name_abs
"${output_name}"
ABSOLUTE
BASE_DIR
"${CMAKE_CURRENT_BINARY_DIR}"
)

# Create a script that prepares CPIO archive contents in a tmp folder and
# then builds the archive. Some cpio versions support the paramter
# "--reproducible" to create the archive with consistent inodes and device
# numbering. In addition, we set each file's the 'modified time' to the
# epoch (ie 0, but simply using 'touch -d @0' is a GNU extension of the
# POSIX standard), and the user/group values to 0:0.
# Since some application access the archive contents by index and not by
# name, the files must be put into the archive in exactly the same order as
# they are listen in 'input_files'. Using simply "ls | cpio ...." instead of
# "printf '%s\\n' \${@##*/} | cpio ..." does not guarantee preserving the
# order.
CheckCPIOArgument(cpio_reproducible_flag "--reproducible")
set(
commands
"bash;-c;cpio ${cpio_reproducible_flag} --quiet --create -H newc --file=${CMAKE_CURRENT_BINARY_DIR}/archive.${output_name}.cpio;&&"
set(cpio_archive_creator "${output_name_abs}.sh")
file(
WRITE
"${cpio_archive_creator}"
# content
"#!/bin/sh\n"
"# auto-generated file from MakeCPIO(), do not edit\n"
"set -e\n"
"TMP_DIR=${cpio_archive}.files\n"
"mkdir -p \${TMP_DIR}\n"
"cp -a \"$@\" \${TMP_DIR}/\n"
"touch -d 1970-01-01T00:00:00Z \${TMP_DIR}/*\n"
"(\n"
" cd \${TMP_DIR}\n"
" printf '%s\\n' \${@##*/} | cpio ${cpio_reproducible_flag} --quiet --create --format=newc --owner=+0:+0\n"
") > ${cpio_archive}\n"
"rm -rf \${TMP_DIR}\n"
)
foreach(file IN LISTS input_files)
# Try and generate reproducible cpio meta-data as we do this:
# - touch -d @0 file sets the modified time to 0
# - --owner=root:root sets user and group values to 0:0
# - --reproducible creates reproducible archives with consistent inodes and device numbering
list(
APPEND
commands
"bash;-c; mkdir -p temp_${output_name} && cd temp_${output_name} && cp -a ${file} . && touch -d 1970-01-01T00:00:00Z `basename ${file}` && echo `basename ${file}` | cpio --append ${cpio_reproducible_flag} --owner=+0:+0 --quiet -o -H newc --file=${CMAKE_CURRENT_BINARY_DIR}/archive.${output_name}.cpio && rm `basename ${file}` && cd ../ && rmdir temp_${output_name};&&"
)
endforeach()
list(APPEND commands "true")

# Create a "program" that makes the compiler generate and object file that
# contains the cpio archive.
# CMake wants the absolute name when creating files
set(cpio_archive_s "${output_name_abs}.S")
file(
WRITE
"${cpio_archive_s}"
# content
"# auto-generated file from MakeCPIO(), do not edit\n"
".section ._archive_cpio, \"aw\"\n"
".globl ${archive_symbol}, ${archive_symbol}_end\n"
"${archive_symbol}:\n"
".incbin \"${cpio_archive}\"\n"
"${archive_symbol}_end:\n"
)

# Re-run CMake configuration in case 'cpio_archive_creator' or
# 'cpio_archive_s' is deleted.
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS "${cpio_archive_creator}" "${cpio_archive_s}"
)

# The 'cpio_archive' is no explicit parameter for the command, because it is
# hard-coded already in the specific script we have generated above. The
# 'input_files' are explicit here, because they are a CMake list that
# will be converted to parameters for the invokation,
add_custom_command(
OUTPUT ${cpio_archive}
COMMAND bash "${cpio_archive_creator}" ${input_files}
DEPENDS "${cpio_archive_creator}" ${input_files} ${MAKE_CPIO_DEPENDS}
COMMENT "Generate CPIO archive ${cpio_archive}"
)

separate_arguments(cmake_c_flags_sep NATIVE_COMMAND "${CMAKE_C_FLAGS}")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
list(APPEND cmake_c_flags_sep "${CMAKE_C_COMPILE_OPTIONS_TARGET}${CMAKE_C_COMPILER_TARGET}")
endif()

# The 'cpio_archive' is no explicit parameter for the command, because it is
# hard-coded already in the specific 'cpio_archive_s' file we have generated
# above.
add_custom_command(
OUTPUT ${output_name}
COMMAND rm -f archive.${output_name}.cpio
COMMAND ${commands}
COMMAND
sh -c
"echo 'X.section ._archive_cpio,\"aw\"X.globl ${archive_symbol}, ${archive_symbol}_endX${archive_symbol}:X.incbin \"archive.${output_name}.cpio\"X${archive_symbol}_end:X' | tr X '\\n'"
> ${output_name}.S
COMMAND
${CMAKE_C_COMPILER} ${cmake_c_flags_sep} -c -o ${output_name} ${output_name}.S
DEPENDS ${input_files} ${MAKE_CPIO_DEPENDS}
VERBATIM
BYPRODUCTS
archive.${output_name}.cpio
${output_name}.S
${CMAKE_C_COMPILER} ${cmake_c_flags_sep} -c -o "${output_name}" "${cpio_archive_s}"
DEPENDS "${cpio_archive_creator}" "${cpio_archive_s}" "${cpio_archive}"
COMMENT "Generate CPIO archive ${output_name}"
)
endfunction(MakeCPIO)
1 change: 0 additions & 1 deletion misc/astylerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# SPDX-License-Identifier: BSD-2-Clause
#

max-instatement-indent=120
style=otbs
pad-header
indent=spaces=4
Expand Down