diff --git a/include/chromebook.sh b/include/chromebook.sh index 0261e149..75e445fc 100644 --- a/include/chromebook.sh +++ b/include/chromebook.sh @@ -2,39 +2,17 @@ # Copyright (c) 2025 Leah Rowe -# Assimilate MrChromebox coreboot distro, adapting its ports -# for use in the Libreboot build system. This will create a -# *patch* file for Libreboot, from the current lbmk commit. +# Import MrChromebox project into xbmk -# These functions are used with the "./mk mrchromebox" command. -# MrChromebox has a habit of using branches per project, each -# branch being a given release. He does his changes on top of -# upstream and goes from there. - -# The coreboot build system (upstream one) already integrates -# MrChromebox edk2 quite heavily, so Mrchromebox's own project -# doesn't need a complicated external build system like lbmk. -# He relies on pre-baked configs, that he provides, and uses -# these to build the machines. +# NOTE: variable naming scheme: +# mr_ for variables/functions dealing with MrChromebox +# mx_ for variables/functions pertaining to Libreboot setup +# because i am a non-binary blob spdx="# SPDX-License-Identifier: GPL-3.0-or-later" -mr_tmprepos="" # dir to clone tmp repos in - -# we will use the upstream edk2 repo, but create trees -# for mrchromebox's patches. this is because i will be -# using edk2 for other projects in the future -# NOTE: these mirror https://github.com/tianocore/edk2.git -mx_edk2gitconf="config/git/edk2/pkg.git" -mx_edk2repo="https://codeberg.org/libreboot/edk2" -mx_edk2repo_bkup="https://git.disroot.org/libreboot/edk2" - -# Now the repos to import. Please note: -# These won't be used directly in xbmk. They're being used -# to pull patches and configs from, that mrchromebox uses. -# "rev" is the rev from mrchromebox. "revbase" is the upstream -# rev that his patches derive from. -# so we format-patch from there to HEAD(=e.g. mr_cbrev) +# temporary work variables +mr_tmpdir="" # dir to clone tmp repos in # NOTE: upstream for our purposes: https://review.coreboot.org/coreboot mr_cbrepo="https://github.com/mrchromebox/coreboot" @@ -53,36 +31,31 @@ mr_edk2tree="chromebook" # tree name in xbmk # mxlibreboot was here prep_mr_import() { + mr_tmpdir="`mktemp -d || err "can't make mrtmpdir"`" || \ + err "can't make mrtmpdir" "prep_mr_coreboot" "$@" + x_ remkdir "$mr_tmpdir" + prep_mx_edk2conf - prep_mr_target + prep_mr_projects } # create config/git/edk2/pkg.cfg prep_mx_edk2conf() { - x_ remkdir "${mx_edk2gitconf%/*}" + x_ remkdir "config/git/edk2" - printf "%s\n\n" "$spdx" > "$mx_edk2gitconf" \ - err "Can't write SPDX to '$mx_edk2gitconf'" prep_mr_edk2conf "$@" - - printf "rev=\"HEAD\"\n\n" >> "$mx_edk2gitconf" \ - err "Can't write HEAD to '$mx_edk2gitconf'" prep_mr_edk2conf "$@" - - printf "url=\"%s\"\n\n" "$mx_edk2repo" >> "$mx_edk2gitconf" \ - err "Can't write repo to '$mx_edk2gitconf'" prep_mr_edk2conf "$@" - - printf "url=\"%s\"\n\n" "$mx_edk2repo_bkup" >> "$mx_edk2gitconf" \ - err "Can't write bkup to '$mx_edk2gitconf'" prep_mr_edk2conf "$@" + prep_mr_file "config/git/edk2/pkg.git" \ + "$spdx" \ + "" \ + "rev=\"HEAD\"" \ + "url=\"https://codeberg.org/libreboot/edk2\"" \ + "bkup_url=\"https://git.disroot.org/libreboot/edk2\"" } # prep config/PROJECT/TREE/ for various projects -prep_mr_target() +prep_mr_projects() { - mr_tmprepos="`mktemp -d || err "can't make mrtmpdir"`" || \ - err "can't make mrtmpdir" "prep_mr_coreboot" "$@" - x_ remkdir "$mr_tmprepos" - prep_mr "coreboot" "$mr_cbrepo" "$mr_cbbranch" "$mr_cbrev" \ "$mr_cbrevbase" "$mr_cbtree" prep_mr "edk2" "$mr_edk2repo" "$mr_edk2branch" "$mr_edk2rev" \ @@ -100,37 +73,60 @@ prep_mr() mr_revbase="$5" mr_tree="$6" - mr_tmpclone="$mr_tmprepos/$mr_projectname" - mr_patchdir="config/$mr_projectname/$mr_tree/patches" + x_ prep_mr_patch "$@" + x_ prep_mr_projectsconf "$@" +} - x_ git clone "$mr_repo" "$mr_tmpclone" - x_ git -C "$mr_tmpclone" checkout "$mr_branch" - x_ git -C "$mr_tmpclone" reset --hard "$mr_rev" - x_ git -C "$mr_tmpclone" format-patch $mr_revbase..HEAD +prep_mr_patch() +{ + mr_tmpclone="$mr_tmpdir/$1" + mx_patchdir="config/$1/$6/patches" - x_ remkdir "$mr_patchdir" - x_ mv "$mr_tmpclone"/*.patch "$mr_patchdir" + x_ git clone "$2" "$mr_tmpclone" + x_ git -C "$mr_tmpclone" checkout "$3" + x_ git -C "$mr_tmpclone" reset --hard "$4" + + x_ remkdir "$mx_patchdir" + if [ "$4" != "$5" ]; then + x_ git -C "$mr_tmpclone" format-patch $5..HEAD + x_ mv "$mr_tmpclone"/*.patch "$mx_patchdir" + fi # if no patches were created, rmdir will succeed - rmdir "$mr_patchdir" 1>/dev/null 2>/dev/null || : - - x_ prep_mr_targetconf "$@" + rmdir "$mx_patchdir" 1>/dev/null 2>/dev/null || : x_ rm -Rf "$mr_tmpclone" } -prep_mr_targetconf() +prep_mr_projectsconf() { - # prep the actual tree, after the patches were done - mr_targetconf="config/$1/$6/target.cfg" + # prep the actual tree config, after the patches were done - printf "%s\n\n" "$spdx" > \ - err "Can't write SPDX to '$mr_targetconf'" prep_mr_targetconf "$@" - - printf "tree=\"%s\"\n" "$6" >> "$mr_targetconf" || \ - err "Can't write tree $6 '$mr_targetconf'" prep_mr_targetconf "$@" - printf "rev=\"%s\"\n" "$5" >> "$mr_targetconf" || \ - err "Can't write rev $5 '$mr_targetconf'" prep_mr_targetconf "$@" - - printf "Created '%s'\n" "$mr_targetconf" + prep_mr_file "config/$1/$6/target.cfg" \ + "$spdx" \ + "" \ + "tree=\"$6\"" \ + "rev=\"$5\"" +} + +prep_mr_file() +{ + mr_filename="$1" + shift 1 + + x_ rm -f "$mr_filename" + + while [ $# -gt 0 ] + do + if [ -f "$2" ]; then + printf "%s\n" "$1" >> "$2" || \ + err "Can't write '$1' to '$2'" "mr_file" "$@" + else + printf "%s\n" "$1" > "$2" || \ + err "Can't write '$1' to '$2'" "mr_file" "$@" + fi + shift 1 + done + + printf "Created '%s'\n" "$mr_filename" }