From nobody Sat Dec 16 22:17:14 2023 X-Original-To: freebsd-arm@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4St0p93ybTz52nvt for ; Sat, 16 Dec 2023 22:17:53 +0000 (UTC) (envelope-from marietto2008@gmail.com) Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4St0p853nKz3C0k for ; Sat, 16 Dec 2023 22:17:52 +0000 (UTC) (envelope-from marietto2008@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=doQass3o; spf=pass (mx1.freebsd.org: domain of marietto2008@gmail.com designates 2a00:1450:4864:20::62f as permitted sender) smtp.mailfrom=marietto2008@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a1f8f470903so217644466b.1 for ; Sat, 16 Dec 2023 14:17:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702765071; x=1703369871; darn=freebsd.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=k3B7BNb8xnjDyZzGYaXM5XDaja5ledbXvZq84Jpsj0s=; b=doQass3oU+HHYGr5TILH4ALcEfA/4toaMgghnfMNAJ7zcFIfgREzn2z8d0DsyBoY25 MONkRZr1l9Y3x7i7qf/IA6LfKTE0Jyl7qhZSVggZXv+zfw37jGOQQFlGqh7RbOzECHQg S8GHPWxm3Mr9ZirVFNo1FP6FSyF8r3Ee3DiKtcwdXXhWjEY+P/S3GQpubxjK0yjTYlCr wXbjdn51nPm66B0Y9Oz1xqfpxth2I4otC/9SLkpeKlK3KMo9DTiuDJVpyj/0M7GDPBj3 OaRYozIbzg87HF6C2UmaXe0/2ZSysgvAJuZnNTExGo++BgH8yNlmmsrEuXktumTVQd75 h2Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702765071; x=1703369871; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=k3B7BNb8xnjDyZzGYaXM5XDaja5ledbXvZq84Jpsj0s=; b=MuPwDOuM/+mTBU3qE1UECSnKDU2af+dI3Txto6X2ndUDuCfxnUArXCVzxx1SVrcAr1 Xytig580klaSMC4U/GOF+HOzNvRAaBG7Jc/oGzXU04Hd8RVtV8tW415VoDEHfsuh6QE/ QMcMWj4PxqTRf7erspZtsom4hFXlxp8bNJ9h1piQtbTI5YXuUtnkEysJhS/xFHjZHv1L txdo2AYAzhw59Z1Eyxz48NP4WBxfiDx7CNRzMPXaQr3MlnG550QHhgwFsibdeZ1b9rym Hy7CAuiSO/+I4kh4rcOa2IFNqiuFgqQl3tzJsXV9PYmmcud+Torer5v3HkijyoqlsEEU ThAA== X-Gm-Message-State: AOJu0YwGEm6NCdVjy4LpKSMjw/ptdYZmzsQo5pK+qUVQNkC/kTWqH7Ki j+tMD8I1E2rZcJuCcU+QTl2sM19uyzMxkbgOK4vGkbgJLAM= X-Google-Smtp-Source: AGHT+IFFaqB6yQRF7Pbc5d5kBxpB65lJ0pFSUTcok0WBKOe+zTMP5AQE+yNl25K5IKmXEm29lxhpAAnOCBBTUzqy2EY= X-Received: by 2002:a17:906:a054:b0:a19:a19b:c72f with SMTP id bg20-20020a170906a05400b00a19a19bc72fmr6864693ejb.127.1702765070667; Sat, 16 Dec 2023 14:17:50 -0800 (PST) List-Id: Porting FreeBSD to ARM processors List-Archive: https://lists.freebsd.org/archives/freebsd-arm List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arm@freebsd.org MIME-Version: 1.0 From: Mario Marietto Date: Sat, 16 Dec 2023 23:17:14 +0100 Message-ID: Subject: How to boot FreeBSD for arm 32 bit as DomU with u-boot on my ARM Chromebook To: freebsd-arm@freebsd.org Content-Type: multipart/alternative; boundary="0000000000002c52af060ca7e3fa" X-Spamd-Result: default: False [-3.97 / 15.00]; NEURAL_HAM_LONG(-0.99)[-0.993]; NEURAL_HAM_MEDIUM(-0.99)[-0.992]; NEURAL_HAM_SHORT(-0.99)[-0.986]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; FREEMAIL_ENVFROM(0.00)[gmail.com]; RCVD_COUNT_ONE(0.00)[1]; FROM_EQ_ENVFROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-arm@freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::62f:from]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ARC_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; PREVIOUSLY_DELIVERED(0.00)[freebsd-arm@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; TO_DN_NONE(0.00)[]; MID_RHS_MATCH_FROMTLD(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] X-Rspamd-Queue-Id: 4St0p853nKz3C0k X-Spamd-Bar: --- --0000000000002c52af060ca7e3fa Content-Type: text/plain; charset="UTF-8" Hello. I'm trying to boot FreeBSD for arm32 bit as DomU on my ARM Chromebook. Basically there are two ways to accomplish this task : 1) to write a patch that allows the FreeBSD kernel to boot as a zImage file. This could be accomplished applying this patch to a specific file that's on the source code of FreeBSD : https://xenbits.xen.org/gitweb/?p=p...8;hb=0782e25d98cc1391472717035f986c979edef0c9 This patch was written by Julien Grall a lot of time ago and now it does not work anymore. This is the reason : It appears FreeBSD-CURRENT removed the last step converting the kernel file to kernel.bin. The patch can be readily rebased, but without kernel.bin that doesn't do too much. So,without a rebase of that patch the first option is not applicable. And I'm not able to fix it. 2) booting FreeBSD using U-Boot,as explained to me by a xen developer : I was trying to explain why and how Julien's patch works so that you could be the one to re-do something similar or fix the patch on the FreeBSD kernel that you are working with. I am happy to help review and write patches but I don't work with the FreeBSD kernel so I wouldn't be able to help you quickly. However, I might have a suggestion. Do you know if FreeBSD can be booted by U-Boot ? Because U-Boot definitely boots as Xen on ARM guest firmware/bootloader. You should be able to build U-Boot and use the U-Boot binary as Xen guest kernel, then U-Boot could load FreeBSD from disk or network and start it. For instance as domU config file: kernel="/home/petalinux/u-boot.bin" disk = [ '/home/petalinux/test.img,raw,xvda' ] I know it is important to build u-boot with the following config to make it work on Xen. CONFIG_CMO_BY_VA_ONLY=y This option seems more doable to me according to my knowledge. But I need to understand how to do it. Well,let's say that on the ARM Chromebook I'm forced to use and install a customized version of u-boot,created by virtual open systems,because it is the only one that allows bypassing its bootloader protection. You can find more information here : http://www.virtualopensystems.com/en/solutions/guides/kvm-on-chromebook/?vos=tech This is the relevant section to read : Bootloader : If you wish to skip this chapter you can download a pre-compiled binary of the bootloader: $ wget http://www.virtualopensystems.com/downloads/guides/kvm_on_chromebook/nv_u-boot-snow.kpart To be able to run KVM on ARM platforms, the kernel has to be booted in hypervisor mode. Because of this relatively recent requirement (due to the introduction of the virtualization extensions), up until now all booting methods would boot the kernel in the standard Supervisor mode. For the ARM Chromebook the default boot procedure doesn't allow us to boot in hypervisor mode. Although the laptop's boot mechanism is based on the frequently used u-boot, the binary is located in RO memory. Fortunately, a chained u-boot mechanism can be used (i.e. starting another u-boot after the original). We can then enter hypervisor mode from our custom iteration of u-boot and subsequently load our kernel and userspace. Checkout the needed u-boot code : $ git clone git://github.com/virtualopensystems/u-boot.git$ cd u-boot$ ./scripts/build.sh If successful, a message about how to copy the bootloader on the USB flash disk or SD card will appear. We will use it later when preparing the boot medium to start our system. If you have followed the Setting up the boot medium chapter and you have a prepared boot device, then you can update u-boot by running : $ sudo dd if=nv_uboot-snow.kpart of=/dev/sdX1 so,the needed u-boot that we must use should be installed on the first partition of the sd card. There is another relevant section to read : Setting up the boot medium Now it is time to copy all the relevant files that we created in the previous chapters,and use them to boot Chromebook with a different kernel and OS. In all these examples the device /dev/sdX is used. Take extra care to change the examples to the device that you have attached. Insert the boot medium on your workstation and carefully execute the following step. First we need to properly format the boot medium. In the uboot source directory : $ sudo ./scripts/sdcard.sh /dev/sdX This will erase all data and create 4 partitions in the medium, along with copying the u-boot binary to the first partition: Partition 1 = ChromeOS signed binary (V.O.S chained u-boot) Partition 2 = not used Partition 3 = EXT2 partition for u-boot files (uImage and exynos5250-snow.dtb) Partition 4 = EXT4 partition for userspace files With u-boot being copied, next is the kernel image and DTB file. From the kernel source execute : $ mkdir ../mnt/ $ sudo mount /dev/sdX3 ../mnt/ $ sudo cp arch/arm/boot/uImage ../mnt/ $ sudo cp arch/arm/boot/dts/exynos5250-snow.dtb ../mnt/ $ sudo umount /dev/sdX3 Finally, we have to copy the Ubuntu userspace filesystem that we created earlier: $ sudo mount /dev/sdX4 mnt/$ sudo cp -a ./precise/* mnt/$ sudo umount /dev/sdX4 Now,my idea is to chainload the already chain loaded u-boot created by V.O.S to the new u-boot that we need for booting FreeBSD and that can be installed in the partition n.2,as shown in this scheme,because it is not used : Partition 1 = ChromeOS signed binary (V.O.S chained u-boot) Partition 2 = not used (maybe we can install the u-boot for arm 32 bit,compatible with FreeBSD on this partition) Partition 3 = EXT2 partition for u-boot files (uImage and exynos5250-snow.dtb) Partition 4 = EXT4 partition for userspace files Take in consideration that default boot string is hardcoded here,in the snow.h file of the custom u-boot created by VOS : https://github.com/virtualopensyste...18a39b6c177dff58a/include/configs/snow.h#L101 and it needs to be recompiled because it should point to the partition n.2,where I will install the u-boot files as explained here : https://wiki.freebsd.org/arm/Chromebook I have some questions to ask before I start working on this. 1) The xen developer said : You should be able to build U-Boot and use the U-Boot binary as Xen guest kernel... where is the u-boot binary,according to this document ? https://wiki.freebsd.org/arm/Chromebook I don't see it. 2) where is the source code of the file that I can get here : http://commondatastorage.googleapis.com/chromeos-localmirror/distfiles/nv_uboot-snow-simplefb.kpart.bz2 I need the source code if I want to recompile u-boot so that it can point to the partition 4. Maybe it can be found on this link : http://linux-exynos.org/dist/chromebook/nv_uboot/ but it can't be opened.... 3) in this specific scenario the source code of u-boot should run on arm 32 bit,not on arm 64,because I have the Samsung Chromebook "SNOW" model XE303C12,that's powered by a Samsung Exynos 5250 (ARMv7 32 bit Cortex A15) Soc. 4) I'm not sure if I can chainload the customized u-boot created by V.O.S that should be installed on the first partition with the u-boot tailored for booting FreeBSD that should be installed on the partition 2.... 5) the xen developer said that u-boot should be compiled enabling this option : Code: CONFIG_CMO_BY_VA_ONLY=y Well,can you provide some good source that can help me to understand how I can recompile u-boot for FreeBSD ? thanks. -- Mario. --0000000000002c52af060ca7e3fa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
<= div id=3D"gmail-:1ay" class=3D"gmail-a3s gmail-aiL">
Hello.=

I'm trying to boot FreeBSD for arm32 bit as DomU on my ARM Chromebook. = Basically there are two ways to accomplish this task :

1) to write a patch that allows the FreeBSD kernel to boot as a zImage=20 file. This could be accomplished applying this patch to a specific file=20 that's on the source code of FreeBSD :


https://xenbits.xen.org/gitweb/?p=3Dp...8;hb= =3D0782e25d98cc1391472717035f986c979edef0c9


This patch was written by Julien Grall a lot of time ago and now it does no= t work anymore. This is the reason :


=09
=09
It appears FreeBSD-CURRENT removed the last step converting the=20 kernel file to kernel.bin. The patch can be readily rebased, but without kernel.bin that doesn't do too much.
=09


So,without a rebase of that patch the first option is not applicable. And I= 'm not able to fix it.

2) booting FreeBSD using U-Boot,as explained to me by a xen developer :


=09
=09
I was trying to explain why and how Julien's patch works so that you= =20 could be the one to re-do something similar or fix the patch on the=20 FreeBSD kernel that you are working with. I am happy to help review and=20 write patches but I don't work with the FreeBSD kernel so I wouldn'= t be=20 able to help you quickly. However, I might have a suggestion. Do you=20 know if FreeBSD can be booted by U-Boot ? Because U-Boot definitely=20 boots as Xen on ARM guest firmware/bootloader. You should be able to=20 build U-Boot and use the U-Boot binary as Xen guest kernel, then U-Boot=20 could load FreeBSD from disk or network and start it. For instance as=20 domU config file:

kernel=3D"/home/petalinux/u-boot.bin"
disk =3D [ '/home/petalinux/test.img,raw,xvda' ]

I know it is important to build u-boot with the following config to make it= work on Xen.

CONFIG_CMO_BY_VA_ONLY=3Dy
=09


This option seems more doable to me according to my knowledge. But I need t= o understand how to do it.

Well,let's say that on the ARM Chromebook I'm forced to use and ins= tall a customized version of u-boot,created by virtual open systems,because it is the only one that allows bypassing its bootloader protection. You=20 can find more information here :

http:/= /www.virtualopensystems.com/en/solutions/guides/kvm-on-chromebook/?vos=3Dte= ch

This is the relevant section to read :


=09
=09
Bootloader :

If you wish to skip this chapter you can download a pre-compiled binary of = the bootloader:


$ wget http://www.virtualopensystems.com/downloads/guides/kvm_on_chromebook= /nv_u-boot-snow.kpart


To be able to run KVM on ARM platforms, the kernel has to be booted in=20 hypervisor mode. Because of this relatively recent requirement (due to=20 the introduction of the virtualization extensions), up until now all=20 booting methods would boot the kernel in the standard Supervisor mode.=20 For the ARM Chromebook the default boot procedure doesn't allow us to= =20 boot in hypervisor mode. Although the laptop's boot mechanism is based= =20 on the frequently used u-boot, the binary is located in RO memory.=20 Fortunately, a chained u-boot mechanism can be used (i.e. starting=20 another u-boot after the original). We can then enter hypervisor mode=20 from our custom iteration of u-boot and subsequently load our kernel and userspace.

Checkout the needed u-boot code :


$ git clone git://github.com/virtualopens= ystems/u-boot.git$ cd u-boot$ ./scripts/build.sh


If successful, a message about how to copy the bootloader on the USB=20 flash disk or SD card will appear. We will use it later when preparing=20 the boot medium to start our system. If you have followed the Setting up the boot medium chapter and you have a prepared boot device, then you=20 can update u-boot by running :


$ sudo dd if=3Dnv_uboot-snow.kpart of=3D/dev/sdX1
=09


so,the needed u-boot that we must use should be installed on the first part= ition of the sd card.

There is another relevant section to read :


=09
=09
Setting up the boot medium

Now it is time to copy all the relevant files that we created in the=20 previous chapters,and use them to boot Chromebook with a different=20 kernel and OS. In all these examples the device /dev/sdX is used. Take=20 extra care to change the examples to the device that you have attached.=20 Insert the boot medium on your workstation and carefully execute the=20 following step. First we need to properly format the boot medium.

In the uboot source directory :


$ sudo ./scripts/sdcard.sh /dev/sdX


This will erase all data and create 4 partitions in the medium, along with = copying the u-boot binary to the first partition:


Partition 1 =3D ChromeOS signed binary (V.O.S chained u-boot)
Partition 2 =3D not used
Partition 3 =3D EXT2 partition for u-boot files (uImage and exynos5250-snow= .dtb)
Partition 4 =3D EXT4 partition for userspace files


With u-boot being copied, next is the kernel image and DTB file. From the k= ernel source execute :


$ mkdir ../mnt/
$ sudo mount /dev/sdX3 ../mnt/
$ sudo cp arch/arm/boot/uImage ../mnt/
$ sudo cp arch/arm/boot/dts/exynos5250-snow.dtb ../mnt/
$ sudo umount /dev/sdX3


Finally, we have to copy the Ubuntu userspace filesystem that we created ea= rlier:


$ sudo mount /dev/sdX4 mnt/$ sudo cp -a ./precise/* mnt/$ sudo umount /dev/= sdX4
=09


Now,my idea is to chainload the already chain loaded u-boot created by=20 V.O.S to the new u-boot that we need for booting FreeBSD and that can be installed in the partition n.2,as shown in this scheme,because it is=20 not used :


Partition 1 =3D ChromeOS signed binary (V.O.S chained u-boot)
Partition 2 =3D not used (maybe we can install the u-boot for arm 32 bit,co= mpatible with FreeBSD on this partition)
Partition 3 =3D EXT2 partition for u-boot files (uImage and exynos5250-snow= .dtb)
Partition 4 =3D EXT4 partition for userspace files


Take in consideration that default boot string is hardcoded here,in the sno= w.h file of the custom u-boot created by VOS :


https://github.com/virtualopensyste...18a39b6c= 177dff58a/include/configs/snow.h#L101


and it needs to be recompiled because it should point to the partition=20 n.2,where I will install the u-boot files as explained here :


https://wiki.freebsd.org/arm/Chromebook


I have some questions to ask before I start working on this.

1) The xen developer said :


=09
=09
You should be able to build U-Boot and use the U-Boot binary as Xen gues= t kernel...
=09


where is the u-boot binary,according to this document ?

https://wiki.freebsd.org/arm/Chromebook

I don't see it.


2) where is the source code of the file that I can get here :

http://commondatastorage.googleapis.com/ch= romeos-localmirror/distfiles/nv_uboot-snow-simplefb.kpart.bz2

I need the source code if I want to recompile u-boot so that it can point t= o the partition 4.

Maybe it can be found on this link :

http://linux-exynos.org/dist/chromebook/= nv_uboot/

but it can't be opened....


3) in this specific scenario the source code of u-boot should run on arm 32 bit,not on arm 64,because I have the Samsung Chromebook "SNOW"= ; model XE303C12,that's powered by a Samsung Exynos 5250 (ARMv7 32 bit Cortex= =20 A15) Soc.


4) I'm not sure if I can chainload the customized u-boot created by=20 V.O.S that should be installed on the first partition with the u-boot=20 tailored for booting FreeBSD that should be installed on the partition=20 2....


5) the xen developer said that u-boot should be compiled enabling this opti= on :


=09 =09
Code:

CONFIG_CMO_BY_VA_ONLY=3Dy


Well,can you provide some good source that can help me to understand how I = can recompile u-boot for FreeBSD ? thanks.

--
Mario.
--0000000000002c52af060ca7e3fa--