Skip to content
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
157 changes: 92 additions & 65 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -1,101 +1,128 @@
name: Build patcher for multi platforms.
name: Build patcher for multiple platforms

on:
push:
branches: [ "main" ]
branches: [main, feature/multi-boot]
pull_request:
branches: [ "main" ]
branches: [main]
workflow_dispatch:

jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Windows x86_64
- os: windows-latest
arch: x86_64
c_compiler: cl
cpp_compiler: cl

# Windows ARM64
- os: windows-11-arm
arch: aarch64
c_compiler: cl
cpp_compiler: cl

# Linux x86_64
- os: ubuntu-latest
arch: x86_64
- name: Windows x64
os: windows-latest
arch: x64
cmake_arch: x64
build_shims: 'OFF'
executable_suffix: .exe
executable_directory: Release
- name: Windows ARM64
os: windows-11-arm
arch: arm64
cmake_arch: ARM64
build_shims: 'OFF'
executable_suffix: .exe
executable_directory: Release
- name: Linux x64
os: ubuntu-latest
arch: x64
c_compiler: clang
cpp_compiler: clang

# Linux ARM64
- os: ubuntu-24.04-arm
arch: aarch64
build_shims: 'ON'
executable_suffix: ''
executable_directory: .
- name: Linux ARM64
os: ubuntu-24.04-arm
arch: arm64
c_compiler: clang
cpp_compiler: clang

# macOS x86_64
- os: macos-latest
arch: x86_64
build_shims: 'OFF'
executable_suffix: ''
executable_directory: .
- name: macOS x64
os: macos-15-intel
arch: x64
c_compiler: clang
cpp_compiler: clang
build_shims: 'OFF'
executable_suffix: ''
executable_directory: .

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
submodules: recursive

- name: Set reusable strings
id: strings
shell: bash
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
sudo apt-get update
sudo apt-get install --yes build-essential cmake git

- name: Configure Compiler
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-24.04-arm' }}
run: |
sudo apt install gcc-aarch64-linux-gnu
echo -e \\nset\(CMAKE_C_FLAGS "--target=${{ matrix.arch }}-linux-gnu"\) \\n >> ${{ github.workspace }}/CMakeLists.txt
- name: Install ARM64 Shim toolchain
if: matrix.build_shims == 'ON'
run: sudo apt-get install --yes binutils-aarch64-linux-gnu

- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
- name: Configure CMake on Windows
if: runner.os == 'Windows'
run: >-
cmake -S "${{ github.workspace }}"
-B "${{ github.workspace }}/build"
-A ${{ matrix.cmake_arch }}
-DCMAKE_BUILD_TYPE=Release
-DBUILD_SHIMS=${{ matrix.build_shims }}

- name: Configure CMake on Unix
if: runner.os != 'Windows'
run: >-
cmake -S "${{ github.workspace }}"
-B "${{ github.workspace }}/build"
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=Release
-S ${{ github.workspace }}
-DBUILD_SHIMS=${{ matrix.build_shims }}

- name: Build Patcher and other tools
if: ${{ matrix.os != 'ubuntu-latest' || matrix.os != 'ubuntu-24.04-arm' }}
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config Release --target DualBootKernelPatcher DualBootPatchRemover HDRTool
- name: Build host tools
run: >-
cmake --build "${{ github.workspace }}/build"
--config Release
--target MultiBootKernelPatcher UnpackTool

- name: Build ASM Codes
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-24.04-arm' }}
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config Release
- name: Build Shims
if: matrix.build_shims == 'ON'
run: >-
cmake --build "${{ github.workspace }}/build"
--config Release
--target Shims

- name: Upload Tools
uses: actions/upload-artifact@v4
- name: Stage host tools
shell: bash
run: |
mkdir -p artifacts/tools
cp "build/${{ matrix.executable_directory }}/MultiBootKernelPatcher${{ matrix.executable_suffix }}" artifacts/tools/
cp "build/${{ matrix.executable_directory }}/UnpackTool${{ matrix.executable_suffix }}" artifacts/tools/

- name: Upload host tools
uses: actions/upload-artifact@v7
with:
name: Tools-${{ matrix.os }}-${{ matrix.arch }}
path: |
${{ steps.strings.outputs.build-output-dir }}/**/DualBootKernelPatcher*
${{ steps.strings.outputs.build-output-dir }}/**/DualBootPatchRemover*
${{ steps.strings.outputs.build-output-dir }}/**/HDRTool*
path: artifacts/tools
if-no-files-found: error

- name: Upload ASM Bins
- name: Upload simplified Shims
if: matrix.build_shims == 'ON'
uses: actions/upload-artifact@v4
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
name: Shellcodes
path: |
${{ steps.strings.outputs.build-output-dir }}/ShellCode/*
name: Shims
path: build/Shims/Shim.*.bin
if-no-files-found: error

- name: Upload Configs
- name: Upload configs
if: matrix.build_shims == 'ON'
uses: actions/upload-artifact@v4
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
name: Configs
path: |
Config/*
path: Config
if-no-files-found: error
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
ShellCode.Epsilon.S
cmake-build-debug
cmake-build-debug
build/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/inih"]
path = lib/inih
url = https://github.com/benhoyt/inih.git
83 changes: 76 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,84 @@
cmake_minimum_required(VERSION 3.18)
project(DualBootKernelPatcher C)
project(MultiBootKernelPatcher C)

option(BUILD_SHIMS "Build the ARM64 Shim binaries" ON)

if (BUILD_SHIMS)
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# MinGW compiler download link:
# https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
set(ARM64_TOOLCHAIN_PREFIX
"E:/aarch64-gcc/aarch64-none-elf/bin/"
CACHE STRING "ARM64 binutils path and executable prefix")
elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(ARM64_TOOLCHAIN_PREFIX "aarch64-linux-gnu-"
CACHE STRING "ARM64 binutils path and executable prefix")
else ()
message(FATAL_ERROR
"Building ARM64 Shim binaries on ${CMAKE_HOST_SYSTEM_NAME} is not supported")
endif ()

set(ARM64_AS "${ARM64_TOOLCHAIN_PREFIX}as"
CACHE FILEPATH "ARM64 assembler")
set(ARM64_OBJCOPY "${ARM64_TOOLCHAIN_PREFIX}objcopy"
CACHE FILEPATH "ARM64 objcopy")
endif ()

set(CMAKE_C_STANDARD 11)
if (MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()

if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif ()

if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/lib/inih/ini.c)
message(FATAL_ERROR
"The inih submodule is missing. Run: git submodule update --init --recursive")
endif ()

add_library(inih_static STATIC
${CMAKE_CURRENT_SOURCE_DIR}/lib/inih/ini.c
)
if (MSVC)
set_property(TARGET inih_static PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()
target_include_directories(inih_static PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/lib/inih
)
set(INIH_TARGET inih_static)

# Compile the patcher.
add_executable(DualBootKernelPatcher patcher.c utils.c)
add_executable(DualBootPatchRemover remover.c utils.c)
add_executable(HDRTool HDRTool.c utils.c)
add_executable(MultiBootKernelPatcher
src/patcher.c
src/shim.c
src/shim_format.c
src/shim_config.c
src/utils.c
)
target_include_directories(MultiBootKernelPatcher PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/inc
)
if (MSVC)
set_property(TARGET MultiBootKernelPatcher PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()
target_link_libraries(MultiBootKernelPatcher PRIVATE ${INIH_TARGET})
add_executable(UnpackTool
src/unpack.c
src/shim_format.c
src/utils.c
)
target_include_directories(UnpackTool PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/inc
)
if (MSVC)
set_property(TARGET UnpackTool PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()

# Compile Shell Codes with aarch64 gcc.
add_subdirectory(ShellCode)
if (BUILD_SHIMS)
add_subdirectory(Shims)
endif ()
24 changes: 24 additions & 0 deletions Config/DualBoot.AYAPS.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[Pack]
Shim=../build/Shims/Shim.AYAPS.bin
Output=../build/PatchedKernel
Default=Image
Timeout=0

[Image]
Name=Android/Linux
Path=/path/to/Image
Type=Linux
BaseImage=true
Align=0x200000

[Image-UEFI]
Name=UEFI
Path=/path/to/SM8550_EFI.fd
Type=FreeExec
BaseImage=false
CopyTo=0xC7CC0000
CopySizeMax=0x00400000
EntryOffset=0

[Manifest]
Type=Manifest
24 changes: 24 additions & 0 deletions Config/DualBoot.Hotdog.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[Pack]
Shim=../build/Shims/Shim.Hotdog.bin
Output=../build/PatchedKernel
Default=Image
Timeout=0

[Image]
Name=Android/Linux
Path=/path/to/Image
Type=Linux
BaseImage=true
Align=0x200000

[Image-UEFI]
Name=UEFI
Path=/path/to/SM8150_EFI.fd
Type=FreeExec
BaseImage=false
CopyTo=0x9FC00000
CopySizeMax=0x00300000
EntryOffset=0

[Manifest]
Type=Manifest
24 changes: 24 additions & 0 deletions Config/DualBoot.KernelWarpper.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[Pack]
Shim=../build/Shims/Shim.KernelWrapper.bin
Output=../build/PatchedKernel
Default=Image
Timeout=0

[Image]
Name=Linux
Path=/path/to/Image
Type=Linux
BaseImage=true
Align=0x200000

[Image-DTB]
Name=Mainline Device Tree
Path=/path/to/mainline.dtb
Type=DTB
BaseImage=false
CopyTo=0x9FC00000
CopySizeMax=0x00300000
Align=8

[Manifest]
Type=Manifest
Loading
Loading