无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 14151|回复: 35
打印 上一主题 下一主题

GRUB 支持 ARM 架构?求确认!

  [复制链接]
跳转到指定楼层
1#
发表于 2017-4-12 23:24:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
今天浏览 debian 的网站,发现:

https://d-i.debian.org/daily-images/arm64/20170412-02:07/netboot/debian-installer/arm64/

天啊!grub 已经支持 ARM64 了!是真的吗?是我老眼昏花看错了吗?有谁知道的,麻烦说说详情。


Index of /daily-images/arm64/20170412-02:07/netboot/debian-installer/arm64  

NameLast modifiedSize

Parent Directory
-
bootnetaa64.efi
2017-04-12 02:06
448K
grub/
2017-04-12 02:06
-
initrd.gz
2017-04-12 02:06
21M
linux
2017-04-12 02:06
13M



请看那些文件,居然有 EFI 文件!请问 ARM 体系也使用 EFI 吗?

如果 grub 能用的话,那是不是说,以后就可以扔掉 U-boot 了?


2#
发表于 2017-4-13 06:31:34 来自手机 | 只看该作者
grub2支持efi没有疑问。arm用efi确实不清楚。
回复

使用道具 举报

3#
发表于 2017-4-13 07:05:58 | 只看该作者
支持。较新的arm设备都是支持uefi的,因此grub-arm可以通过efi shell启动。
甚至部分解锁了bootloader的手机都可以通过efidroid加载grub。
http://efidroid.org
回复

使用道具 举报

4#
发表于 2017-4-13 07:49:11 来自手机 | 只看该作者
哦,对了arm设备在支持桌面系统。
回复

使用道具 举报

5#
 楼主| 发表于 2017-4-13 08:42:18 | 只看该作者
谢谢,非常感谢。很高兴这么快就解惑了。也谢谢 wintoflash 提供链接,让我可以更进一步了解。

回复

使用道具 举报

6#
发表于 2017-4-13 12:27:56 | 只看该作者
学习了,很好很强大
回复

使用道具 举报

7#
 楼主| 发表于 2017-4-16 22:13:54 | 只看该作者
Running ARM Grub on U-Boot on QEMU


At the Mini-debconf in Cambridge back in November there was an ARM Sprint (which Hectorwrote up as a Bits from ARMportersmail). During this there a brief discussion about using GRUB as a standard bootloader, particularly for ARM server devices. This has the advantage of providing a more "normal" (which in practice means "x86 server-like")as well as flexible solution compared with the existing flash-kernel tool which is often used on ARM.
On ARMv7 devices this will more than likely involve chain loading from the U-Boot supplied by the manufacturer. For test and development it would be useful to be able to set up a similar configuration using Qemu.

Cross-compilers


Although this can be built and run on an ARM system I am using a cross compiler here. I'm using gcc-linaro-arm-linux-gnueabihf-4.8-2013.08_linux from Linaro, which can be downloaded from the linaro-toolchain-binaries page on Launchpad. (It looks like 2013.10 is the latest available right now, I can't see any reason why that wouldn't be fine).
Once the cross-compiler has been downloaded unpack it somewhere, Iwill refer to the resultinggcc-linaro-arm-linux-gnueabihf-4.8-2013.08_linux directory as $CROSSROOT.
Make sure $CROSSROOT/bin (which contains arm-linux-gnueabihf-gcc etc) is in your $PATH.


Qemu

I'm using the version packaged in Jessie, which is 1.7.0+dfsg-2. We need both qemu-system-arm for running the final system and qemu-user to run some of the tools. I'd previously tried an older version of qemu (1.6.x?) and had some troubles, although they may have been of my own making...

Das U-boot for Qemu

First thing to do is to build a suitable u-boot for use in the qemuemulated environment. Since we need to make some configuration changes, we need to build from scratch.
Start by cloning the upstream git tree:


$ git clone git://git.denx.de/u-boot.git
$ cd u-boot


I am working on top of e03c76c30342 "powerpc/mpc85xx: Update CONFIG_SYS_FSL_TBCLK_DIV for T1040" dated Wed Dec 11 12:49:13 2013+0530.
We are going to use the Versatile Express Cortex-A9 u-boot but first we need to enable some additional configuration options:

  • CONFIG_API -- This enables the u-boot API which Grub uses to access the lowlevel services provided by u-boot. This means that grub doesn't need to contains dozens of platform specific flash, mmc, nand, network, console drivers etc and can be completely platform agnostic.
  • CONFIG_SYS_MMC_MAX_DEVICE -- Setting CONFIG_API needs this.
  • CONFIG_CMD_EXT2 -- Useful for accessing EXT2 formatted filesystems. In this example I use a VFAT /boot for convenience but in a real system we would want to use EXT2 (or even something more modern)).
  • CONFIG_CMD_ECHO -- Just useful.


You can add all these to include/configs/vexpress_common.h:

#define CONFIG_API
#define CONFIG_SYS_MMC_MAX_DEVICE   1
#define CONFIG_CMD_EXT2
#define CONFIG_CMD_ECHO

Or you can apply the patch which I sent upstream:

$ wget -O - http://patchwork.ozlabs.org/patch/304786/raw | git apply --index
$ git commit -m "Additional options for grub-on-uboot"

Finally we can build u-boot:

$ make CROSS_COMPILE=arm-linux-gnueabihf-  vexpress_ca9x4_config
$ make CROSS_COMPILE=arm-linux-gnueabihf-

The result is a u-boot binary which we can load with qemu.

GRUB for ARM

Next we can build grub. Start by cloning the upstream git tree:

$ git clone git://git.sv.gnu.org/grub.git
$ cd grub

By default grub is built for systems which have RAM at address0x00000000. However the Versatile Express platform which we aretargeting has RAM starting from 0x60000000 so we need to make a couple of modifications. First in grub-core/Makefile.core.def we need to change arm_uboot_ldflags, from:

-Wl,-Ttext=0x08000000

to

-Wl,-Ttext=0x68000000

and second we need make a similar change to include/grub/offsets.h changing GRUB_KERNEL_ARM_UBOOT_LINK_ADDR from 0x08000000 to 0x68000000.

Now we are ready to build grub:

$ ./autogen.sh
$ ./configure --host arm-linux-gnueabihf
$ make

Now we need to build the final grub "kernel" image, normally this would be taken care of by grub-install but because we are cross building grub we cannot use this and have to use grub-mkimage directly. However the version we have just built is for the ARM target and not for host we are building things on. I've not yet figured out how to build grub for ARM while building the tools for the host system(I'm sure it is possible somehow...). Luckily we can use qemu to runthe ARM binary:

$ cat load.cfg
set prefix=(hd0)
$ qemu-arm -r 3.11 -L $CROSSROOT/arm-linux-gnueabihf/libc  ./grub-mkimage -c load.cfg -O arm-uboot -o core.img -d grub-core/   fat ext2 probe terminal scsi ls linux elf msdospart normal help echo

Here we create load.cfg which is the setup script which will be built into the grub kernel, our version just sets the root device so that grub can find the rest of its configuration.

Then we use qemu-arm-static to invoke grub-mkimage. The "-r 3.11"option tells qemu to pretend to be a 3.11 kernel (which is required by the libc used by our cross compiler, without this you will get a fatal: kernel too old message) and "-L $CROSSROOT/..." tells it where to find the basic libraries, such as the dynamic linker (luckily grub-mkimage doesn't need much in the way of libraries so we don't need a full cross library environment.

The grub-mkimage command passes in the load.cfg and requests an output kernel targeting arm-uboot, core.img is the output file and the modules are in grub-core (because we didn't actually install grub in the target system, normally these would be found in /boot/grub). Lastly we pass in a list of default modules to build into the kernel, including filesystem drivers (fat, ext2), disk drivers(scsi), partition handling (msdos), loaders (linux, elf), the menu system (normal) and various other bits and bobs.

So after all that, we now have our grub kernel in core.img.


Putting it all together

Before we can launch qemu we need to create various disk images.

Firstly we need some images for the 2 64M flash devices:

$ dd if=/dev/zero of=pflash0.img bs=1M count=64
$ dd if=/dev/zero of=pflash1.img bs=1M count=64

We will initialise these later from the u-boot command line.

Secondly we need an image for the root filesystem on an MMC device. I'm using a FAT formatted image here simply for the convenience of using mtools to update the images during development.

$ dd if=/dev/zero of=mmc.img bs=1M count=16
$ /sbin/mkfs.vfat mmc.img

Thirdly we need a kernel, device tree and grub configuration on our root filesystem. For the first two I extracted them from the standardarmmp kernel flavour package. I used the backports.org version 3.11-0.bpo.2-armmp version and extracted /boot/vmlinuz-3.11-0.bpo.2-armmp as vmlinuz and /usr/lib/linux-image-3.11-0.bpo.2-armmp/vexpress-v2p-ca9.dtb as dtb. Then I hand coded a simple grub.cfg:

menuentry 'Linux' {
        echo "Loading vmlinuz"
        set root='hd0'
        linux /vmlinuz console=ttyAMA0 ro debug
        devicetree /dtb
}

In a real system the kernel and dtb would be provided by the kernelpackages and grub.cfg would be generated by update-grub.

Now that we have all the bits we need copy them into the root ofmmc.img. Since we are using a FAT formatted image we can usemcopy from the mtools package.

$ mcopy -v -o -n -i mmc.img core.img dtb vmlinuz grub.cfg ::

Finally after all that, we can run qemu passing it our u-boot binary and the mmc and flash images and requesting a Cortex-A9 based Versatile Express system with 1GB of RAM:

$ qemu-system-arm -M vexpress-a9 -kernel u-boot -m 1024m -sd mmc.img   -nographic -pflash pflash0.img -pflash pflash1.img

Then at the VExpress# prompt we can configure the default bootcmd to load grub and save the environment to the flash images. The backslash escapes (\$ and \;) should be included as written here so that e.g. the variables are only evaluated when bootcmd is evaluated and not immediately when setting bootcmd and the bootm is set as part of bootcmd instead of executed immediately:

VExpress# setenv bootcmd fatload mmc 0:0 \${loadaddr} core.img \; bootm \${loadaddr}
VExpress# saveenv

Now whenever we boot the system it will automatically load boot grub from the mmc and launch it. Grub in turn will load the Linux binary and DTB and launch those. I haven't actually configure Linux with a root filesystem here so it will eventually panic after failing to find root.


Future work

The most pressing issue is the hard coded load address built in to the grub kernel image. This is something which needs to be discussed with the upstream grub maintainers as well as the Debian package maintainers.

Now that the ARM packages have hit Debian (in experimental in the 2.02~beta2-1 package) I also plan to start looking at debian-installer integration as well as updating flash-kernel to setup the chain load of grub instead of loading a kernel directly.


RSS   Atom
Forgot to mention...

... that it is possible to debug things using gdb via qemu. First add -s -S to the qemu-system-arm command line, where -s is short for -gdb tcp::1234 (i.e. start a remote gdb server on TCP port 1234) and -S means wait for gdb to connect before starting.

Then run arm-linux-gnueabihf-gdb grub-core/kernel.exec and run:

(gdb) target remote :1234
(gdb) b *0x68000000
(gdb) c

This will connect to qemu, set a break point at the grub entry point and then continue.
I've also found that you can build grub twice, once for x86 and once for arm-uboot and then use the x86 version of grub-mkimage to build an arm-boot image. Eventually once the ARM support hits the Debian archive I presume the installed version of grub-mkimage would be fine but in the meantime something like this seems to do the trick:

$ ( mkdir obj-arm && cd obj-arm && ./configure --host arm-linux-gnueabihf && make )
$ ( mkdir obj-x86 && cd obj-x86 && ./configure && make )
$ ./obj-x86/grub-mkimage -c load.cfg -O arm-uboot -o core.img -d obj-arm/grub-core   fat ext2 probe terminal scsi ls linux elf msdospart normal help echo

Lastly I've made some progress on getting grub-mkimage to relocate the arm-uboot flavour of grub at runtime instead of hardcoding a particular ram address. I don't know if it will be acceptable upstream but it works for me and I'll send it along once I've cleaned it up a bit.

点评

我现在用的就是arm国产操作系统,而且是grub启动的,不过grub文件夹被隐藏了,不让看,不知道为什么不让看  详情 回复 发表于 2021-8-9 13:58
回复

使用道具 举报

8#
 楼主| 发表于 2017-4-17 21:35:14 | 只看该作者
在 firefly 上,grub 编译成功了。编译步骤如下:

$ git clone git://git.sv.gnu.org/grub.git
$ cd grub
$ ./autogen.sh
$ ./configure       注意:不要带参数 “--host arm-linux-gnueabihf”,带参数反而失败。
$ make

下一步该怎么办?谁能帮一把?

点评

是不是需要先刷入UEFI的固件? 上谷歌搜了一下,树莓派有UEFI的固件:https://github.com/ms-iot/RPi-UEFI。不过这对于Firefly应该没什么用。 另外搜到这篇文章:http://www.cnx-software.com/2016/08/11/u-boot-n  详情 回复 发表于 2017-4-17 22:26
回复

使用道具 举报

9#
发表于 2017-4-17 22:26:50 | 只看该作者
不点 发表于 2017-4-17 21:35
在 firefly 上,grub 编译成功了。编译步骤如下:

$ git clone git://git.sv.gnu.org/grub.git

是不是需要先刷入UEFI的固件?
上谷歌搜了一下,树莓派有UEFI的固件:https://github.com/ms-iot/RPi-UEFI。不过这对于Firefly应该没什么用。
另外搜到这篇文章:http://www.cnx-software.com/2016 ... -bit-arm-platforms/

点评

谢谢。 在编译结果里面,没有找到一个 .efi 文件,那是不是说,就不能用于 EFI 启动? 找到的 .img 文件只有一个,就是 firefly@firefly:~/grub$ ll */*.img -rw-rw-r-- 1 firefly firefly 93448 4月 17  详情 回复 发表于 2017-4-18 06:48
回复

使用道具 举报

10#
 楼主| 发表于 2017-4-18 06:48:25 | 只看该作者
wintoflash 发表于 2017-4-17 22:26
是不是需要先刷入UEFI的固件?
上谷歌搜了一下,树莓派有UEFI的固件:https://github.com/ms-iot/RPi-UE ...

谢谢。

在编译结果里面,没有找到一个 .efi 文件,那是不是说,就不能用于 EFI 启动?

找到的 .img 文件只有一个,就是

firefly@firefly:~/grub$ ll */*.img
-rw-rw-r-- 1 firefly firefly 93448 4月  17 13:26 grub-core/kernel.img

firefly@firefly:~/grub$ file grub-core/kernel.img
grub-core/kernel.img: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), not stripped

都不像是用于 EFI 启动的。

点评

sudo make install 然后用grub-mkimage制作出efi可执行文件。  详情 回复 发表于 2017-4-18 07:11
回复

使用道具 举报

11#
发表于 2017-4-18 07:11:51 | 只看该作者
不点 发表于 2017-4-18 06:48
谢谢。

在编译结果里面,没有找到一个 .efi 文件,那是不是说,就不能用于 EFI 启动?

sudo make install
然后用grub-mkimage制作出efi可执行文件。
回复

使用道具 举报

12#
发表于 2017-4-18 07:15:31 | 只看该作者
本帖最后由 wintoflash 于 2017-4-18 07:16 编辑

看你提供的教程应该是
grub-mkimage -c load.cfg -O arm-uboot -o core.img fat ext2 probe terminal scsi ls linux elf msdospart normal help echo
其中load.cfg是内置菜单,需要自己写一下。
输出的文件是arm-uboot。
回复

使用道具 举报

13#
 楼主| 发表于 2017-4-18 12:47:57 | 只看该作者

  1. firefly@firefly:~/grub$ ./grub-mkimage -c load.cfg -O arm-uboot -o core.img fat ext2 probe terminal scsi ls linux elf msdospart normal help echo
  2. Prefix not specified (use the -p option).
  3. 用法: ./grub-mkimage [OPTION...] [OPTION]... [MODULES]
  4. Try './grub-mkimage --help' or './grub-mkimage --usage' for more information.

  5. firefly@firefly:~/grub$ ./grub-mkimage -p ./ -c load.cfg -O arm-uboot -o core.img fat ext2 probe terminal scsi ls linux elf msdospart normal help echo
  6. ./grub-mkimage:错误: cannot open `/usr/local/lib/grub/arm-uboot/moddep.lst': 没有那个文件或目录.

  7. firefly@firefly:~/grub$ ./grub-mkimage -p ./ -c load.cfg -O arm-uboot -o core.img -d grub-core/ fat ext2 probe terminal scsi ls linux elf msdospart normal help echo
  8. ./grub-mkimage:错误: invalid ELF header.

复制代码


说明一下,我还没有执行 make install,因为我担心 firefly 启动时死掉,死掉重做系统,麻烦,不像 PC 那样可以从 U 盘启动。

点评

不对啊,你之前configure的时候没有加--with-platform=uboot 或--with-platform=efi之类的参数吗? 那就不知道默认生成的是arm-uboot还是arm-efi的grub了。  详情 回复 发表于 2017-4-18 18:26
回复

使用道具 举报

14#
发表于 2017-4-18 18:26:33 | 只看该作者
不点 发表于 2017-4-18 12:47
说明一下,我还没有执行 make install,因为我担心 firefly 启动时死掉,死掉重做系统,麻烦,不像 PC  ...

不对啊,你之前configure的时候没有加--with-platform=uboot 或--with-platform=efi之类的参数吗?
那就不知道默认生成的是arm-uboot还是arm-efi的grub了。

点评

它自动探测我的系统,生成的是 arm64-efi 的,我看到它给出这样的信息。  详情 回复 发表于 2017-4-18 20:51
回复

使用道具 举报

15#
 楼主| 发表于 2017-4-18 20:51:09 | 只看该作者
wintoflash 发表于 2017-4-18 18:26
不对啊,你之前configure的时候没有加--with-platform=uboot 或--with-platform=efi之类的参数吗?
那就 ...

它自动探测我的系统,生成的是 arm64-efi 的,我看到它给出这样的信息。

点评

./grub-mkimage -p "/boot/grub" -d ./grub-core -o grub.efi -O arm64-efi fat ext2 probe terminal scsi ls linux elf msdospart normal help echo  详情 回复 发表于 2017-4-18 21:34
回复

使用道具 举报

16#
发表于 2017-4-18 21:34:18 | 只看该作者
不点 发表于 2017-4-18 20:51
它自动探测我的系统,生成的是 arm64-efi 的,我看到它给出这样的信息。

./grub-mkimage -p "/boot/grub" -d ./grub-core -o grub.efi -O arm64-efi fat ext2 probe terminal scsi ls linux elf msdospart normal help echo

点评

成功了,已经生成 grub.efi firefly@firefly:~/grub$ ll grub.efi -rw-rw-r-- 1 firefly firefly 372736 4月 18 14:55 grub.efi 下一步该怎么办?  详情 回复 发表于 2017-4-18 23:01
回复

使用道具 举报

17#
 楼主| 发表于 2017-4-18 23:01:17 | 只看该作者
wintoflash 发表于 2017-4-18 21:34
./grub-mkimage -p "/boot/grub" -d ./grub-core -o grub.efi -O arm64-efi fat ext2 probe terminal scs ...

成功了,已经生成 grub.efi

firefly@firefly:~/grub$ ll grub.efi
-rw-rw-r-- 1 firefly firefly 372736 4月  18 14:55 grub.efi

下一步该怎么办?

点评

接下来怎么办我也不知道了,等高手吧。 在x86_64的设备上,接下来直接把grub.efi复制到某FAT分区的/EFI/boot/下,重命名为bootx64.efi就行了,arm的不知道。  详情 回复 发表于 2017-4-19 18:16
回复

使用道具 举报

18#
发表于 2017-4-19 18:16:53 | 只看该作者
不点 发表于 2017-4-18 23:01
成功了,已经生成 grub.efi

firefly@firefly:~/grub$ ll grub.efi

接下来怎么办我也不知道了,等高手吧。
在x86_64的设备上,接下来直接把grub.efi复制到某FAT分区的/EFI/boot/下,重命名为bootx64.efi就行了,arm的不知道。
回复

使用道具 举报

19#
发表于 2017-4-19 23:39:18 来自手机 | 只看该作者
估计他会去找bootloader分区或者bootloader.img。
回复

使用道具 举报

20#
 楼主| 发表于 2017-4-20 20:51:32 | 只看该作者
谢谢两位帮忙。看来问题得慢慢解决。不着急,等着吧。

回复

使用道具 举报

21#
发表于 2017-4-22 19:42:14 来自手机 | 只看该作者
大师一定会搞定,搞好记得说说。

点评

我岁数大了,缺少精力和时间,我不会去做这样费劲的事情的。我等着 firefly 的开发团队放出现成的刷机包。  详情 回复 发表于 2017-4-22 23:36
回复

使用道具 举报

22#
 楼主| 发表于 2017-4-22 23:36:37 | 只看该作者
窄口牛 发表于 2017-4-22 19:42
大师一定会搞定,搞好记得说说。

我岁数大了,缺少精力和时间,我不会去做这样费劲的事情的。我等着 firefly 的开发团队放出现成的刷机包。
回复

使用道具 举报

23#
发表于 2017-4-25 11:45:27 来自手机 | 只看该作者
好的
回复

使用道具 举报

24#
发表于 2019-10-29 04:56:16 来自手机 | 只看该作者
uboot拥有自己的shell以启动,参考https://forum.odroid.com/viewtopic.php?t=26894
回复

使用道具 举报

25#
发表于 2019-10-29 04:57:06 来自手机 | 只看该作者
文中的地址应该相对于不同开发板会有区别
回复

使用道具 举报

26#
发表于 2019-10-29 04:58:24 来自手机 | 只看该作者
而在编译uboot的时候,有选项是“是否支持执行efi文件……?”无法准确的翻译这个
回复

使用道具 举报

27#
发表于 2020-1-28 21:19:27 | 只看该作者
弄清楚了吗?还有debian支持那些ARM的处理器呢?那里看支持型号?
回复

使用道具 举报

28#
发表于 2020-2-23 14:36:10 | 只看该作者
支持了吗?
回复

使用道具 举报

29#
发表于 2020-3-4 08:28:55 | 只看该作者
支持了吗?ARM的。
回复

使用道具 举报

30#
发表于 2020-5-3 13:12:09 | 只看该作者
好像还不开
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2025-12-11 19:20

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表