Booting with grub

Patching grub to simply add the entry to the devicetree was actually simpler than i expected :slight_smile:

This is the patch:

diff -Naur grub-2.06/grub-core/loader/riscv64/linux.c grub-2.06-mod/grub-core/loader/riscv64/linux.c
--- grub-2.06/grub-core/loader/riscv64/linux.c	2021-07-03 19:45:08.797409969 +0200
+++ grub-2.06-mod/grub-core/loader/riscv64/linux.c	2021-07-03 19:43:54.673239976 +0200
@@ -48,6 +48,13 @@
 static grub_addr_t initrd_start;
 static grub_addr_t initrd_end;
 
+#define get_hartid(__v)                        \
+{                                      \
+  __asm__ __volatile__ ("mv %0, tp"    \
+                       : "=r" (__v) :  \
+                       : "memory");    \
+}
+
 grub_err_t
 grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
 {
@@ -68,6 +75,7 @@
 finalize_params_linux (void)
 {
   int node, retval;
+  int hartid;
 
   void *fdt;
 
@@ -83,6 +91,9 @@
   if (node < 1)
     goto failure;
 
+  get_hartid(hartid);
+  grub_fdt_set_prop32 (fdt, node, "boot-hartid", hartid);
+
   /* Set initrd info */
   if (initrd_start && initrd_end > initrd_start)
     {

After that the kernel booted … and immediately oops’ed when the initscripts tried to mount eftvarsfs. After i removed that from the initscrips it worked :smiley:. My system is now running after being booted via grub.

Now the next question is how to instruct u-boot to execute the required commands to start grub automatically, does anyone have a clue? I tried to add it to extlinux.conf with it’s own label but that doesn’t work.

2 Likes