diff --git a/.github/workflows/kanso-cd.yml b/.github/workflows/kanso-cd.yml index fc8c1db..b4817c2 100644 --- a/.github/workflows/kanso-cd.yml +++ b/.github/workflows/kanso-cd.yml @@ -6,9 +6,13 @@ jobs: kernel-build: strategy: matrix: - include: ${{ fromJSON(vars.Platforms) }} + Platform: [ "riscv64", "riscv32" ] uses: ./.github/workflows/kernel-build.yml secrets: inherit with: - platform: ${{ matrix.platform }} + platform: ${{ matrix.Platform }} + release-pine64_star64: + needs: kernel-build + uses: ./.github/workflows/release-pine64_star64.yml + secrets: inherit diff --git a/.github/workflows/kanso-ci.yml b/.github/workflows/kanso-ci.yml index 6ca42d1..f7b2951 100644 --- a/.github/workflows/kanso-ci.yml +++ b/.github/workflows/kanso-ci.yml @@ -28,9 +28,9 @@ jobs: if: ${{ needs.filter.outputs.kernel == 'true' || needs.filter.outputs.common == 'true' }} strategy: matrix: - include: ${{ fromJSON(vars.Platforms) }} + Platform: [ "riscv64", "riscv32" ] uses: ./.github/workflows/kernel-build.yml secrets: inherit with: - platform: ${{ matrix.platform }} + platform: ${{ matrix.Platform }} diff --git a/.github/workflows/release-pine64_star64.yml b/.github/workflows/release-pine64_star64.yml new file mode 100644 index 0000000..bced922 --- /dev/null +++ b/.github/workflows/release-pine64_star64.yml @@ -0,0 +1,69 @@ +name: Kernel-Build +on: + workflow_call: + +jobs: + build: + runs-on: ubuntu-latest + env: + CROSS_COMPILE: riscv64-linux-gnu- + + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Download kernel.bin artifact + uses: actions/download-artifact@v4 + with: + name: kernel-riscv64 + path: kanso_kernel + + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential \ + gcc-riscv64-linux-gnu g++-riscv64-linux-gnu binutils-riscv64-linux-gnu \ + device-tree-compiler bison flex libssl-dev bc libgnutls28-dev \ + u-boot-tools genimage + + - name: Clone u-boot + run: git clone https://github.com/u-boot/u-boot.git u-boot + + - name: Clone OpenSBI + run: git clone https://github.com/riscv-software-src/opensbi.git opensbi + + - name: Clone StarFive utilities + run: git clone https://github.com/starfive-tech/soft_3rdpart.git starfive_utils + + - name: Build U-Boot SPL and DTBs + run: | + make -C u-boot starfive_visionfive2_defconfig + make -C u-boot -j$(nproc) spl/u-boot-spl.bin + make -C u-boot -j$(nproc) dtbs + + - name: Pack SPL image with StarFive spl_tool + run: | + make -C starfive_utils/spl_tool + starfive_utils/spl_tool/spl_tool -c -f u-boot/spl/u-boot-spl.bin + + - name: Build OpenSBI firmware + run: | + make -C opensbi \ + PLATFORM=generic \ + FW_PAYLOAD_PATH=../kanso_kernel/kernel.bin \ + FW_FDT_PATH=../u-boot/dts/upstream/src/riscv/starfive/jh7110-pine64-star64.dtb \ + FW_TEXT_START=0x40000000 + + - name: Create Star64 FIT image + run: mkimage -f .github/workflows/releases/pine64_star64/star64-uboot-fit-image.its -A riscv -O u-boot -T firmware kernel.img + + - name: Run genimage + run: genimage --config .github/workflows/releases/pine64_star64/genimage.cfg --inputpath . --tmppath temp + + - name: Upload packaged Star64 image + uses: actions/upload-artifact@v4 + with: + name: kanso_pine64_star64 + path: | + images/kanso_pine64_star64.img diff --git a/.github/workflows/releases/pine64_star64/genimage.cfg b/.github/workflows/releases/pine64_star64/genimage.cfg new file mode 100644 index 0000000..7b14921 --- /dev/null +++ b/.github/workflows/releases/pine64_star64/genimage.cfg @@ -0,0 +1,19 @@ +image kanso_pine64_star64.img { + hdimage { + gpt = true + } + + partition spl { + image = "u-boot/spl/u-boot-spl.bin.normal.out" + partition-type-uuid = 2E54B353-1271-4842-806F-E436D6AF6985 + offset = 2M + size = 2M + } + + partition uboot { + image = "kernel.img" + partition-type-uuid = 5B193300-FC78-40CD-8002-E86C45580B47 + offset = 4M + size = 4M + } +} \ No newline at end of file diff --git a/.github/workflows/releases/pine64_star64/star64-uboot-fit-image.its b/.github/workflows/releases/pine64_star64/star64-uboot-fit-image.its new file mode 100644 index 0000000..1a5e1cd --- /dev/null +++ b/.github/workflows/releases/pine64_star64/star64-uboot-fit-image.its @@ -0,0 +1,28 @@ +/dts-v1/; + +/ { + description = "U-boot-spl FIT image for JH7110 Pine64 Star64"; + #address-cells = <2>; + + images { + firmware { + description = "u-boot"; + data = /incbin/("../../../../opensbi/build/platform/generic/firmware/fw_payload.bin"); + type = "firmware"; + arch = "riscv"; + os = "u-boot"; + load = <0x0 0x40000000>; + entry = <0x0 0x40000000>; + compression = "none"; + }; + }; + configurations { + default = "config-1"; + + config-1 { + description = "U-boot-spl FIT config for JH7110 Pine64 Star64"; + firmware = "firmware"; + }; + }; +}; + diff --git a/CMakeLists.txt b/CMakeLists.txt index 272308d..2330ff3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,5 +6,17 @@ project(Kanso LANGUAGES C ASM) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +include(cmake/utils.cmake) + +set(VERSION_HEADER_PATH "${CMAKE_BINARY_DIR}/src/Common/Version.h") +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/src/Common") + +add_custom_target(generate_version_header ALL + COMMAND ${CMAKE_COMMAND} -DOUT_FILE=${VERSION_HEADER_PATH} + -P "${CMAKE_SOURCE_DIR}/cmake/generate_version_header.cmake" + COMMENT "Regenerating version.h from Git tag" +) + add_subdirectory(src/Common) add_subdirectory(src/Kernel) + diff --git a/cmake/generate_version_header.cmake b/cmake/generate_version_header.cmake new file mode 100644 index 0000000..67eac38 --- /dev/null +++ b/cmake/generate_version_header.cmake @@ -0,0 +1,33 @@ +execute_process( + COMMAND git describe --tags --abbrev=0 + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + +if(NOT GIT_TAG) + set(GIT_TAG "0.0.0-DEV") +endif() + +string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)-([A-Za-z0-9]+)$" _ "${GIT_TAG}") + +set(MAJOR ${CMAKE_MATCH_1}) +set(MINOR ${CMAKE_MATCH_2}) +math(EXPR BUILD "${CMAKE_MATCH_3} + 1") +set(LABEL ${CMAKE_MATCH_4}) + +set(VERSION_FULL "${MAJOR}.${MINOR}.${BUILD}-${LABEL}") + +file(WRITE "${OUT_FILE}" " +// Auto-generated version.h from Git tag ${GIT_TAG} + +#pragma once + +#define KANSO_VERSION_MAJOR ${MAJOR} +#define KANSO_VERSION_MINOR ${MINOR} +#define KANSO_VERSION_BUILD ${BUILD} +#define KANSO_VERSION_LABEL \"${LABEL}\" +#define KANSO_VERSION_FULL \"${VERSION_FULL}\" +") + diff --git a/cmake/utils.cmake b/cmake/utils.cmake new file mode 100644 index 0000000..8d6ccc9 --- /dev/null +++ b/cmake/utils.cmake @@ -0,0 +1,26 @@ +function(get_git_version OUT_PREFIX) + execute_process( + COMMAND git describe --tags --abbrev=0 + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE _GIT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + + if(NOT _GIT_TAG) + set(_GIT_TAG "0.0.0-UNKNOWN") + endif() + + string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)-([A-Za-z0-9]+)$" _ "${_GIT_TAG}") + + set(${OUT_PREFIX}_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE) + set(${OUT_PREFIX}_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE) + set(${OUT_PREFIX}_BUILD "${CMAKE_MATCH_3}" PARENT_SCOPE) + set(${OUT_PREFIX}_LABEL "${CMAKE_MATCH_4}" PARENT_SCOPE) + + set(${OUT_PREFIX}_FULL + "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}-${CMAKE_MATCH_4}" + PARENT_SCOPE + ) +endfunction() + diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index 8538637..a8980f7 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -1,3 +1,6 @@ add_library(Common INTERFACE) +add_dependencies(Common generate_version_header) + +target_include_directories(Common INTERFACE .) +target_include_directories(Common INTERFACE ${CMAKE_BINARY_DIR}/src/Common) -target_include_directories(Common INTERFACE .) \ No newline at end of file diff --git a/src/Kernel/CMakeLists.txt b/src/Kernel/CMakeLists.txt index 0bb5603..953783e 100644 --- a/src/Kernel/CMakeLists.txt +++ b/src/Kernel/CMakeLists.txt @@ -1,2 +1,4 @@ # TODO: Add the correct platform add_subdirectory(Platforms/RiscV) +add_dependencies(Kernel generate_version_header) +add_dependencies(KernelTest generate_version_header) diff --git a/src/Kernel/KernelMain.c b/src/Kernel/KernelMain.c index d66e401..630b31b 100644 --- a/src/Kernel/KernelMain.c +++ b/src/Kernel/KernelMain.c @@ -1,6 +1,7 @@ #include "Types.h" #include "String.h" #include "Memory.h" +#include "Version.h" #include "Platform.h" #include "KernelConsole.h" #include "Kernel.h" @@ -29,9 +30,8 @@ void KernelMain() { auto platformInformation = PlatformGetInformation(); - // this is a test KernelConsolePrint(String("\n\n\x1b[36m%s\x1b[0m\n"), KernelLogo); - KernelConsolePrint(String("Kanso OS 1.0-DEV1 ")); + KernelConsolePrint(String("Kanso OS %s "), KANSO_VERSION_FULL); KernelConsolePrint(String("(%s %d-bit)\n\n"), platformInformation.Name.Pointer, platformInformation.ArchitectureBits); //CpuSetSupervisorTrapHandler(&KernelSupervisorTrapHandler); diff --git a/src/Kernel/KernelTest.c b/src/Kernel/KernelTest.c index 38a9189..07bdedd 100644 --- a/src/Kernel/KernelTest.c +++ b/src/Kernel/KernelTest.c @@ -3,6 +3,7 @@ #include "String.h" #include "KernelConsole.h" #include "Platform.h" +#include "Version.h" const char* TEST_CONSOLE_RESET = "\x1b[0m"; const char* TEST_CONSOLE_GREEN = "\x1b[32m"; @@ -44,6 +45,11 @@ void KernelTestHandler(TestRunState state, ReadOnlySpanChar message, ...) void KernelMain() { + auto platformInformation = PlatformGetInformation(); + + KernelConsolePrint(String("\n\nKanso OS Kernel Tests %s "), KANSO_VERSION_FULL); + KernelConsolePrint(String("(%s %d-bit)\n\n"), platformInformation.Name.Pointer, platformInformation.ArchitectureBits); + TestRun(KernelTestHandler); BiosReset(BiosResetType_Shutdown, BiosResetReason_None); }