All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] Complete verified uboot example
Date: Wed, 22 Feb 2017 09:07:52 +0100	[thread overview]
Message-ID: <20170222090752.72a4cb8b@jawa> (raw)
In-Reply-To: <CAPZm7uVW+uY_Y-FPMWGVw+f3rpvV0LeenKqqEZgS5wzQ3SHAsQ@mail.gmail.com>

On Tue, 21 Feb 2017 13:08:19 -0500
Ron Brash <ron.brash@gmail.com> wrote:

> Hello all,
> 
> I am adding verified kernel support on a board we are using and I am
> struggling to fully understand all of the concepts and steps required
> to pull everything together (on ARM, using ZImages and booting with a
> working DTB on 4.4.3x).  I also looked at the test script inside of
> examples, but it left me with more questions than understanding.
> 
> Please correct me where appropriate in my understanding, but if I am
> confused, likely others are too and I hope this helps everyone
> involved overall.

Some time ago I've gave a try to verified boot on BBB (beagle bone
black).

Please refer to:
/home/lukma/work/embedded/u-boot-denx/doc/uImage.FIT/beaglebone_vboot.txt

It should shed some more light to your problem and provide reference.

> 
> Steps:
> ---------------------------------------------------------------
> 
> First, u-boot needs to have the appropriate features enabled and to be
> built using them.  At a minimum, I suspect:
> 
> CONFIG_RSA=y
> CONFIG_FIT=y
> CONFIG_FIT_SIGNATURE=y
> CONFIG_OF_CONTROL=y
> 
> Next, we need to derive the appropriate cryptographic primitives/keys.
> 
> #Generate a private signing key (RSA2048):
> openssl genrsa -F4 -out \
> "${key_dir}"/"${key_name}".key 2048
> 
> # Generate a public key:
> openssl req -batch -new -x509 \
> -key "${key_dir}"/"${key_name}".key \
> -out "${key_dir}"/"${key_name}".crt
> 
> Then we derive the ITS or image source file - a file that
> hints/describes the elements that will be verified and/or inside of
> the FIT image?  Lets call this $FIT_ITS
> 
> / dts - v1 /;
> / {
> description = "Configuration to load a Xen Kernel";
> #address-cells = <1>;
> images {
> linux_kernel @ 1 {
> description = "Linux zImage";
> data = /incbin / ("pathToImage/zImage");
> type = "kernel";
> arch = "arm";
> os = "linux";
> compression = "none";
> load = <0xaf600000 >;
> entry = <0xaf600000 >;
> hash @ 1 {
> algo = "sha1";
> };
> };
> fdt @ 1 {
> description = "FDT blob";
> data = /incbin / ("PathToDTBUsedByBootingKernel/ex.dtb");
> type = "flat_dt";
> arch = "arm";
> compression = "none";
> load = <0xaec00000 >;
> hash @ 1 {
> algo = "sha1";
> };
> };
> };
> configurations {
> default = "config at 1";
> config @ 1 {
> description = "Plain Linux";
> kernel = "linux_kernel at 1";
> fdt = "fdt at 1";
> loadables = "linux_kernel at 1";
> };
> };
> };
> 
> Question: Does a signature section go into this as well? underneath
> the hash node for each value?
> 
> signature at 1 {
>      algo = "sha1,rsa2048";
>      value = <...kernel signature 1...>
>  };
> 
> Then using the device-tree-compiler (dtc), I create a DTB for
> u-boot.  This is the control FDT and this defines what keys are used
> etc..
> 
> #Assemble control FDT for U-Boot with space for public key:
> $DTC -p 0x1000 u-boot.dts -O dtb -o u-boot.dtb
> 
> Question: What is required inside of the u-boot.dts for u-boot?  Is it
> simply the same .dts used by the booting kernel, but with a section
> proclaiming the keys?

u-boot dts is not 100% compatible with Linux kernel, but does the
same job.

Yes, you put your public key to it IIRC.

> 
> Question:  Where will the compiled u-boot.dtb eventually go?  Is this
> put into a FIT image, or flashed onto the board alongside the u-boot
> bootloader itself?

The u-boot dtb will be packed into FIT image, which comprise u-boot and
several dtb's. This image is not the one, which kernel uses to boot the
kernel.

(There is a switch CONFIG_SPL_LOAD_FIT in spl.c, so please look for a
reference).

> 
> Next, given that the above steps are completed, I need to create a FIT
> image with space for the signature.
> 
> # Generate fitImage with space for signature:
> $MKIMG -D "-I dts -O dtb -p 2000" \
> -f f$FIT_ITS $FIT_IMG
> 
> Question: Is the FIT_IMAGE the actual zimage or is it an output image
> that contains all of the values contained within the ITS?
> 
> Next this FIT_IMAGE (assuming that this is the final FIT image that
> contains the FDT and zImage) needs to be signed and the public key
> added to it; given that that the key information is in the uboot.
> 
> # Sign fitImage and add public key into u-boot.dtb:
> $MKIMG -D "-I dts -O dtb -p 2000" -F \
> -k "${key dir}" -K u-boot.dtb -r $FIT_IMG
> 
> Then, we sign the subsequent fitImage again - correct?
> 
> # Signing subsequent fitImage:
> $MKIMG -D "-I dts -O dtb -p 2000" \
> -k "${key dir}" -f $FIT_ITS -r $FIT_IMG
> 
> Now that all of the above is done - we need to:
> 1. Write our uboot to the flash
> 2. Write our FIT_IMAGE to flash
> 
> Question: Do we write anything else to persistent storage? The ITS?
> etc..
> 
> Question: Do we just boot using anything else or just bootm
> 0xLocationOfTheFitImageInRAM
> 
> Greatly appreciate any assistance to all of these questions and I'm
> sure this threat will be of interest to anyone else too.
> 
> Thanks!
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de

  reply	other threads:[~2017-02-22  8:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21 18:08 [U-Boot] Complete verified uboot example Ron Brash
2017-02-22  8:07 ` Lukasz Majewski [this message]
2017-02-22 18:51 ` Rick Altherr
2017-02-23  5:23   ` Lukasz Majewski
2017-02-23 15:48   ` Ron Brash
2017-02-23 17:27     ` Rick Altherr
2017-02-23 18:06       ` Ron Brash
2017-02-23 18:12         ` Rick Altherr
2017-02-27 15:34       ` Ron Brash
2017-02-27 20:58         ` Rick Altherr
2017-02-27 21:49           ` Ron Brash
2017-02-27 21:53             ` Rick Altherr
2017-02-28 19:09               ` Ron Brash
2017-02-28 21:51                 ` Rick Altherr
2017-03-01  0:06                   ` Ron Brash
2017-03-07 21:30                     ` Rick Altherr
2017-03-08 21:02                     ` Simon Glass
2017-03-08 21:02             ` Simon Glass
2017-03-08 21:02 ` Simon Glass

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=20170222090752.72a4cb8b@jawa \
    --to=lukma@denx.de \
    --cc=u-boot@lists.denx.de \
    /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.