From nobody Sat Dec 16 23:35:17 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 4St2Wm2DX3z53dY3 for ; Sat, 16 Dec 2023 23:35:32 +0000 (UTC) (envelope-from stanislav.silnicki@mailgate.us) Received: from mailgate.us (mailgate.us [185.72.246.236]) by mx1.freebsd.org (Postfix) with ESMTP id 4St2Wj6G9fz3HGJ for ; Sat, 16 Dec 2023 23:35:29 +0000 (UTC) (envelope-from stanislav.silnicki@mailgate.us) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=mailgate.us header.s=mail header.b=XkRt98ZO; spf=pass (mx1.freebsd.org: domain of stanislav.silnicki@mailgate.us designates 185.72.246.236 as permitted sender) smtp.mailfrom=stanislav.silnicki@mailgate.us; dmarc=none Received: from localhost (api.telegram.org [192.168.2.1]) by mailgate.us (Postfix) with ESMTPSA id 8A1857A4DC for ; Sun, 17 Dec 2023 02:35:21 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailgate.us; s=mail; t=1702769722; bh=ocCazKnrgkil/JBAVNvj5TTQ+3wBIzWS6ynFSpmYhy8=; h=From:Subject:To:References:Date; b=XkRt98ZONrPornff0N6MlN6PMlTWQHi19b22q73uQvPWGI8hU2gp4C4uhWcoqdfjZ BIYptdOYAhl5w050SDuwDM+nIfB5RcmiE/tGM7yExCiwCqzPGVs+kOPEJGM5G68mi5 Biq+UWrEPAX7GhfM5lA5iboQAlTmZl47VuZ0khqg= Content-Type: multipart/alternative; boundary="----sinikael-?=_1-17027697189480.8312620581783601" From: Stanislav Silnicki Subject: Re: How to boot FreeBSD for arm 32 bit as DomU with u-boot on my ARM Chromebook X-Type: replyAll To: freebsd-arm@freebsd.org User-Agent: Desktop Message-Id: <97aa980b9b44.6eb7f9d5c54e7@mailgate.us> References: Content-Transfer-Encoding: quoted-printable Date: Sat, 16 Dec 2023 23:35:17 +0000 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 X-Spamd-Result: default: False [-3.39 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; R_SPF_ALLOW(-0.20)[+ip4:185.72.246.236/32]; R_DKIM_ALLOW(-0.20)[mailgate.us:s=mail]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; XM_UA_NO_VERSION(0.01)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_COUNT_ONE(0.00)[1]; MLMMJ_DEST(0.00)[freebsd-arm@freebsd.org]; DKIM_TRACE(0.00)[mailgate.us:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; ASN(0.00)[asn:47447, ipnet:185.72.246.0/24, country:DE]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; DMARC_NA(0.00)[mailgate.us]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-arm@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; MID_RHS_MATCH_FROM(0.00)[] X-Rspamd-Queue-Id: 4St2Wj6G9fz3HGJ X-Spamd-Bar: --- ------sinikael-?=_1-17027697189480.8312620581783601 Content-Type: text/plain; format=flowed Content-Transfer-Encoding: 7bit Hi Mario, U-Boot beast is hiding in this den: https://source.denx.de/u-boot/u-boot.git I took a brief look at your post and it seems to me, that option CONFIG_CMO_BY_VA_ONLY is irrelevant to your target armv7 32 bit platform: https://source.denx.de/u-boot/u-boot/-/blob/master/arch/arm/cpu/armv8/Kconfig?ref_type=heads#L3 As for compiling the u-boot, it is a doable task, given that you understand what you are doing. There are no specific options in u-boot devoted to FreeBSD. It is a boot loader, whose mission to make basic hardware initialization, read you kernel file from some media into RAM and then pass it control. Basically, you can grab some defconfig, prepared for any other Exynos5250 based board (say, this one: https://source.denx.de/u-boot/u-boot/-/blob/master/configs/arndale_defconfig?ref_type=heads) and adopt it somehow. As per my experience, you have to respect these two options, compiling u-boot for FreeBSD: https://github.com/freebsd/freebsd-ports/blob/main/sysutils/u-boot-master/files/FreeBSD_Fragment As I understand, it makes sure, that u-boot keeps in secure mode during boot and passes control to ubldr, which boots FreBSD kernel, in that mode. Otherwise, there a lot of surprises you may realize. Hope, this will help to progress you tasks Stan Mario Marietto wrote: 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. ------sinikael-?=_1-17027697189480.8312620581783601 Content-Type: text/html; format=flowed Content-Transfer-Encoding: 7bit
Hi Mario,

U-Boot  beast is hiding in this den: https://source.denx.de/u-boot/u-boot.git
I took a brief look at your post and it seems to me, that option CONFIG_CMO_BY_VA_ONLY is irrelevant to your target armv7 32 bit platform: https://source.denx.de/u-boot/u-boot/-/blob/master/arch/arm/cpu/armv8/Kconfig?ref_type=heads#L3

As for compiling the u-boot, it is a doable task, given that you understand what you are doing. There are no specific options in u-boot devoted to FreeBSD. It is a boot loader, whose mission to make basic hardware initialization, read you kernel file from some media into RAM and then pass it control.

Basically, you can grab some defconfig, prepared for any other Exynos5250 based board  (say, this one: https://source.denx.de/u-boot/u-boot/-/blob/master/configs/arndale_defconfig?ref_type=heads) and adopt it somehow.

As per my experience, you have to respect these two options, compiling u-boot for FreeBSD: https://github.com/freebsd/freebsd-ports/blob/main/sysutils/u-boot-master/files/FreeBSD_Fragment

As I understand, it makes sure, that u-boot keeps in secure mode during boot and passes control to ubldr, which boots FreBSD kernel, in that mode. Otherwise, there a lot of surprises you may realize.

Hope, this will help to progress you tasks
Stan

Mario Marietto wrote:


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.
------sinikael-?=_1-17027697189480.8312620581783601--