forked from aweeraman/kernel-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aweeraman#3 from elleaech/feature/add-polimorph-bu…
…ild-busybox-script Add polimorph build script
- Loading branch information
Showing
2 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from subprocess import run | ||
from os import chdir | ||
from abc import ABC | ||
from sys import exit | ||
|
||
import argparse | ||
|
||
|
||
def parse_cli_args() -> argparse.ArgumentParser: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"arch", | ||
type=str, | ||
help="Busybox's target architecture", | ||
) | ||
|
||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
class BoxBuilder(ABC): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
self.__command = "make" | ||
self.__busybox_dir = "deps/busybox" | ||
self.__basedir = "." | ||
|
||
def build(self, procs: int) -> None: | ||
raise NotImplementedError | ||
|
||
def _goto_busybox_folder(self) -> None: | ||
chdir(self.__busybox_dir) | ||
|
||
def _dump_log(self) -> str: | ||
return f"2>&1 | tee -a {self.__basedir}/log" | ||
|
||
|
||
class CrossBoxBuilder(BoxBuilder): | ||
def __init__(self, compiler: str) -> None: | ||
super().__init__() | ||
self._cross_compiler = compiler | ||
self._arch = "" | ||
|
||
|
||
class ARMBoxBuilder(CrossBoxBuilder): | ||
def __init__(self, compiler: str) -> None: | ||
super().__init__(compiler) | ||
self._arch = "arm" | ||
|
||
def build(self, procs: int) -> None: | ||
self._goto_busybox_folder() | ||
|
||
run( | ||
f"{self._BoxBuilder__command} -j{str(procs)} ARCH={self._arch} CROSS_COMPILE={self._cross_compiler} {self._dump_log()}", | ||
shell=True, | ||
check=True, | ||
) | ||
run( | ||
f"{self._BoxBuilder__command} ARCH={self._arch} CROSS_COMPILE={self._cross_compiler} install {self._dump_log()}", | ||
shell=True, | ||
check=True, | ||
) | ||
|
||
|
||
class X86_64BoxBuilder(BoxBuilder): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
def build(self, procs: int) -> None: | ||
self._goto_busybox_folder() | ||
|
||
run( | ||
f"{self._BoxBuilder__command} -j{str(procs)} {self._dump_log()}", | ||
shell=True, | ||
check=True, | ||
) | ||
run( | ||
f"{self._BoxBuilder__command} CONFIG_PREFIX=initrd install {self._dump_log()}", | ||
shell=True, | ||
check=True, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
args: argparse.ArgumentParser = parse_cli_args() | ||
|
||
if args.arch == "x86_64": | ||
make = X86_64BoxBuilder() | ||
make.build(2) | ||
|
||
elif args.arch == "arm": | ||
make = ARMBoxBuilder("arm-linux-gnueabi-") | ||
make.build() | ||
|
||
exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters