All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: Leif Lindholm <leif.lindholm@linaro.org>
Cc: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH 4/7] Support for ARM/U-Boot platforms
Date: Mon, 08 Apr 2013 12:47:48 +0200	[thread overview]
Message-ID: <5162A054.5090502@gmail.com> (raw)
In-Reply-To: <20130403163238.GL23069@rocoto.smurfnet.nu>

[-- Attachment #1: Type: text/plain, Size: 5599 bytes --]

On 03.04.2013 18:32, Leif Lindholm wrote:

> On Mon, Apr 01, 2013 at 04:15:03AM +0200, Vladimir '??-coder/phcoder' Serbinenko wrote:
>>> +#define GRUB_KERNEL_MACHINE_STACK_SIZE 0x40000
>>> +#define GRUB_KERNEL_MACHINE_HEAP_SIZE  (grub_size_t) (2 * 1024 * 1024)
>>
>> Why so small heap?
>  
> I copied ieee1275 HEAP_MIN_SIZE to begin with, and it was always enough.
> (Since U-Boot doesn't provide any memory mapping service, kernel and
> initrd are not going on the heap.)

On x86 we reuse heap for kernels as well

> I could increase it?
> 

If we want to support any kind of graphics (gfxterm, gfxmenu) on arm as well, we'll need more heap

>>> === modified file 'util/grub-install.in'
>>> --- util/grub-install.in	2013-01-27 15:17:21 +0000
>>> +++ util/grub-install.in	2013-03-24 13:03:31 +0000
>>> @@ -319,6 +319,8 @@
>>>  		    target=i386-pc
>>>  		fi
>>>  		;;
>>> +	    x"arm"*)
>>> +		target="arm-uboot";;
>>>  	    *)
>>>  		gettext "Unable to determine your platform. Use --target." ;
>>>  		echo	;;
>>> @@ -338,7 +340,7 @@
>>>      if [ x$disk_module = xunspecified ]; then
>>>  	disk_module=biosdisk
>>>      fi
>>> -elif [ "${grub_modinfo_platform}" = "ieee1275" ] || [ "${grub_modinfo_platform}" = "efi" ] || [ "${grub_modinfo_platform}" = "arc" ] ; then
>>> +elif [ "${grub_modinfo_platform}" = "ieee1275" ] || [ "${grub_modinfo_platform}" = "efi" ] || [ "${grub_modinfo_platform}" = "arc" ] || [ "${grub_modinfo_platform}" = "uboot" ] ; then
>>>      disk_module=
>>>  else
>>>      disk_module=native
>>> @@ -854,6 +856,14 @@
>>>  		-L "$bootloader_id" -l "\\EFI\\$efi_distributor\\$efi_file"
>>>  	fi
>>>      fi
>>> +elif [ x"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = xarm-uboot ]; then
>>> +    grub_imgname="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}"
>>> +    raw_imgname="${uboot_imgname}.raw"
>>
>> Where is uboot_imgname set?
> 
> *cough* that would be a typo then - should be grub_imgname.
>  
>>> +    mv "$grub_imgname" "$raw_imgname"
>>> +    mkimage -T kernel -A ARM -O Linux -a 0x08000000 -e 0x08000000 -C none -d "$raw_imgname" "$grub_imgname"
>>
>> Is it from uboot? You need to check for its availability
>  
> Yes.
> 

the header is trivial. I added it to grub-mkimage (patch at the bottom).
Trouble is that grub-install now rightfully warns about the lack of platform-specific install.
What do we have to do to register the image at u-boot? Put it in specific location?
Also you spoke about relocatable image but AFAICT header always specifies load address. Do you have a way around it?

=== modified file 'util/grub-install.in'
--- util/grub-install.in	2013-04-07 00:41:07 +0000
+++ util/grub-install.in	2013-04-08 10:42:46 +0000
@@ -833,14 +833,6 @@
 		-L "$bootloader_id" -l "\\EFI\\$efi_distributor\\$efi_file"
 	fi
     fi
-elif [ x"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = xarm-uboot ]; then
-    grub_imgname="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}"
-    raw_imgname="${uboot_imgname}.raw"
-    mv "$grub_imgname" "$raw_imgname"
-    mkimage -T kernel -A ARM -O Linux -a 0x08000000 -e 0x08000000 -C none -d "$raw_imgname" "$grub_imgname"
-    if [ $? -eq 0 ]; then
-	rm -f "$raw_imgname"
-    fi
 else
     gettext "WARNING: no platform-specific install was performed" 1>&2
     echo 1>&2

=== modified file 'util/grub-mkimage.c'
--- util/grub-mkimage.c	2013-04-07 00:41:07 +0000
+++ util/grub-mkimage.c	2013-04-08 09:40:18 +0000
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <grub/efi/pe32.h>
+#include <grub/uboot/image.h>
 
 #define _GNU_SOURCE	1
 #include <argp.h>
@@ -1499,6 +1500,42 @@
       core_size = rom_size;
     }
     break;
+
+    case IMAGE_UBOOT:
+    {
+      struct grub_uboot_image_header *hdr;
+      GRUB_PROPERLY_ALIGNED_ARRAY (crc32_context, GRUB_MD_CRC32->contextsize);
+
+      hdr = xmalloc (core_size + sizeof (struct grub_uboot_image_header));
+      memcpy (hdr + 1, core_img, core_size);
+
+      memset (hdr, 0, sizeof (*hdr));
+      hdr->ih_magic = grub_cpu_to_be32_compile_time (GRUB_UBOOT_IH_MAGIC);
+      hdr->ih_time = grub_cpu_to_be32 (time (0));
+      hdr->ih_size = grub_cpu_to_be32 (core_size);
+      hdr->ih_load = grub_cpu_to_be32 (image_target->link_addr);
+      hdr->ih_ep = grub_cpu_to_be32 (image_target->link_addr);
+      hdr->ih_os = GRUB_UBOOT_IH_OS_LINUX;
+      hdr->ih_arch = GRUB_UBOOT_IH_ARCH_ARM;
+      hdr->ih_type = GRUB_UBOOT_IH_TYPE_KERNEL;
+      hdr->ih_comp = GRUB_UBOOT_IH_COMP_NONE;
+
+      GRUB_MD_CRC32->init(crc32_context);
+      GRUB_MD_CRC32->write(crc32_context, hdr + 1, core_size);
+      GRUB_MD_CRC32->final(crc32_context);
+      hdr->ih_dcrc = grub_get_unaligned32 (GRUB_MD_CRC32->read (crc32_context));
+
+      GRUB_MD_CRC32->init(crc32_context);
+      GRUB_MD_CRC32->write(crc32_context, hdr, sizeof (*hdr));
+      GRUB_MD_CRC32->final(crc32_context);
+      hdr->ih_hcrc = grub_get_unaligned32 (GRUB_MD_CRC32->read (crc32_context));
+
+      free (core_img);
+      core_img = (char *) hdr;
+      core_size += sizeof (struct grub_uboot_image_header);
+    }
+    break;
+
     case IMAGE_MIPS_ARC:
       {
 	char *ecoff_img;
@@ -1725,9 +1762,6 @@
 	core_size = program_size + header_size + footer_size;
       }
       break;
-    case IMAGE_UBOOT:
-      /* Raw image, header added by grub-install */
-      break;
     }
 
   grub_util_write_image (core_img, core_size, out, outname);



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

  reply	other threads:[~2013-04-08 12:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-24 17:01 [PATCH 4/7] Support for ARM/U-Boot platforms Leif Lindholm
2013-04-01  2:15 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-01  9:53   ` Francesco Lavra
2013-04-01 11:24     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-01 14:29       ` Francesco Lavra
2013-04-03 10:29         ` Leif Lindholm
2013-04-03 16:32   ` Leif Lindholm
2013-04-08 10:47     ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2013-04-09 10:26       ` Leif Lindholm
2013-04-09 17:26         ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-09  0:15 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-09 11:39   ` Leif Lindholm
2013-04-09 11:55     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-09 12:45     ` Vladimir 'φ-coder/phcoder' Serbinenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5162A054.5090502@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=leif.lindholm@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.