From patchwork Tue Apr 19 06:46:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Chepurnyi X-Patchwork-Id: 1618691 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=msz9l4Qg; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KjDqv3vKNz9sG2 for ; Tue, 19 Apr 2022 16:47:07 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 66A9383B2D; Tue, 19 Apr 2022 08:46:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="msz9l4Qg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0B84783ABE; Tue, 19 Apr 2022 08:46: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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 A855E83B08 for ; Tue, 19 Apr 2022 08:46:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andrii.chepurnyi82@gmail.com Received: by mail-wr1-x42e.google.com with SMTP id p18so20223971wru.5 for ; Mon, 18 Apr 2022 23:46:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p0ckN1OVAMjIjaB5CKPVzVV1vwtfPQjnSLj50p644Kw=; b=msz9l4QgdCI4x0G6xAY46AzmA6ouvgW9zwbVZdGy1Wl3p4UOt00iG5Z4CG7dzt2G0O I0zwimjZ1RS3AwQAN7xEgGe+tbwELBJrnRUh76K3YfeCRrO0n7baciS4qBLzeOAw2Ld3 NlAU0gqI3hU3LMhSzlz5NqZ2lR19U9OlVTGrzPSaEnsNycYgeLwMuSxXSUX6CFjNmrID 7btUc2EUPN0uda4ra9AuRz4t5fY+0DKz6jN554pI5WXnwdtrOfpaBRirwBfoojE1PO7Q obGdMmqcqpDPfx4oZpjCYFmlpV5hRACP+22oXMwrXVQPLaSzwjCWpM3iHav/or2orvPt W0NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p0ckN1OVAMjIjaB5CKPVzVV1vwtfPQjnSLj50p644Kw=; b=W2zN/ekNcX7owykcr/ss7kIoUpDJVx/Hh6OWG8b7jha5+GoOGL/NItMJa3qtT68Vyf ijOu/4dK9bGGz5ho6TAnI18zhPjGByz1v+H0xYEZfNOxt0I5HT+iFtOSekXTknkhfm9F YZ6WotO3viIgH5kl6zvRjpCTgKVXc1HwWLB9kkdvnqyTPTCgm1EDEUj+1T0qukvF4Osu vh80yioHdbofShdpo/yBhPCmo8fuviK7O+KOropr8DOB2uzieM3uLfCrutzL2XC8CQYi FAJg99tNL4wmfy0HFbH4r//2f/65Yw8MRs37DkwC/v43JF/marQW+FkxUjUTYfjI1Q38 9FDA== X-Gm-Message-State: AOAM533K8dFl3n3ju/mOz5iXrdxLDU1KquDOWE3yh1UhellA4bkOAavd ACzAljP+tJSx+35WsKDmxWwrRo8FpbvDIA== X-Google-Smtp-Source: ABdhPJwh5ecOsArSl2u28duDUj4PS0gVmlqoh5cb8NudD6ZCTbCRw4R1PyUzvSkF/lMdMe59BvixCw== X-Received: by 2002:adf:e944:0:b0:207:af9e:a4e7 with SMTP id m4-20020adfe944000000b00207af9ea4e7mr10524524wrn.296.1650350800986; Mon, 18 Apr 2022 23:46:40 -0700 (PDT) Received: from localhost.localdomain ([31.148.149.129]) by smtp.gmail.com with ESMTPSA id q4-20020adffec4000000b00207a6236066sm13296481wrs.90.2022.04.18.23.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 23:46:40 -0700 (PDT) From: Andrii Chepurnyi X-Google-Original-From: Andrii Chepurnyi To: u-boot@lists.denx.de Cc: igor.opaniuk@gmail.com, gary.bisson@boundarydevices.com, Andrii Chepurnyi , Andrii Chepurnyi Subject: [PATCH v2 2/2] cmd: avb: introduce optional interface parameter to avb init Date: Tue, 19 Apr 2022 09:46:19 +0300 Message-Id: <20220419064619.455604-3-andrii_chepurnyi@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220408124303.180531-1-andrii_chepurnyi@epam.com> References: <20220408124303.180531-1-andrii_chepurnyi@epam.com> 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.5 at phobos.denx.de X-Virus-Status: Clean From: Andrii Chepurnyi From: Andrii Chepurnyi Originally, avb implementation relay on mmc block devices. The interface parameter will give the ability to use avb with various block devices by choosing the exact interface type. By default (if no interface parameter is provided) mmc interface will be used. Signed-off-by: Andrii Chepurnyi Acked-by: Igor Opaniuk --- cmd/avb.c | 13 +++++-------- common/avb_verify.c | 28 ++++++++++------------------ doc/android/avb2.rst | 2 +- include/avb_verify.h | 11 ++++++++++- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/cmd/avb.c b/cmd/avb.c index 783f51b816..6fdbdc708f 100644 --- a/cmd/avb.c +++ b/cmd/avb.c @@ -17,17 +17,14 @@ static struct AvbOps *avb_ops; int do_avb_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - unsigned long mmc_dev; - - if (argc != 2) + if (argc != 2 && argc != 3) return CMD_RET_USAGE; - mmc_dev = hextoul(argv[1], NULL); - if (avb_ops) avb_ops_free(avb_ops); - avb_ops = avb_ops_alloc(mmc_dev); + avb_ops = avb_ops_alloc(argv[1], (argc == 3) ? argv[2] : "mmc"); + if (avb_ops) return CMD_RET_SUCCESS; @@ -419,7 +416,7 @@ int do_avb_write_pvalue(struct cmd_tbl *cmdtp, int flag, int argc, } static struct cmd_tbl cmd_avb[] = { - U_BOOT_CMD_MKENT(init, 2, 0, do_avb_init, "", ""), + U_BOOT_CMD_MKENT(init, 3, 0, do_avb_init, "", ""), U_BOOT_CMD_MKENT(read_rb, 2, 0, do_avb_read_rb, "", ""), U_BOOT_CMD_MKENT(write_rb, 3, 0, do_avb_write_rb, "", ""), U_BOOT_CMD_MKENT(is_unlocked, 1, 0, do_avb_is_unlocked, "", ""), @@ -455,7 +452,7 @@ static int do_avb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) U_BOOT_CMD( avb, 29, 0, do_avb, "Provides commands for testing Android Verified Boot 2.0 functionality", - "init - initialize avb2 for \n" + "init [] - initialize avb2 for []\n" "avb read_rb - read rollback index at location \n" "avb write_rb - write rollback index to \n" "avb is_unlocked - returns unlock status of the device\n" diff --git a/common/avb_verify.c b/common/avb_verify.c index 0520a71455..e086dc6760 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -338,7 +338,6 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) { int ret; u8 dev_num; - int part_num = 0; struct mmc_part *part; struct blk_desc *mmc_blk; @@ -347,22 +346,8 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition) return NULL; dev_num = get_boot_device(ops); - part->mmc = find_mmc_device(dev_num); - if (!part->mmc) { - printf("No MMC device at slot %x\n", dev_num); - goto err; - } - - if (mmc_init(part->mmc)) { - printf("MMC initialization failed\n"); - goto err; - } + mmc_blk = get_blk(ops); - ret = mmc_switch_part(part->mmc, part_num); - if (ret) - goto err; - - mmc_blk = mmc_get_blk_desc(part->mmc); if (!mmc_blk) { printf("Error - failed to obtain block descriptor\n"); goto err; @@ -976,7 +961,8 @@ free_name: * AVB2.0 AvbOps alloc/initialisation/free * ============================================================================ */ -AvbOps *avb_ops_alloc(int boot_device) + +AvbOps *avb_ops_alloc(const char *boot_device, const char *interface) { struct AvbOpsData *ops_data; @@ -999,7 +985,13 @@ AvbOps *avb_ops_alloc(int boot_device) ops_data->ops.read_persistent_value = read_persistent_value; #endif ops_data->ops.get_size_of_partition = get_size_of_partition; - ops_data->mmc_dev = boot_device; + ops_data->mmc_dev = simple_strtoul(boot_device, NULL, 16); + ops_data->blk = NULL; + if (interface && (blk_get_device_by_str(interface, boot_device, &ops_data->blk) < 0)) { + printf("Error - failed to obtain block descriptor for devce=%s if=%s\n", + boot_device, interface); + return NULL; + } return &ops_data->ops; } diff --git a/doc/android/avb2.rst b/doc/android/avb2.rst index a072119574..8fa54338fd 100644 --- a/doc/android/avb2.rst +++ b/doc/android/avb2.rst @@ -38,7 +38,7 @@ AVB 2.0 U-Boot shell commands Provides CLI interface to invoke AVB 2.0 verification + misc. commands for different testing purposes:: - avb init - initialize avb 2.0 for + avb init [] - initialize avb2 for [] avb verify - run verification process using hash data from vbmeta structure avb read_rb - read rollback index at location avb write_rb - write rollback index to diff --git a/include/avb_verify.h b/include/avb_verify.h index 1e787ba666..ff70cb26f8 100644 --- a/include/avb_verify.h +++ b/include/avb_verify.h @@ -32,6 +32,7 @@ struct AvbOpsData { struct udevice *tee; u32 session; #endif + struct blk_desc *blk; }; struct mmc_part { @@ -46,7 +47,7 @@ enum mmc_io_type { IO_WRITE }; -AvbOps *avb_ops_alloc(int boot_device); +AvbOps *avb_ops_alloc(const char *boot_device, const char *interface); void avb_ops_free(AvbOps *ops); char *avb_set_state(AvbOps *ops, enum avb_boot_state boot_state); @@ -98,4 +99,12 @@ static inline int get_boot_device(AvbOps *ops) return -1; } +static inline struct blk_desc *get_blk(AvbOps *ops) +{ + if (ops && ops->user_data) + return ((struct AvbOpsData *)ops->user_data)->blk; + + return NULL; +} + #endif /* _AVB_VERIFY_H */