From patchwork Wed Oct 17 07:32:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 149023 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp318968lji; Wed, 17 Oct 2018 00:31:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV60tQdFo6f+KWMJKKGUeDg1nY4c3h6eoPbsyF+EOG6Yb1OcHfji+/Hrlf0G+6m9/V3BKEY7s X-Received: by 2002:a50:9151:: with SMTP id f17-v6mr5772719eda.159.1539761493398; Wed, 17 Oct 2018 00:31:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539761493; cv=none; d=google.com; s=arc-20160816; b=Vjalj8IPfRF0oYM0cTxB70sQuKhDqzT+AjaOYuOdyk1VIa5vCTK88ctjP1a+sPMw3h KVXxVnpXsgP9MDBtku8K+PtaONwS1OmXmQWeQ5B5e0LZAIhw0oZHH3BDlNMZZrVk9Nh6 kuKzh1nZkQ56BTLJ4alXVl1tFvUNHGHiaYln4cOiSa13CcancAgzQni9Uk+2BDy22B2R clbN3OkaL48eVPGHFZEZ0lKC5Srg9zP8GfJS5l935HWUm+jvStezSAiZiBZYeFhdCmXb wahWvEuET4JDWU1AJl0/gUw8DFMNHOBRhRd+9/4VR3kyh0agPcDPMf8Olessc6nm0AtZ RwTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=AItn3FEgZgz3XLuh4q6+rakLoQQZiaY3CWP4hs202Ow=; b=zSyOxqgQ8JZx6UagJZVlO7WbNGxV3YvO33iunMnuUqxaRmMtLpIBDU8ANa2wakS7Eg DAoqSEogjpevq8wPGW1/WFQaSgfW+5Q3W2TVJjeOfzh+vNxPI4Szw9BfpiVrbnkTuMa3 INvPrmt23D0SPiRUbDlPr+XRw+VeIBhf9t7ewbe7WuHJXm3xunsdQhXQRh+uEIlOp+Tp k62IvpvvQxn3C0OoxFi8YF8WbBj2typamI0wM7HGDLf7d0/UpPmjEc19/ZZffevgQ3g3 FjBtU+6XXkQXN2tPqKIKUIp774AJR7jh/pu5G9VwwavbzIh9XqbXEalgk9RfKpTr9IPy 4QDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="ifYiF/1c"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id ch16-v6si4840274ejb.147.2018.10.17.00.31.33; Wed, 17 Oct 2018 00:31:33 -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=@linaro.org header.s=google header.b="ifYiF/1c"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 046A3C21DD7; Wed, 17 Oct 2018 07:31:19 +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=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 BA075C21D9A; Wed, 17 Oct 2018 07:31:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B61CEC21E08; Wed, 17 Oct 2018 07:30:44 +0000 (UTC) Received: from mail-yw1-f68.google.com (mail-yw1-f68.google.com [209.85.161.68]) by lists.denx.de (Postfix) with ESMTPS id 34BA3C21C2C for ; Wed, 17 Oct 2018 07:30:40 +0000 (UTC) Received: by mail-yw1-f68.google.com with SMTP id v198-v6so9948170ywg.12 for ; Wed, 17 Oct 2018 00:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S+zst4eVwZEd8oZfKOrZwRDmBIZDGuz/IBWtT1IdhC0=; b=ifYiF/1cBZRFc4RsDmktyUCHrd6W8PlnC+MYouBTbcch3VqKNz981/QkB+r3IPjSJf EjrIoiuZxmKsda4tDSFWo/UpRUxJEReVwiBA3FB5D9HI6GxCRbAmVDO7gz6ty+fWKb32 0er+NlrbjzxynsMmwCNY8P/72Cd5Adxoii50M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S+zst4eVwZEd8oZfKOrZwRDmBIZDGuz/IBWtT1IdhC0=; b=nFVw1M9M3bZ925HMUx3eZTXrtt0atS+w8C9EBopfQmbooVEJ2VmaTV+5AGTaOScglN OPfhpF6YTo+1l0v6RTfAb5eg9l31OYt4VLMI0tS4MHro6MEosArXE6E5zxGRyfv9ja3/ IUGSUj44oD/On4Opgb3+SNguq7EFODgBfKCq4OcZGn+VurLVgaYPmK5JKYMXKITqNIPD 1zPcw/MPeX803A06uWk9UPRYV7lJkV/zcNM9duw3zfTAkNiygqultdC+wxKrSJxmLdGF kwQf1Q/nURkLmrHvNElGPuKwgkQAPsI9CdeRiaJdV4yvu3Q9axCod2fdu7Maw5hMzLnn 3vSA== X-Gm-Message-State: ABuFfoggidxTDBxTsaqvLkAYr1ww7A/XoBDl4BOpZ6/9+nfwZ68SP99d 9m2oAzR/P/Q+7WZdGwykRxH3Yw== X-Received: by 2002:a81:af0b:: with SMTP id n11-v6mr13614891ywh.377.1539761439096; Wed, 17 Oct 2018 00:30:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l30-v6sm7710696ywa.104.2018.10.17.00.30.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 00:30:38 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Wed, 17 Oct 2018 16:32:03 +0900 Message-Id: <20181017073207.13150-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181017073207.13150-1-takahiro.akashi@linaro.org> References: <20181017073207.13150-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 2/6] efi_loader: add efi_dp_from_name() 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Factor out efi_set_bootdev() and extract efi_dp_from_name(). This function will be used to set a boot device in efishell command. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 42 ++++++---------------------- include/efi_loader.h | 4 +++ lib/efi_loader/efi_device_path.c | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 34 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 99f5b2b95706..b3e2845120fe 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -647,45 +647,19 @@ U_BOOT_CMD( void efi_set_bootdev(const char *dev, const char *devnr, const char *path) { - char filename[32] = { 0 }; /* dp->str is u16[32] long */ - char *s; + struct efi_device_path *device, *image; + efi_status_t ret; /* efi_set_bootdev is typically called repeatedly, recover memory */ efi_free_pool(bootefi_device_path); efi_free_pool(bootefi_image_path); - /* If blk_get_device_part_str fails, avoid duplicate free. */ - bootefi_device_path = NULL; - bootefi_image_path = NULL; - - if (strcmp(dev, "Net")) { - struct blk_desc *desc; - disk_partition_t fs_partition; - int part; - - part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition, - 1); - if (part < 0) - return; - - bootefi_device_path = efi_dp_from_part(desc, part); - } else { -#ifdef CONFIG_NET - bootefi_device_path = efi_dp_from_eth(); -#endif - } - - if (!path) - return; - if (strcmp(dev, "Net")) { - /* Add leading / to fs paths, because they're absolute */ - snprintf(filename, sizeof(filename), "/%s", path); + ret = efi_dp_from_name(dev, devnr, path, &device, &image); + if (ret == EFI_SUCCESS) { + bootefi_device_path = device; + bootefi_image_path = image; } else { - snprintf(filename, sizeof(filename), "%s", path); + bootefi_device_path = NULL; + bootefi_image_path = NULL; } - /* DOS style file path: */ - s = filename; - while ((s = strchr(s, '/'))) - *s++ = '\\'; - bootefi_image_path = efi_dp_from_file(NULL, 0, filename); } diff --git a/include/efi_loader.h b/include/efi_loader.h index 74df070316a0..b73fbb6de23f 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -425,6 +425,10 @@ const struct efi_device_path *efi_dp_last_node( efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path, struct efi_device_path **device_path, struct efi_device_path **file_path); +efi_status_t efi_dp_from_name(const char *dev, const char *devnr, + const char *path, + struct efi_device_path **device, + struct efi_device_path **file); #define EFI_DP_TYPE(_dp, _type, _subtype) \ (((_dp)->type == DEVICE_PATH_TYPE_##_type) && \ diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 5a61a1c1dcf9..3af444147283 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -942,3 +942,50 @@ efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path, *file_path = fp; return EFI_SUCCESS; } + +efi_status_t efi_dp_from_name(const char *dev, const char *devnr, + const char *path, + struct efi_device_path **device, + struct efi_device_path **file) +{ + int is_net; + struct blk_desc *desc = NULL; + disk_partition_t fs_partition; + int part = 0; + char filename[32] = { 0 }; /* dp->str is u16[32] long */ + char *s; + + if (!device || (path && !file)) + return EFI_INVALID_PARAMETER; + + is_net = !strcmp(dev, "Net"); + if (!is_net) { + part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition, + 1); + if (part < 0) + return EFI_INVALID_PARAMETER; + + *device = efi_dp_from_part(desc, part); + } else { +#ifdef CONFIG_NET + *device = efi_dp_from_eth(); +#endif + } + + if (!path) + return EFI_SUCCESS; + + if (!is_net) { + /* Add leading / to fs paths, because they're absolute */ + snprintf(filename, sizeof(filename), "/%s", path); + } else { + snprintf(filename, sizeof(filename), "%s", path); + } + /* DOS style file path: */ + s = filename; + while ((s = strchr(s, '/'))) + *s++ = '\\'; + *file = efi_dp_from_file(NULL, 0, filename); + + return EFI_SUCCESS; +}