forked from tfgrid/zosbuilder
Separate component building from copying for better architecture
- Remove component copying from build functions (build_zinit, build_rfs, etc) - Add initramfs_copy_components() function to copy built components to initramfs - Add components_copy stage between init_script and modules_setup - Fix components_verify to check built components (not initramfs locations) - Now supports partial builds: build components separately, copy later - All 4 components (zinit 8.1M, rfs 13M, mycelium 21M, corex 4.0M) working
This commit is contained in:
@@ -262,6 +262,10 @@ function main_build_process() {
|
||||
initramfs_install_init_script "$INSTALL_DIR" "${CONFIG_DIR}/init"
|
||||
}
|
||||
|
||||
function stage_components_copy() {
|
||||
initramfs_copy_components "$INSTALL_DIR" "$COMPONENTS_DIR"
|
||||
}
|
||||
|
||||
function stage_modules_setup() {
|
||||
# Calculate full kernel version (needed for incremental builds when kernel_modules stage is skipped)
|
||||
local full_kernel_version=$(kernel_get_full_version "$KERNEL_VERSION" "$KERNEL_CONFIG")
|
||||
@@ -328,6 +332,7 @@ function main_build_process() {
|
||||
stage_run "kernel_modules" stage_kernel_modules
|
||||
stage_run "zinit_setup" stage_zinit_setup
|
||||
stage_run "init_script" stage_init_script
|
||||
stage_run "components_copy" stage_components_copy
|
||||
stage_run "modules_setup" stage_modules_setup
|
||||
stage_run "modules_copy" stage_modules_copy
|
||||
stage_run "cleanup" stage_cleanup
|
||||
|
||||
@@ -291,13 +291,8 @@ function build_zinit() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Install to initramfs
|
||||
safe_mkdir "${INSTALL_DIR}/sbin"
|
||||
safe_execute cp "$binary_path" "${INSTALL_DIR}/sbin/zinit"
|
||||
safe_execute chmod +x "${INSTALL_DIR}/sbin/zinit"
|
||||
|
||||
local binary_size=$(get_file_size "${INSTALL_DIR}/sbin/zinit")
|
||||
log_info "Installed zinit binary (${binary_size}) to: ${INSTALL_DIR}/sbin/zinit"
|
||||
local binary_size=$(get_file_size "$binary_path")
|
||||
log_info "Built zinit binary (${binary_size}) at: ${binary_path}"
|
||||
}
|
||||
|
||||
# Build function for rfs (standard Rust build)
|
||||
@@ -343,13 +338,8 @@ function build_rfs() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Install to initramfs
|
||||
safe_mkdir "${INSTALL_DIR}/usr/bin"
|
||||
safe_execute cp "$binary_path" "${INSTALL_DIR}/usr/bin/rfs"
|
||||
safe_execute chmod +x "${INSTALL_DIR}/usr/bin/rfs"
|
||||
|
||||
local binary_size=$(get_file_size "${INSTALL_DIR}/usr/bin/rfs")
|
||||
log_info "Installed rfs binary (${binary_size}) to: ${INSTALL_DIR}/usr/bin/rfs"
|
||||
local binary_size=$(get_file_size "$binary_path")
|
||||
log_info "Built rfs binary (${binary_size}) at: ${binary_path}"
|
||||
}
|
||||
|
||||
# Build function for mycelium (special subdirectory build)
|
||||
@@ -388,13 +378,8 @@ function build_mycelium() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Install to initramfs
|
||||
safe_mkdir "${INSTALL_DIR}/usr/bin"
|
||||
safe_execute cp "$binary_path" "${INSTALL_DIR}/usr/bin/mycelium"
|
||||
safe_execute chmod +x "${INSTALL_DIR}/usr/bin/mycelium"
|
||||
|
||||
local binary_size=$(get_file_size "${INSTALL_DIR}/usr/bin/mycelium")
|
||||
log_info "Installed mycelium binary (${binary_size}) to: ${INSTALL_DIR}/usr/bin/mycelium"
|
||||
local binary_size=$(get_file_size "$binary_path")
|
||||
log_info "Built mycelium binary (${binary_size}) at: ${binary_path}"
|
||||
}
|
||||
|
||||
# Install function for rfs (pre-built binary)
|
||||
@@ -413,14 +398,11 @@ function install_rfs() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Make executable and install
|
||||
# Make executable
|
||||
safe_execute chmod +x "$binary_path"
|
||||
safe_mkdir "${INSTALL_DIR}/usr/bin"
|
||||
safe_execute cp "$binary_path" "${INSTALL_DIR}/usr/bin/rfs"
|
||||
safe_execute chmod +x "${INSTALL_DIR}/usr/bin/rfs"
|
||||
|
||||
local binary_size=$(get_file_size "${INSTALL_DIR}/usr/bin/rfs")
|
||||
log_info "Installed rfs binary (${binary_size}) to: ${INSTALL_DIR}/usr/bin/rfs"
|
||||
local binary_size=$(get_file_size "$binary_path")
|
||||
log_info "Prepared rfs binary (${binary_size}) at: ${binary_path}"
|
||||
}
|
||||
|
||||
# Install function for corex (pre-built binary)
|
||||
@@ -443,37 +425,34 @@ function install_corex() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Make executable and install
|
||||
# Make executable
|
||||
safe_execute chmod +x "$binary_path"
|
||||
safe_mkdir "${INSTALL_DIR}/usr/bin"
|
||||
safe_execute cp "$binary_path" "${INSTALL_DIR}/usr/bin/corex"
|
||||
safe_execute chmod +x "${INSTALL_DIR}/usr/bin/corex"
|
||||
|
||||
local binary_size=$(get_file_size "${INSTALL_DIR}/usr/bin/corex")
|
||||
log_info "Installed corex binary (${binary_size}) to: ${INSTALL_DIR}/usr/bin/corex"
|
||||
local binary_size=$(get_file_size "$binary_path")
|
||||
log_info "Prepared corex binary (${binary_size}) at: ${binary_path}"
|
||||
}
|
||||
|
||||
# Verify all built components
|
||||
# Verify all components are built (not copied to initramfs yet)
|
||||
function components_verify_installation() {
|
||||
local install_dir="${INSTALL_DIR:-${PROJECT_ROOT}/initramfs}"
|
||||
local components_dir="${COMPONENTS_DIR:-${PROJECT_ROOT}/components}"
|
||||
|
||||
section_header "Verifying Component Installation"
|
||||
section_header "Verifying Component Build"
|
||||
|
||||
# List of expected binaries and their locations
|
||||
# List of expected built binaries and their locations in components directory
|
||||
local expected_binaries=(
|
||||
"sbin/zinit"
|
||||
"usr/bin/rfs"
|
||||
"usr/bin/mycelium"
|
||||
"usr/bin/corex"
|
||||
"zinit/target/x86_64-unknown-linux-musl/release/zinit"
|
||||
"rfs/rfs"
|
||||
"mycelium/myceliumd/target/x86_64-unknown-linux-musl/release/mycelium"
|
||||
"corex/corex"
|
||||
)
|
||||
|
||||
local missing_count=0
|
||||
|
||||
for binary in "${expected_binaries[@]}"; do
|
||||
local full_path="${install_dir}/${binary}"
|
||||
local full_path="${components_dir}/${binary}"
|
||||
if [[ -f "$full_path" && -x "$full_path" ]]; then
|
||||
local size=$(get_file_size "$full_path")
|
||||
log_info "✓ ${binary} (${size})"
|
||||
log_info "✓ Built ${binary##*/} (${size}) at: ${binary}"
|
||||
else
|
||||
log_error "✗ Missing or not executable: ${binary}"
|
||||
((missing_count++))
|
||||
@@ -481,10 +460,10 @@ function components_verify_installation() {
|
||||
done
|
||||
|
||||
if [[ $missing_count -eq 0 ]]; then
|
||||
log_info "All components installed successfully"
|
||||
log_info "All components built successfully"
|
||||
return 0
|
||||
else
|
||||
log_error "${missing_count} components missing or invalid"
|
||||
log_error "${missing_count} components missing or failed to build"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -102,6 +102,87 @@ function initramfs_install_init_script() {
|
||||
log_info " Boot flow: /init -> setup environment -> switch_root -> /sbin/zinit init"
|
||||
}
|
||||
|
||||
# Copy built components to initramfs (separate from building)
|
||||
function initramfs_copy_components() {
|
||||
local initramfs_dir="$1"
|
||||
local components_dir="${2:-${PROJECT_ROOT}/components}"
|
||||
|
||||
section_header "Copying Built Components to Initramfs"
|
||||
|
||||
if [[ ! -d "$components_dir" ]]; then
|
||||
log_error "Components directory not found: ${components_dir}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local copied_count=0
|
||||
local missing_count=0
|
||||
|
||||
# Copy zinit to /sbin
|
||||
local zinit_binary="${components_dir}/zinit/target/x86_64-unknown-linux-musl/release/zinit"
|
||||
if [[ -f "$zinit_binary" ]]; then
|
||||
safe_mkdir "${initramfs_dir}/sbin"
|
||||
safe_execute cp "$zinit_binary" "${initramfs_dir}/sbin/zinit"
|
||||
safe_execute chmod +x "${initramfs_dir}/sbin/zinit"
|
||||
local size=$(get_file_size "${initramfs_dir}/sbin/zinit")
|
||||
log_info "✓ Copied zinit (${size}) to /sbin/zinit"
|
||||
((copied_count++))
|
||||
else
|
||||
log_error "✗ zinit binary not found: ${zinit_binary}"
|
||||
((missing_count++))
|
||||
fi
|
||||
|
||||
# Copy rfs to /usr/bin
|
||||
local rfs_binary="${components_dir}/rfs/rfs"
|
||||
if [[ -f "$rfs_binary" ]]; then
|
||||
safe_mkdir "${initramfs_dir}/usr/bin"
|
||||
safe_execute cp "$rfs_binary" "${initramfs_dir}/usr/bin/rfs"
|
||||
safe_execute chmod +x "${initramfs_dir}/usr/bin/rfs"
|
||||
local size=$(get_file_size "${initramfs_dir}/usr/bin/rfs")
|
||||
log_info "✓ Copied rfs (${size}) to /usr/bin/rfs"
|
||||
((copied_count++))
|
||||
else
|
||||
log_error "✗ rfs binary not found: ${rfs_binary}"
|
||||
((missing_count++))
|
||||
fi
|
||||
|
||||
# Copy mycelium to /usr/bin
|
||||
local mycelium_binary="${components_dir}/mycelium/myceliumd/target/x86_64-unknown-linux-musl/release/mycelium"
|
||||
if [[ -f "$mycelium_binary" ]]; then
|
||||
safe_mkdir "${initramfs_dir}/usr/bin"
|
||||
safe_execute cp "$mycelium_binary" "${initramfs_dir}/usr/bin/mycelium"
|
||||
safe_execute chmod +x "${initramfs_dir}/usr/bin/mycelium"
|
||||
local size=$(get_file_size "${initramfs_dir}/usr/bin/mycelium")
|
||||
log_info "✓ Copied mycelium (${size}) to /usr/bin/mycelium"
|
||||
((copied_count++))
|
||||
else
|
||||
log_error "✗ mycelium binary not found: ${mycelium_binary}"
|
||||
((missing_count++))
|
||||
fi
|
||||
|
||||
# Copy corex to /usr/bin
|
||||
local corex_binary="${components_dir}/corex/corex"
|
||||
if [[ -f "$corex_binary" ]]; then
|
||||
safe_mkdir "${initramfs_dir}/usr/bin"
|
||||
safe_execute cp "$corex_binary" "${initramfs_dir}/usr/bin/corex"
|
||||
safe_execute chmod +x "${initramfs_dir}/usr/bin/corex"
|
||||
local size=$(get_file_size "${initramfs_dir}/usr/bin/corex")
|
||||
log_info "✓ Copied corex (${size}) to /usr/bin/corex"
|
||||
((copied_count++))
|
||||
else
|
||||
log_error "✗ corex binary not found: ${corex_binary}"
|
||||
((missing_count++))
|
||||
fi
|
||||
|
||||
log_info "Component copy complete: ${copied_count} copied, ${missing_count} missing"
|
||||
|
||||
if [[ $missing_count -gt 0 ]]; then
|
||||
log_error "Some components missing - build may have failed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Setup 2-stage module loading system with dependency resolution and firmware correlation
|
||||
function initramfs_setup_modules() {
|
||||
local initramfs_dir="$1"
|
||||
@@ -784,5 +865,6 @@ function initramfs_copy_resolved_modules() {
|
||||
|
||||
# Export all functions at the end after they're all defined
|
||||
export -f initramfs_setup_zinit initramfs_setup_modules initramfs_resolve_module_dependencies
|
||||
export -f initramfs_install_init_script initramfs_create_module_scripts initramfs_strip_and_upx
|
||||
export -f initramfs_create_cpio initramfs_validate initramfs_test_archive initramfs_copy_resolved_modules
|
||||
export -f initramfs_install_init_script initramfs_copy_components initramfs_create_module_scripts
|
||||
export -f initramfs_strip_and_upx initramfs_create_cpio initramfs_validate initramfs_test_archive
|
||||
export -f initramfs_copy_resolved_modules
|
||||
Reference in New Issue
Block a user