Skip to content

Commit

Permalink
builders: imgBuilder: opensbi: deprecate opensbi common-build
Browse files Browse the repository at this point in the history
  • Loading branch information
xieby1 committed Jan 9, 2025
1 parent 137034a commit 0e36fb5
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 32 deletions.
8 changes: 1 addition & 7 deletions builders/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ benchmark: lib.makeScope lib.callPackageWith (self: {
linux = callPackage ./imgBuilder/linux { inherit (self) initramfs; };

dts = callPackage ./imgBuilder/opensbi/dts {};
opensbi-common-build = callPackage ./imgBuilder/opensbi/common-build.nix {
inherit (self) dts;
};
opensbi = callPackage ./imgBuilder/opensbi {
inherit (self) dts linux;
common-build = self.opensbi-common-build;
};
opensbi = callPackage ./imgBuilder/opensbi { inherit (self) dts linux; };
gcpt_single_core = callPackage ./imgBuilder/gcpt/single_core.nix {
inherit (self) opensbi;
};
Expand Down
30 changes: 9 additions & 21 deletions builders/imgBuilder/opensbi/default.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{ stdenv
, fetchFromGitHub
, python3
, enableOverlayFS ? true
, fuse-overlayfs
, vmTools

, riscv64-cc
, rmExt
, linux
, dts
, common-build
}@args: let overlayfsDisabled = stdenv.mkDerivation {
}@args: stdenv.mkDerivation {
name = "${rmExt linux.name}.opensbi";

src = common-build;
src = fetchFromGitHub {
owner = "riscv-software-src";
repo = "opensbi";
rev = "c4940a9517486413cd676fc8032bb55f9d4e2778";
hash = "sha256-cV+2DJjlqdG9zR3W6cH6BIZqnuB1kdH3mjc4PO+VPeE=";
};

buildInputs = [
python3
Expand Down Expand Up @@ -58,21 +60,7 @@
'';

installPhase = ''
# runInLinuxVM will auto create dir $out
rm -rf $out
cp build/platform/generic/firmware/fw_payload.bin $out
'';
passthru = args;
};
overlayfsEnabled = vmTools.runInLinuxVM (overlayfsDisabled.overrideAttrs (old: {
unpackPhase = ''
mkdir workdir
mkdir upperdir
mkdir overlaydir
/run/modprobe fuse
${fuse-overlayfs}/bin/fuse-overlayfs -o lowerdir=${old.src},workdir=workdir,upperdir=upperdir overlaydir
cd overlaydir
'';
memSize = 2048;
}));
in if enableOverlayFS then overlayfsEnabled else overlayfsDisabled
}
78 changes: 78 additions & 0 deletions builders/imgBuilder/opensbi/deprecated.default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{ stdenv
, python3
, enableOverlayFS ? true
, fuse-overlayfs
, vmTools

, riscv64-cc
, rmExt
, linux
, dts
, common-build
}@args: let overlayfsDisabled = stdenv.mkDerivation {
name = "${rmExt linux.name}.opensbi";

src = common-build;

buildInputs = [
python3
riscv64-cc
];

makeFlags = [
"CROSS_COMPILE=riscv64-unknown-linux-gnu-"
"PLATFORM=generic"
"FW_FDT_PATH=${dts}/xiangshan.dtb"
"FW_PAYLOAD_PATH=${linux}"
];
buildPhase = ''
patchShebangs .
# Default FW_PAYLOAD memory layout:
# Refers to https://github.com/riscv-software-src/opensbi/blob/master/platform/generic/objects.mk
# and https://docs.xiangshan.cc/zh-cn/latest/tools/opensbi-kernel-for-xs/
# FW_PAYLOAD_OFFSET=0x100000
# -------------------------------------------------------------------
# | gcpt | opensbi firmware | payload e.g. linux Image | FDT |
# -------------------------------------------------------------------
# | | | |
# |OFFSET | FW_PAYLOAD_OFFSET | |
# |(1MB) | (default:0x100000=1MB) | |
# | |
# |---------- FW_PAYLOAD_FDT_OFFSET --------------------------|
# (default:0x2200000=2MB+32MB)
# Noted: In 64bit system, the FW_PAYLOAD_OFFSET and FW_PAYLOAD_FDT_OFFSET must be aligned to 2MB.
# Calculate the FW_PAYLOAD_FDT_OFFSET
ALIGN=0x200000
FW_PAYLOAD_OFFSET=0x100000
IMAGE_SIZE=$(ls -l ${linux} | awk '{print $5}')
IMAGE_END=$((FW_PAYLOAD_OFFSET + IMAGE_SIZE))
IMAGE_END_ALIGNED=$(( (IMAGE_END + ALIGN-1) & ~(ALIGN-1) ))
IMAGE_END_ALIGNED_HEX=$(printf "0x%x" $IMAGE_END_ALIGNED)
echo FW_PAYLOAD_FDT_OFFSET=$IMAGE_END_ALIGNED_HEX
make -j $NIX_BUILD_CORES $makeFlags \
FW_PAYLOAD_OFFSET=$FW_PAYLOAD_OFFSET \
FW_PAYLOAD_FDT_OFFSET=$IMAGE_END_ALIGNED_HEX
'';

installPhase = ''
# runInLinuxVM will auto create dir $out
rm -rf $out
cp build/platform/generic/firmware/fw_payload.bin $out
'';
passthru = args;
};
overlayfsEnabled = vmTools.runInLinuxVM (overlayfsDisabled.overrideAttrs (old: {
unpackPhase = ''
mkdir workdir
mkdir upperdir
mkdir overlaydir
/run/modprobe fuse
${fuse-overlayfs}/bin/fuse-overlayfs -o lowerdir=${old.src},workdir=workdir,upperdir=upperdir overlaydir
cd overlaydir
'';
memSize = 2048;
}));
in if enableOverlayFS then overlayfsEnabled else overlayfsDisabled
4 changes: 0 additions & 4 deletions docs/designs/4.builders/images/deps_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def __init__(self, **args):
def __init__(self, **args):
CCluster.__init__(self, "opensbi", **args)
self.dts = addNode(self, "dts")
self.common_build = addNode(self, "common-build")
addEdge(self, self.dts, self.common_build, constraint=False)
self.linux = add(self, self.Linux())
def __init__(self, **args):
CCluster.__init__(self, "gcpt", **args, penwidth=3)
Expand Down Expand Up @@ -101,7 +99,6 @@ def __init__(self, name, **args):
addEdge(self, self._level1_, self._level2_, color="transparent")
self.linux = addNode(self._level2_, "linux"); set_colors.gcpt(self.linux)
self.dts = addNode(self._level2_, "dts"); set_colors.gcpt(self.dts)
self.opensbi_common_build = addNode(self._level2_, "opensbi-common-build"); set_colors.gcpt(self.opensbi_common_build)
self.opensbi = addNode(self._level2_, "opensbi"); set_colors.gcpt(self.opensbi)
self.gcpt = addNode(self._level2_, "gcpt"); set_colors.gcpt(self.gcpt)
self.img = addNode(self._level2_, "img"); set_colors.imgBuilder(self.img)
Expand Down Expand Up @@ -140,7 +137,6 @@ def addFlatEdge(g: Graph, n1: Node|CCluster, n2: Node|CCluster, **args):
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.linux.initramfs, output.initramfs)
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.linux, output.linux)
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.dts, output.dts)
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi.common_build, output.opensbi_common_build)
addFlatEdge(graph, builder.imgBuilder.gcpt.opensbi, output.opensbi)
addFlatEdge(graph, builder.imgBuilder.gcpt, output.gcpt)
addFlatEdge(graph, builder.imgBuilder, output.img)
Expand Down

0 comments on commit 0e36fb5

Please sign in to comment.