From bb92fe0ed5eedc447294769cc2666a80c0d97de1 Mon Sep 17 00:00:00 2001 From: Alice Ziuziakowska Date: Thu, 21 May 2026 11:30:20 +0100 Subject: [PATCH] sw: add U-boot build system integration bison and flex are required in the Nix environment too Signed-off-by: Alice Ziuziakowska --- flake.nix | 2 ++ sw/CMakeLists.txt | 1 + sw/cmake/uboot.cmake | 59 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 sw/cmake/uboot.cmake diff --git a/flake.nix b/flake.nix index c6c885734..c59304bdb 100644 --- a/flake.nix +++ b/flake.nix @@ -73,7 +73,9 @@ ftditool-cli = inputs.ftditool.packages.${system}.default; commonPackages = with pkgs; [ + bison cmake + flex gnumake screen picocom diff --git a/sw/CMakeLists.txt b/sw/CMakeLists.txt index 4896fc9a9..0ad6d6e7b 100644 --- a/sw/CMakeLists.txt +++ b/sw/CMakeLists.txt @@ -20,3 +20,4 @@ include(ExternalProject) add_subdirectory(device) include(cmake/opensbi.cmake) +include(cmake/uboot.cmake) diff --git a/sw/cmake/uboot.cmake b/sw/cmake/uboot.cmake new file mode 100644 index 000000000..577ab1580 --- /dev/null +++ b/sw/cmake/uboot.cmake @@ -0,0 +1,59 @@ +# Copyright lowRISC contributors. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +# Function that builds U-Boot, creating a target with the given output name. +function(mocha_uboot OUTPUT_NAME) + set(UBOOT_BUILD_NAME ${OUTPUT_NAME}_build) + # U-Boot repository and tag to use. + set(UBOOT_REPOSITORY https://github.com/ziuziakowska/u-boot) + set(UBOOT_TAG mocha-devel) + + # configure command - load Mocha defconfig file. + set(CONFIGURE_COMMAND + make + lowrisc_mocha_smode_defconfig + ) + + # build command. + set(BUILD_COMMAND + make + # override CC and LD, as U-boot defaults to using the GNU toolchain. + "CC=clang -target riscv64-unknown-elf" + "LD=ld.lld" + ) + + ExternalProject_Add( + ${UBOOT_BUILD_NAME} + PREFIX ${UBOOT_BUILD_NAME} + GIT_REPOSITORY ${UBOOT_REPOSITORY} + GIT_TAG ${UBOOT_TAG} + GIT_SHALLOW true + # U-boot builds in it's own source tree. + BUILD_IN_SOURCE true + # make is job server aware. + BUILD_JOB_SERVER_AWARE true + CONFIGURE_COMMAND ${CONFIGURE_COMMAND} + BUILD_COMMAND ${BUILD_COMMAND} + INSTALL_COMMAND "" + # suppress output from stdout. + LOG_DOWNLOAD true + LOG_UPDATE true + LOG_PATCH true + LOG_CONFIGURE true + LOG_BUILD true + LOG_INSTALL true + LOG_MERGED_STDOUTERR true + LOG_OUTPUT_ON_FAILURE true + ) + + add_executable(${OUTPUT_NAME} IMPORTED GLOBAL) + set_target_properties(${OUTPUT_NAME} PROPERTIES + IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${UBOOT_BUILD_NAME}/src/${UBOOT_BUILD_NAME}/u-boot + ) + add_dependencies(${OUTPUT_NAME} ${UBOOT_BUILD_NAME}) +endfunction() + +mocha_uboot(uboot) + +mocha_opensbi_with_payload(uboot)