support aarch64 in tftpboot test

This commit is contained in:
Daniel Barlow 2023-12-19 12:12:12 +00:00
parent e5db2691e5
commit 32c13c46bb
7 changed files with 42 additions and 17 deletions

View file

@ -43,5 +43,9 @@
boot.commandLine = [ boot.commandLine = [
"console=ttyAMA0,38400" "console=ttyAMA0,38400"
]; ];
hardware = let addr = lim.parseInt "0x40010000"; in {
loadAddress = addr;
entryPoint = addr;
};
}; };
} }

View file

@ -70,26 +70,30 @@ in {
in in
pkgs.buildPackages.runCommand "boot-scr" { nativeBuildInputs = [ pkgs.pkgsBuildBuild.dtc ]; } '' pkgs.buildPackages.runCommand "boot-scr" { nativeBuildInputs = [ pkgs.pkgsBuildBuild.dtc ]; } ''
uimageSize=$(($(stat -L -c %s ${o.uimage}) + 0x1000 &(~0xfff))) uimageSize=$(($(stat -L -c %s ${o.uimage}) + 0x1000 &(~0xfff)))
rootfsStart=0x$(printf %x $((${toString cfg.loadAddress} + 0x100000 + $uimageSize &(~0xfffff) ))) rootfsStart=$(printf %x $((${toString cfg.loadAddress} + 0x100000 + $uimageSize &(~0xfffff) )))
rootfsBytes=$(($(stat -L -c %s ${o.rootfs}) + 0x100000 &(~0xfffff))) rootfsBytes=$(($(stat -L -c %s ${o.rootfs}) + 0x100000 &(~0xfffff)))
rootfsBytes=$(($rootfsBytes + ${toString cfg.freeSpaceBytes} )) rootfsBytes=$(($rootfsBytes + ${toString cfg.freeSpaceBytes} ))
rootfsMb=$(($rootfsBytes >> 20)) rootfsMb=$(($rootfsBytes >> 20))
cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes},${toString config.hardware.flash.eraseBlockSize} root=/dev/mtdblock0"; cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,0x''${rootfsStart},''${rootfsBytes},${toString config.hardware.flash.eraseBlockSize} root=/dev/mtdblock0";
dtbStart=$(printf %x $((${toString cfg.loadAddress} + $rootfsBytes + 0x100000 + $uimageSize ))) dtbStart=$(printf %x $((${toString cfg.loadAddress} + $rootfsBytes + 0x100000 + $uimageSize )))
mkdir $out mkdir $out
cat ${o.dtb} > $out/dtb cat ${o.dtb} > $out/dtb
fdtput -p -t s $out/dtb /reserved-memory/phram-rootfs compatible phram fdtput -p $out/dtb /reserved-memory '#address-cells' 2
fdtput -p -t lx $out/dtb /reserved-memory/phram-rootfs reg 0 $rootfsStart 0 $(printf %x $rootfsBytes) fdtput -p $out/dtb /reserved-memory '#size-cells' 2
fdtput -p $out/dtb /reserved-memory ranges
fdtput -p -t s $out/dtb /reserved-memory/phram-rootfs@$rootfsStart compatible phram
fdtput -p -t lx $out/dtb /reserved-memory/phram-rootfs@$rootfsStart reg 0 0x$rootfsStart 0 $(printf %x $rootfsBytes)
# dtc -I dtb -O dts -o /dev/stdout $out/dtb; exit 1
dtbBytes=$(($(stat -L -c %s $out/dtb) + 0x1000 &(~0xfff))) dtbBytes=$(($(stat -L -c %s $out/dtb) + 0x1000 &(~0xfff)))
cat > $out/script << EOF cat > $out/script << EOF
setenv serverip ${cfg.serverip} setenv serverip ${cfg.serverip}
setenv ipaddr ${cfg.ipaddr} setenv ipaddr ${cfg.ipaddr}
setenv bootargs 'liminix ${cmdline} $cmd' setenv bootargs 'liminix ${cmdline} $cmd'
tftpboot 0x${lib.toHexString cfg.loadAddress} result/uimage ; tftpboot 0x$(printf %x $rootfsStart) result/rootfs ; tftpboot 0x$dtbStart result/dtb tftpboot 0x${lib.toHexString cfg.loadAddress} result/uimage ; tftpboot 0x$rootfsStart result/rootfs ; tftpboot 0x$dtbStart result/dtb
bootm 0x${lib.toHexString cfg.loadAddress} - 0x$dtbStart bootm 0x${lib.toHexString cfg.loadAddress} - 0x$dtbStart
EOF EOF
''; '';

View file

@ -200,6 +200,12 @@ extraPkgs // {
strace = prev.strace.override { libunwind = null; }; strace = prev.strace.override { libunwind = null; };
ubootQemuAarch64 = final.buildUBoot {
defconfig = "qemu_arm64_defconfig";
extraMeta.platforms = ["aarch64-linux"];
filesToInstall = ["u-boot.bin"];
};
ubootQemuArm = final.buildUBoot { ubootQemuArm = final.buildUBoot {
defconfig = "qemu_arm_defconfig"; defconfig = "qemu_arm_defconfig";
extraMeta.platforms = ["armv7l-linux"]; extraMeta.platforms = ["armv7l-linux"];

View file

@ -87,7 +87,7 @@
(local bin { (local bin {
:mips ["qemu-system-mips" "-M" "malta"] :mips ["qemu-system-mips" "-M" "malta"]
:aarch64 ["qemu-system-aarch64" "-M" "virt" :aarch64 ["qemu-system-aarch64" "-M" "virt"
"-semihosting" "-cpu" "cortex-a72"] "-cpu" "cortex-a72"]
:arm ["qemu-system-arm" "-M" "virt,highmem=off" :arm ["qemu-system-arm" "-M" "virt,highmem=off"
"-cpu" "cortex-a15"] "-cpu" "cortex-a15"]
}) })

View file

@ -4,8 +4,13 @@ let
dts = pkgs.runCommand "qemu.dts" { dts = pkgs.runCommand "qemu.dts" {
nativeBuildInputs = with pkgs.pkgsBuildBuild; [ dtc qemu ]; nativeBuildInputs = with pkgs.pkgsBuildBuild; [ dtc qemu ];
} '' } ''
qemu-system-arm -machine virt -machine dumpdtb=tmp.dtb qemu-system-${pkgs.stdenv.hostPlatform.qemuArch} \
-machine virt -machine dumpdtb=tmp.dtb
dtc -I dtb -O dts -o $out tmp.dtb dtc -I dtb -O dts -o $out tmp.dtb
# https://stackoverflow.com/a/69890137,
# XXX try fdtput $out -p -t s /pl061@9030000 status disabled
# instead of using sed
sed -i $out -e 's/compatible = "arm,pl061.*/status = "disabled";/g'
''; '';
in { in {
imports = [ imports = [
@ -15,7 +20,7 @@ in {
config = { config = {
hardware.dts.src = lib.mkForce dts; hardware.dts.src = lib.mkForce dts;
boot.tftp = { boot.tftp = {
loadAddress = lim.parseInt "0x42000000"; loadAddress = lim.parseInt "0x44000000";
serverip = "10.0.2.2"; serverip = "10.0.2.2";
ipaddr = "10.0.2.15"; ipaddr = "10.0.2.15";
}; };

View file

@ -1,4 +1,4 @@
set timeout 10 set timeout 30
spawn socat unix-connect:vm/console - spawn socat unix-connect:vm/console -
expect "stop autoboot" expect "stop autoboot"

View file

@ -1,13 +1,15 @@
{ {
liminix liminix
}: }:
let check = deviceName : ubootName :
let derivation = (import liminix { let derivation = (import liminix {
device = import "${liminix}/devices/qemu-armv7l/"; device = import "${liminix}/devices/${deviceName}/";
liminix-config = ./configuration.nix; liminix-config = ./configuration.nix;
}); });
img = derivation.outputs.tftpboot; img = derivation.outputs.tftpboot;
pkgs = derivation.pkgs; uboot = derivation.pkgs.${ubootName};
pkgsBuild = pkgs.pkgsBuildBuild; pkgsBuild = derivation.pkgs.pkgsBuildBuild;
phram = 240 * 1024 * 1024;
in pkgsBuild.runCommand "check" { in pkgsBuild.runCommand "check" {
nativeBuildInputs = with pkgsBuild; [ nativeBuildInputs = with pkgsBuild; [
expect expect
@ -17,15 +19,19 @@ in pkgsBuild.runCommand "check" {
} '' } ''
mkdir vm mkdir vm
ln -s ${img} result ln -s ${img} result
run-liminix-vm \ run-liminix-vm \
--background ./vm \ --background ./vm \
--u-boot ${pkgs.ubootQemuArm}/u-boot.bin \ --u-boot ${uboot}/u-boot.bin \
--arch arm \ --arch ${derivation.pkgs.stdenv.hostPlatform.qemuArch} \
--flag -S \ --phram-address $(printf "0x%x" ${toString phram} ) \
--phram-address 0x40200000 \
--lan "user,tftp=`pwd`" \ --lan "user,tftp=`pwd`" \
--disk-image result/rootfs \ --disk-image result/rootfs \
result/uimage result/rootfs result/uimage result/rootfs
expect ${./script.expect} 2>&1 |tee $out expect ${./script.expect} 2>&1 |tee $out
'' '';
in {
arm = check "qemu-armv7l" "ubootQemuArm";
aarch64 = check "qemu-aarch64" "ubootQemuAarch64";
}