Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68C9DC00528 for ; Sun, 30 Jul 2023 17:19:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 01CAD86AB9; Sun, 30 Jul 2023 19:17:29 +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="BXAC8Eh8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1E20B869DC; Sun, 30 Jul 2023 19:17:21 +0200 (CEST) Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) (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 552D9869DC for ; Sun, 30 Jul 2023 19:17:17 +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-io1-xd30.google.com with SMTP id ca18e2360f4ac-78360f61ba0so183427539f.1 for ; Sun, 30 Jul 2023 10:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1690737436; x=1691342236; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mhIi7QnXIgNDP/f5UwzZqlaxEcA3cCxWSjteDDntSZ4=; b=BXAC8Eh8wzfcuwIfyt8nsSZSV+zSGAtLmxpuPreS4gDRfA/oR0vpBgjF8zYMboXqJ4 5R3xpI/i1XBWRwS/fA4jGXKDa5WMuFZNt548r0JJifccDZkwCswOtE/z4YsBhGlu2lsv 3ama6ba5wykA2u+Jx6xGdfh9egaxj2CQqOXNQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690737436; x=1691342236; 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:message-id:reply-to; bh=mhIi7QnXIgNDP/f5UwzZqlaxEcA3cCxWSjteDDntSZ4=; b=M9sVir/ulc4R/E15oQm5dgLEFluohZXhthCAfJ0mkggEz9IpNvOz8gOtq3Ei/eKJgH li07kfJoCJ2EQd6OGEtNlbwcYnNefPqerUpWCKQBrJDXgE/vy3lPv2N2lIRuxaIWXccu VjQGX/KbeI0Y9U7nra1/Ig9VwjMsq2G3pGaNhOAGMK55uWKx34mPN1O4213B9X1VJdm2 wzPL8LIOlu3bHcyitYsNglNj8il3pbcAyjHgVPt0fqI1IASv1Ttvg1gZO7OS4GkmV31l GfCupQx5vcJC0u7maUNxC5YETsJSAYyS0yHiaNrFbEjgvVxSNSEzs5l6VdCFdrQmXLU5 jVYg== X-Gm-Message-State: ABy/qLYR4+9IdoRFgudyuHdOgI0kZ1DIdvqQPmJX987fgFm8QofhH07D cuVTYnvuMB3pIoGCt2Ury1a5Gvg/KBommaSPfbs= X-Google-Smtp-Source: APBJJlE2FSD87+rvQ31xH7GEavjLSRfmmdIGC+gEJUcdBPPBwolvUZPctpbgA5yjbDRobTolnZVQaw== X-Received: by 2002:a5d:9395:0:b0:787:1a8f:1d08 with SMTP id c21-20020a5d9395000000b007871a8f1d08mr3165009iol.15.1690737435970; Sun, 30 Jul 2023 10:17:15 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id b24-20020a02a598000000b0041cd626ea0csm2537412jam.147.2023.07.30.10.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 10:17:15 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Alper Nebi Yasak , Simon Glass Subject: [PATCH 02/16] bootstd: cros: Move partition reading into a function Date: Sun, 30 Jul 2023 11:16:48 -0600 Message-ID: <20230730171709.917352-3-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230730171709.917352-1-sjg@chromium.org> References: <20230730171709.917352-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.8 at phobos.denx.de X-Virus-Status: Clean Move the code which reads a partition into its own function. Add a constant for the number of bytes to 'probe' at the start of the partition. Signed-off-by: Simon Glass --- boot/bootmeth_cros.c | 66 +++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 6179a547f74a..f6fb521f2065 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -23,6 +23,8 @@ #include enum { + PROBE_SIZE = SZ_4K, /* initial bytes read from partition */ + /* Offsets in the kernel-partition header */ KERN_START = 0x4f0, KERN_SIZE = 0x518, @@ -77,6 +79,51 @@ static int copy_cmdline(const char *from, const char *uuid, char **bufp) return 0; } +/** + * scan_part() - Scan a kernel partition to see if has a ChromeOS header + * + * This reads the first PROBE_SIZE of a partition, loookng for CHROMEOS + * + * @blk: Block device to scan + * @partnum: Partition number to scan + * @info: Please to put partition info + * @hdrp: Return allocated keyblock header on success + */ +static int scan_part(struct udevice *blk, int partnum, + struct disk_partition *info, void **hdrp) +{ + struct blk_desc *desc = dev_get_uclass_plat(blk); + struct vb2_keyblock *hdr; + ulong num_blks; + int ret; + + ret = part_get_info(desc, partnum, info); + if (ret) + return log_msg_ret("part", ret); + + /* Make a buffer for the header information */ + num_blks = PROBE_SIZE >> desc->log2blksz; + log_debug("Reading header, blk=%s, start=%lx, blocks=%lx\n", + blk->name, (ulong)info->start, num_blks); + hdr = memalign(SZ_1K, PROBE_SIZE); + if (!hdr) + return log_msg_ret("hdr", -ENOMEM); + ret = blk_read(blk, info->start, num_blks, hdr); + if (ret != num_blks) { + free(hdr); + return log_msg_ret("inf", -EIO); + } + + if (memcmp("CHROMEOS", hdr, 8)) { + free(hdr); + return -ENOENT; + } + + *hdrp = hdr; + + return 0; +} + static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) { struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); @@ -93,23 +140,10 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) return log_msg_ret("max", -ENOENT); /* Check partition 2 */ - ret = part_get_info(desc, 2, &info); + ret = scan_part(bflow->blk, 2, &info, &hdr); if (ret) - return log_msg_ret("part", ret); - - /* Make a buffer for the header information */ - num_blks = SZ_4K >> desc->log2blksz; - log_debug("Reading header, blk=%s, start=%lx, blocks=%lx\n", - bflow->blk->name, (ulong)info.start, num_blks); - hdr = memalign(SZ_1K, SZ_4K); - if (!hdr) - return log_msg_ret("hdr", -ENOMEM); - ret = blk_read(bflow->blk, info.start, num_blks, hdr); - if (ret != num_blks) - return log_msg_ret("inf", -EIO); - - if (memcmp("CHROMEOS", hdr, 8)) - return -ENOENT; + return log_msg_ret("scan", ret); + bflow->part = 2; log_info("Header at %lx\n", (ulong)map_to_sysmem(hdr)); start = *(u32 *)(hdr + KERN_START); -- 2.41.0.487.g6d72f3e995-goog