From patchwork Sun Sep 25 15:02:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1682198 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=caEPmlC6; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mb8Pd5v9pz1yq1 for ; Mon, 26 Sep 2022 01:07:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 005A484CE6; Sun, 25 Sep 2022 17:04:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="caEPmlC6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7455C84BE1; Sun, 25 Sep 2022 17:03:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7DC5184B5D for ; Sun, 25 Sep 2022 17:03:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x135.google.com with SMTP id a4so2404547ilj.8 for ; Sun, 25 Sep 2022 08:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=t8VIZL195S5ceKaswsbex137EB3eRjtgo7pRor5SnDw=; b=caEPmlC6+fJhjZk3Xq8ech3qBk3ID/M3BxcZvU8fBq5S+bOhmtyoyjmoWvzK5B6cls YvYpx828xAvrEQ56Lj++W/2k0I9EXY4Qhw4vi3syOso9y34Eoq8pqykIww2sHwLJy1jj VDaEyVPnO17/9FsCHnTI1ZILRDOuTyvy5Z2To= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=t8VIZL195S5ceKaswsbex137EB3eRjtgo7pRor5SnDw=; b=3W4HcG9oqKOHlc8zSXNwV15xT3YnK3iLTJsTWi7TE65ay7GCHCtdqp7sRXjCn82Rv6 4vnb3eeuDQ3ChvVdhmPyQLoWp2pvhtdHVshGOiWtsXX1ARfbKmjnSWrbMKbFx4XOYE1s 2z/23d3zG05Tb3eLyQGlZurzO0SFC5tVsb7OU0nvecjIqmSEeL3qa/G3UbItl3d1QLhr CLLq3FbEioeoVz1J+rxuO10ZjbvLn5p+VNgIrU2vyC9a6D/U7uDhhL7Sb17oHuy8SXLi INGDHxnP00HX08ngz1TRJH8EBegCTPsDSXiFKCtt3CjjBvAv+UTHXpgwFlavvxEICy3Z MuiA== X-Gm-Message-State: ACrzQf3btMCB8RW1x+d2Imju8zXZRmLni2jC/P4hnUw1BHnpDv5EnGDu TCnT+xNlDj/QbM0RfAGcHX3l6UE1GQqbgg== X-Google-Smtp-Source: AMsMyM4tm3tH+6uJ/I0PrPxmReKGTdJ+vtE1Rg5ogu+69DBESNq6btUSh2/lgcknaClhSTwavBYrNA== X-Received: by 2002:a05:6e02:1542:b0:2f5:7a97:a6f6 with SMTP id j2-20020a056e02154200b002f57a97a6f6mr8626566ilu.6.1664118217688; Sun, 25 Sep 2022 08:03:37 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id u19-20020a926013000000b002f19d9838c6sm5360578ilb.25.2022.09.25.08.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 08:03:37 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Alexandru Gagniuc , Andre Przywara , Heinrich Schuchardt , Jan Kiszka , Joe Hershberger , Marek Vasut , Philippe Reynes , Samuel Holland , Thomas Huth Subject: [PATCH 26/45] image: Add the concept of a phase to FIT Date: Sun, 25 Sep 2022 09:02:29 -0600 Message-Id: <20220925150248.2524421-27-sjg@chromium.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220925150248.2524421-1-sjg@chromium.org> References: <20220925150248.2524421-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean We want to be able to mark a configuration as relataed to a phase, so we can easily load all the images for SPL or for U-Boot proper. Add this to the FIT specification, along with some access functions. Signed-off-by: Simon Glass --- boot/image.c | 18 +++++++++++ include/image.h | 74 ++++++++++++++++++++++++++++++++++++++++++++-- test/boot/Makefile | 1 + test/boot/image.c | 36 ++++++++++++++++++++++ 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 test/boot/image.c diff --git a/boot/image.c b/boot/image.c index 9f95b3260a8..b33d1dfc6b3 100644 --- a/boot/image.c +++ b/boot/image.c @@ -194,6 +194,13 @@ static const table_entry_t uimage_comp[] = { { -1, "", "", }, }; +static const table_entry_t uimage_phase[] = { + { IH_PHASE_NONE, "none", "any", }, + { IH_PHASE_U_BOOT, "u-boot", "U-Boot phase", }, + { IH_PHASE_SPL, "spl", "SPL Phase", }, + { -1, "", "", }, +}; + struct table_info { const char *desc; int count; @@ -215,6 +222,7 @@ static const struct table_info table_info[IH_COUNT] = { { "compression", IH_COMP_COUNT, uimage_comp }, { "operating system", IH_OS_COUNT, uimage_os }, { "image type", IH_TYPE_COUNT, uimage_type }, + { "phase", IH_PHASE_COUNT, uimage_phase }, }; /*****************************************************************************/ @@ -656,6 +664,11 @@ const char *genimg_get_comp_name(uint8_t comp) comp)); } +const char *genimg_get_phase_name(enum image_phase_t phase) +{ + return get_table_entry_name(uimage_phase, "Unknown Phase", phase); +} + static const char *genimg_get_short_name(const table_entry_t *table, int val) { table = get_table_entry(table, val); @@ -731,3 +744,8 @@ int genimg_get_comp_id(const char *name) { return (get_table_entry_id(uimage_comp, "Compression", name)); } + +int genimg_get_phase_id(const char *name) +{ + return get_table_entry_id(uimage_phase, "Phase", name); +} diff --git a/include/image.h b/include/image.h index ca1c6c5b3c2..09821dce642 100644 --- a/include/image.h +++ b/include/image.h @@ -58,6 +58,7 @@ enum ih_category { IH_COMP, IH_OS, IH_TYPE, + IH_PHASE, IH_COUNT, }; @@ -184,8 +185,7 @@ enum { * New IDs *MUST* be appended at the end of the list and *NEVER* * inserted for backward compatibility. */ - -enum { +enum image_type_t { IH_TYPE_INVALID = 0, /* Invalid Image */ IH_TYPE_STANDALONE, /* Standalone Program */ IH_TYPE_KERNEL, /* OS Kernel Image */ @@ -252,6 +252,59 @@ enum { IH_COMP_COUNT, }; +/** + * Phases - images intended for particular U-Boot phases (SPL, etc.) + * + * @IH_PHASE_NONE: No phase information, can be loaded by any phase + * @IH_PHASE_U_BOOT: Only for U-Boot proper + * @IH_PHASE_SPL: Only for SPL + */ +enum image_phase_t { + IH_PHASE_NONE = 0, + IH_PHASE_U_BOOT, + IH_PHASE_SPL, + + IH_PHASE_COUNT, +}; + +#define IMAGE_PHASE_SHIFT 8 +#define IMAGE_PHASE_MASK (0xff << IMAGE_PHASE_SHIFT) +#define IMAGE_TYPE_MASK 0xff + +/** + * image_ph() - build a composite value combining and type + * + * @phase: Image phase value + * @type: Image type value + * Returns: Composite value containing both + */ +static inline int image_ph(enum image_phase_t phase, enum image_type_t type) +{ + return type | (phase << IMAGE_PHASE_SHIFT); +} + +/** + * image_ph_phase() - obtain the phase from a composite phase/type value + * + * @image_ph_type: Composite value to convert + * Returns: Phase value taken from the composite value + */ +static inline int image_ph_phase(int image_ph_type) +{ + return (image_ph_type & IMAGE_PHASE_MASK) >> IMAGE_PHASE_SHIFT; +} + +/** + * image_ph_type() - obtain the type from a composite phase/type value + * + * @image_ph_type: Composite value to convert + * Returns: Type value taken from the composite value + */ +static inline int image_ph_type(int image_ph_type) +{ + return image_ph_type & IMAGE_TYPE_MASK; +} + #define LZ4F_MAGIC 0x184D2204 /* LZ4 Magic Number */ #define IH_MAGIC 0x27051956 /* Image Magic Number */ #define IH_NMLEN 32 /* Image Name Length */ @@ -437,6 +490,22 @@ const char *genimg_get_os_short_name(uint8_t comp); const char *genimg_get_arch_name(uint8_t arch); +/** + * genimg_get_phase_name() - Get the friendly name for a phase + * + * @phase: Phase value to look up + * Returns: Friendly name for the phase (e.g. "U-Boot phase") + */ +const char *genimg_get_phase_name(enum image_phase_t phase); + +/** + * genimg_get_phase_id() - Convert a phase name to an ID + * + * @name: Name to convert (e.g. "u-boot") + * Returns: ID for that phase (e.g. IH_PHASE_U_BOOT) + */ +int genimg_get_phase_id(const char *name); + /** * genimg_get_arch_short_name() - get the short name for an architecture * @@ -955,6 +1024,7 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size, #define FIT_FPGA_PROP "fpga" #define FIT_FIRMWARE_PROP "firmware" #define FIT_STANDALONE_PROP "standalone" +#define FIT_PHASE_PROP "phase" #define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE diff --git a/test/boot/Makefile b/test/boot/Makefile index 5bb3f889759..d724629d3b0 100644 --- a/test/boot/Makefile +++ b/test/boot/Makefile @@ -3,6 +3,7 @@ # Copyright 2021 Google LLC obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o bootmeth.o +obj-$(CONFIG_FIT) += image.o ifdef CONFIG_OF_LIVE obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += vbe_simple.o diff --git a/test/boot/image.c b/test/boot/image.c new file mode 100644 index 00000000000..8f696416d3d --- /dev/null +++ b/test/boot/image.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for image handling + * + * Copyright 2022 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include "bootstd_common.h" + +/* Test of image phase */ +static int test_image_phase(struct unit_test_state *uts) +{ + int val; + + ut_asserteq_str("U-Boot phase", genimg_get_phase_name(IH_PHASE_U_BOOT)); + ut_asserteq_str("SPL Phase", genimg_get_phase_name(IH_PHASE_SPL)); + ut_asserteq_str("any", genimg_get_phase_name(IH_PHASE_NONE)); + ut_asserteq_str("Unknown Phase", genimg_get_phase_name(-1)); + + ut_asserteq(IH_PHASE_U_BOOT, genimg_get_phase_id("u-boot")); + ut_asserteq(IH_PHASE_SPL, genimg_get_phase_id("spl")); + ut_asserteq(IH_PHASE_NONE, genimg_get_phase_id("none")); + ut_asserteq(-1, genimg_get_phase_id("fred")); + + val = image_ph(IH_PHASE_SPL, IH_TYPE_FIRMWARE); + ut_asserteq(IH_PHASE_SPL, image_ph_phase(val)); + ut_asserteq(IH_TYPE_FIRMWARE, image_ph_type(val)); + + return 0; +} +BOOTSTD_TEST(test_image_phase, 0);