From patchwork Sun Oct 22 06:15:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 116625 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3361153qgn; Sat, 21 Oct 2017 23:15:21 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TF0tm3FP1YASqATJWOSE/waKvPt1QZQI1bZCvnRZLMUjaljlYKTRKQ52hWYAARjlktRYm1 X-Received: by 10.80.171.25 with SMTP id s25mr12421939edc.67.1508652921463; Sat, 21 Oct 2017 23:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508652921; cv=none; d=google.com; s=arc-20160816; b=JI+W1d4IK5w+RdiVxrNvlr3Ft8nzLCZow91p3pYHw1KNYdpi9rU/wyCivyD//tE/Yc plCniRA35nGwNY9dKrieQl+CCAu0HUXXZSiclb/QLXfVD7NhfveKOq5NN1wdJWyiLKh7 o+srbtpglMZs9Ot3inKUM12uOMC+qLJV3GKwPvmu2HpqSWp17nZK2HTV864WbQU9eOYl oIzq2cebcQmhyLNuDShRTaUx2fnU/rwGm34HKB93s4EkMcGZ9NKC+WQC7LDNj21+BZwE l+vKOWMqrT09x/lNI0wOd2xQACzf9UyXgFG1wdtgYScjoY1Y/0YHj44UAarT5aQQ9MJf lVsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :dkim-filter:arc-authentication-results; bh=5JxsXYOUX0aylmiuVE5lmSFAjMGs3S6FQLotQVsISg4=; b=oREv1N5139hGh6q3vscyCYM6HXQxQVLrVgmf9o41OFLpLSNrhLe4ZzM0IhviMyV5jV ckLwJrgHtTHdBYaY7iBQpheJ0ctkhUxHGwqjmkb4HzGcVV1zdH/A2+NDDuUvlpY01YzW jOg7GTXAK0ObC+0os9tc74CB1q6lClly2QMXnI/USR2NuVVInwHrexxYB1jLjJ41X8uB OJXR34Vx/vBjQC01FTvmX1X4H7lvQ8vuRkB94ZsSf8s2nVIv/FJYnVsD9fkNBG9Y9TNu HtIHSJyyhiOy9bpLOVegj9g+YrklktK8qiH9Kf5oGOhMr/Y6ym6Iqc/qVU7CVezU4XaD DyJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=Y/6BoGwP; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id 7si3039154edo.226.2017.10.21.23.15.20; Sat, 21 Oct 2017 23:15:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=Y/6BoGwP; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 9BB51C2200D; Sun, 22 Oct 2017 06:15:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CB250C21C58; Sun, 22 Oct 2017 06:15:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E8D82C21C58; Sun, 22 Oct 2017 06:15:13 +0000 (UTC) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lists.denx.de (Postfix) with ESMTPS id BFFA2C21C4F for ; Sun, 22 Oct 2017 06:15:12 +0000 (UTC) Received: from grover.sesame (FL1-122-131-185-176.osk.mesh.ad.jp [122.131.185.176]) (authenticated) by conuserg-08.nifty.com with ESMTP id v9M6F3ee003402; Sun, 22 Oct 2017 15:15:03 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com v9M6F3ee003402 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1508652903; bh=vePLVXE+RpAGFCBFhuCKZ2tAq88pJ7+nrHsRxSBtws0=; h=From:To:Cc:Subject:Date:From; b=Y/6BoGwPQhanq0+RDvgIfb9ji2YvKCamuJNlztbBbhBNOX1fdd668Fz1QJXKDIN3D HwSSk6IkFUfVjsx5sTXNGYSRceQ39XuWzE7Kn68nQFkGss3h/VXu1N5GnI6qLHQBc/ zzuR4uStIDjhW67ugJYcQ5lWkWFHXjO9htsnsR0BPADNf/D0kDPwnGl1cuLNgfYG2Q JtV7KzO6HFOfXmbqS9JyBdP6vWVlB+blnPvL3Hxmvgn2XDHBP9VKSQSf/fOV2+EfmF WVwlqL7A63PSQXcZRB3SyhNoKTve1phwaTd3hnGxshSmFH1/dh8147u6fG5F3Z8w3M DMfbNk9PzFvcw== X-Nifty-SrcIP: [122.131.185.176] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Sun, 22 Oct 2017 15:15:01 +0900 Message-Id: <1508652901-15684-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Subject: [U-Boot] [PATCH] doc: uniphier: add simple guide to Verified Boot X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add a simple documentation about how to use the Verified Boot on UniPhier boards. Signed-off-by: Masahiro Yamada --- doc/README.uniphier | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 226 insertions(+), 1 deletion(-) diff --git a/doc/README.uniphier b/doc/README.uniphier index e4fd9a3..a58041a 100644 --- a/doc/README.uniphier +++ b/doc/README.uniphier @@ -107,6 +107,231 @@ Firmware. [ARM Trusted Firmware]: https://github.com/ARM-software/arm-trusted-firmware +Verified Boot +------------- + +U-Boot supports an image verification method called "Verified Boot". +This is a brief tutorial to utilize this feature for the UniPhier platform. +You will find details docs in the doc/uImage.FIT directory. + +Here, we take LD20 reference board for example, but it should work for any +other boards including 32 bit SoCs. + +1. Generate key to sign with + + $ mkdir keys + $ openssl genpkey -algorithm RSA -out keys/dev.key \ + -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 + $ openssl req -batch -new -x509 -key keys/dev.key -out keys/dev.crt + +Two files "dev.key" and "dev.crt" will be created. The base name is arbitrary, +but need to match to the "key-name-hint" property described below. + +2. Describe FIT source + +You need to write an FIT (Flattened Image Tree) source file to describe the +structure of the image container. + +The following is an example for a simple usecase: + +---------------------------------------->8---------------------------------------- +/dts-v1/; + +/ { + description = "Kernel, DTB and Ramdisk for UniPhier LD20 Reference Board"; + #address-cells = <1>; + + images { + kernel@0 { + description = "linux"; + data = /incbin/("PATH/TO/YOUR/LINUX/DIR/arch/arm64/boot/Image.gz"); + type = "kernel"; + arch = "arm64"; + os = "linux"; + compression = "gzip"; + load = <0x82080000>; + entry = <0x82080000>; + hash@0 { + algo = "sha256"; + }; + }; + + fdt@0 { + description = "fdt"; + data = /incbin/("PATH/TO/YOUR/LINUX/DIR/arch/arm64/boot/dts/socionext/uniphier-ld20-ref.dtb"); + type = "flat_dt"; + arch = "arm64"; + compression = "none"; + hash@0 { + algo = "sha256"; + }; + }; + + ramdisk@0 { + description = "ramdisk"; + data = /incbin/("PATH/TO/YOUR/ROOTFS/DIR/rootfs.cpio"); + type = "ramdisk"; + arch = "arm64"; + os = "linux"; + compression = "none"; + hash@0 { + algo = "sha256"; + }; + }; + }; + + configurations { + default = "config@0"; + + config@0 { + description = "Configuration0"; + kernel = "kernel@0"; + fdt = "fdt@0"; + ramdisk = "ramdisk@0"; + signature@0 { + algo = "sha256,rsa2048"; + key-name-hint = "dev"; + sign-images = "kernel", "fdt", "ramdisk"; + }; + }; + }; +}; +---------------------------------------->8---------------------------------------- + +You need to change the three '/incbin/' lines, depending on the location of +your kernel image, device tree blob, and init ramdisk. The "load" and "entry" +properties also need to be adjusted if you want to change the physical placement +of the kernel. + +The "key-name-hint" must specify the key name you have created in the step 1. + +The FIT file name is arbitrary. Let's say you saved it into "fit.its". + +3. Compile U-Boot with FIT and signature enabled + +To use the Verified Boot, you need to enable the following two options: + CONFIG_FIT + CONFIG_FIT_SIGNATURE + +They are disabled by default for UniPhier defconfig files. So, you need to +tweak the configuration from "make menuconfig" or friends. + + $ make uniphier_v8_defconfig + $ make menuconfig + [ enable CONFIG_FIT and CONFIG_FIT_SIGNATURE ] + $ make CROSS_COMPILE=aarch64-linux-gnu- + +4. Build the image tree blob + +After building U-Boot, you will see tools/mkimage. With this tool, you can +create an image tree blob as follows: + + $ tools/mkimage -f fit.its -k keys -K dts/dt.dtb -r -F fitImage + +The -k option must specify the key directory you have created in step 1. + +A file "fitImage" will be created. This includes kernel, DTB, Init-ramdisk, +hash data for each of the three, and signature data. + +The public key needed for the run-time verification is stored in "dts/dt.dtb". + +5. Compile U-Boot again + +Since the "dt.dtb" has been updated in step 4, you need to re-compile the +U-Boot. + + $ make CROSS_COMPILE=aarch64-linux-gnu- + +The re-compiled "u-boot.bin" is appended with DTB that contains the public key. + +6. Flash the image + +Flash the "fitImage" to a storage device (NAND, eMMC, or whatever) on your +board. + +Please note the "u-boot.bin" must be signed, and verified by someone when it is +loaded. For ARMv8 SoCs, the "someone" is generally ARM Trusted Firmware BL2. +ARM Trusted Firmware supports an image authentication mechanism called Trusted +Board Boot (TBB). The verification process must be chained from the moment of +the system reset. If the Chain of Trust has a breakage somewhere, the verified +boot process is entirely pointless. + +7. Boot verified kernel + +Load the fitImage to memory and run the following from the U-Boot command line. + + > bootm + +Here, is the base address of the fitImage. + +If it is successful, you will see messages like follows: + +---------------------------------------->8---------------------------------------- +## Loading kernel from FIT Image at 84100000 ... + Using 'config@0' configuration + Verifying Hash Integrity ... sha256,rsa2048:dev+ OK + Trying 'kernel@0' kernel subimage + Description: linux + Created: 2017-10-20 14:32:29 UTC + Type: Kernel Image + Compression: gzip compressed + Data Start: 0x841000c8 + Data Size: 6957818 Bytes = 6.6 MiB + Architecture: AArch64 + OS: Linux + Load Address: 0x82080000 + Entry Point: 0x82080000 + Hash algo: sha256 + Hash value: 82a37b7f11ae55f4e07aa25bf77e4067cb9dc1014d52d6cd4d588f92eee3aaad + Verifying Hash Integrity ... sha256+ OK +## Loading ramdisk from FIT Image at 84100000 ... + Using 'config@0' configuration + Trying 'ramdisk@0' ramdisk subimage + Description: ramdisk + Created: 2017-10-20 14:32:29 UTC + Type: RAMDisk Image + Compression: uncompressed + Data Start: 0x847a5cc0 + Data Size: 5264365 Bytes = 5 MiB + Architecture: AArch64 + OS: Linux + Load Address: unavailable + Entry Point: unavailable + Hash algo: sha256 + Hash value: 44980a2874154a2e31ed59222c9f8ea968867637f35c81e4107a984de7014deb + Verifying Hash Integrity ... sha256+ OK +## Loading fdt from FIT Image at 84100000 ... + Using 'config@0' configuration + Trying 'fdt@0' fdt subimage + Description: fdt + Created: 2017-10-20 14:32:29 UTC + Type: Flat Device Tree + Compression: uncompressed + Data Start: 0x847a2cb0 + Data Size: 12111 Bytes = 11.8 KiB + Architecture: AArch64 + Hash algo: sha256 + Hash value: c517099db537f6d325e6be46b25c871a41331ad5af0283883fd29d40bfc14e1d + Verifying Hash Integrity ... sha256+ OK + Booting using the fdt blob at 0x847a2cb0 + Uncompressing Kernel Image ... OK + reserving fdt memory region: addr=80000000 size=2000000 + Loading Device Tree to 000000009fffa000, end 000000009fffff4e ... OK + +Starting kernel ... +---------------------------------------->8---------------------------------------- + +Please pay attention to the lines that start with "Verifying Hash Integrity". + +"Verifying Hash Integrity ... sha256,rsa2048:dev+ OK" means the signature check +passed. + +"Verifying Hash Integrity ... sha256+ OK" (3 times) means the hash check passed +for kernel, DTB, and Init ramdisk. + +If they are not displayed, the Verified Boot is not working. + + UniPhier specific commands -------------------------- @@ -179,4 +404,4 @@ newer SoCs. Even if it is, EA[25] is not connected on most of the boards. -- Masahiro Yamada -Sep. 2017 +Oct. 2017