From patchwork Fri Dec 14 09:47:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 153791 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1856440ljp; Fri, 14 Dec 2018 01:44:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/UioxOavy21qazSOFKHOBsyIr5fzLlaOB8SlstDv15e36S0Wz3T6iyICayQRO8EzrWJMHIu X-Received: by 2002:a50:c182:: with SMTP id m2mr2421626edf.139.1544780653989; Fri, 14 Dec 2018 01:44:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544780653; cv=none; d=google.com; s=arc-20160816; b=xfeXS5kesTACT3cRXrWibP8ivY1w9/eijKnoX0ZRfJ1JvzPb7g/11AkI7fO4YS25x+ tA5jo4to1puUYINy5SHHsi/3zNoqWKwBUFqjHdG4wFmjeOR8yzdx3nD2psgtG3z5/Vs6 RiT5YghhOCEa4m65dP4CzzT/VD/ue6fUS6wF70H7JUbXOBK5LE+d/ZSa1ix7INn2gJEz arv7HvGA6V/YdUProFc1l+L//BHRvjfYAQWun9qTtZS6EH+ZrHFYrE7kqslVfZhhKi0q taDjYSWkmFkk/aniQWxuzJnQO6WJmE10A69D0Hf58fK5cG4RGWYOv3VYk23/Iu7jxsFh Z4FQ== 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:message-id:date:to:from:dkim-signature; bh=pfUlnKUHQ+wwUnUlDo0mOql2Y4vPhrwPsL4NxRjaT2Y=; b=dSSagXc2PbbpaqE2uqj1rEmBtmCiXxHsdtzcR/+6Eq1APuDgvt//jRkI9MDszReXMu ena+qyCKfsB5XhIJbQKEp/vBMgE+kv3/nXOIrVm63aedi0/bTGv1EHXb5+rJxYoGq/f3 LBWiunCkE6SBaaS7/y/2V1CJDQnBrizIMJReBBI9f0pFMatjVEFmdcZEV3eYpRiG2ZiX APyGmzyliMe0EHcx1UOPfL4DJ0+LCXXt0XUz7d1V8ZfiG/VgWWDtAolLsBF0RhyhFGrP DnmO3LfwJHHaEoV0seb60+vuF0rvuk0/bZlaNEF+XrsJHHl5SgOecYrJ7TYw0sRiECf2 PVDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=P4A9YlfH; 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 g5si83846edn.354.2018.12.14.01.44.13; Fri, 14 Dec 2018 01:44:13 -0800 (PST) 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=P4A9YlfH; 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 95E4FC225D0; Fri, 14 Dec 2018 09:44:11 +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_MSPIKE_H2, 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 C0104C21FD6; Fri, 14 Dec 2018 09:44:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 33FE7C21FD6; Fri, 14 Dec 2018 09:44:07 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id 445D7C21F49 for ; Fri, 14 Dec 2018 09:44:06 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id d2so2004814ybs.11 for ; Fri, 14 Dec 2018 01:44:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=r7wwdbRQz3B4/PVs5NP2Ot9MNqM5YCL6BiIWB0lHZRY=; b=P4A9YlfHF6PC14WBZXHT3YajezS0jBb9/xAtLjkp3I2PykYDoWyUtUYZnuvtWwt3H4 ePZmlHfmQEeoSu1HDiA4x2bp0WSl18WgxUBahKYRNhOQ0nZpPeMKtaV5eF8+tqWx/0kZ HU/DJF99akRt9gjWTHCrQUbYslhFeVMXJUsPc= 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:mime-version :content-transfer-encoding; bh=r7wwdbRQz3B4/PVs5NP2Ot9MNqM5YCL6BiIWB0lHZRY=; b=rNOhI2OtAggyFPZ/wrdTLEOD+vf6iSf8kmK+kbJDvWXdkPRPoM3Ozygl66RWt3pI7c xT4cUAV3tX+TbHae8CjVIML4YDSVUP2HGn9APMBBT2CJVo0cJcoRAN+nuyOhpxeEwQi4 t9ASGj6C3yCNRd9kOO7OCkT442fDW6IUSduNYnJYmjgLry0g+2bJlvheG5Mx2Gk0cJGt ZRcrmkn22H5NMuIJI1Zf2LWiiAn57MVn6s5PfxE002Gq2eI3cX/zf0BcOnjtb5zrs7XP DVKmsbTuSxHfCCkPszwC+V+jcF2oju95f7m8JLd3VVOMWjlXtqyZsISXJTvG7/DdK5lH 5O3A== X-Gm-Message-State: AA+aEWYb+tA0rl8H70X0bfA6V/eRMueA4JxQ1NgEiaJzsEiOXHQeG22T czeJUTx8XPuKtzpGERwwg/jw3Q== X-Received: by 2002:a25:3852:: with SMTP id f79mr2098651yba.237.1544780644935; Fri, 14 Dec 2018 01:44:04 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j2sm1425422ywa.73.2018.12.14.01.44.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 01:44:04 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Fri, 14 Dec 2018 18:47:11 +0900 Message-Id: <20181214094712.9051-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 1/2] efi_loader: implement GetNextVariableName() 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" The current GetNextVariableName() is a placeholder. With this patch, it works well as expected. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_variable.c | 116 +++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 19d9cb865f25..dac2f49aa1cc 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #define READ_ONLY BIT(31) @@ -241,14 +244,125 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, efi_guid_t *vendor, return EFI_EXIT(EFI_SUCCESS); } +static char *efi_variables_list; +static char *efi_cur_variable; + +static efi_status_t parse_uboot_variable(char *variable, + efi_uintn_t *variable_name_size, + u16 *variable_name, + efi_guid_t *vendor, + u32 *attribute) +{ + char *guid, *name, *end, c; + unsigned long name_size; + u16 *p; + + guid = strchr(variable, '_'); + if (!guid) + return EFI_NOT_FOUND; + guid++; + name = strchr(guid, '_'); + if (!name) + return EFI_NOT_FOUND; + name++; + end = strchr(name, '='); + if (!end) + return EFI_NOT_FOUND; + + /* FIXME: size is in byte or u16? */ + name_size = end - name; + if (*variable_name_size < (name_size + 1)) { + *variable_name_size = name_size + 1; + return EFI_BUFFER_TOO_SMALL; + } + end++; /* point to value */ + + p = variable_name; + utf8_utf16_strncpy(&p, name, name_size); + variable_name[name_size] = 0; + + c = *(name - 1); + *(name - 1) = '\0'; /* guid need be null-terminated here */ + uuid_str_to_bin(guid, (unsigned char *)vendor, UUID_STR_FORMAT_GUID); + *(name - 1) = c; + + parse_attr(end, attribute); + + return EFI_SUCCESS; +} + /* http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES#GetNextVariableName.28.29 */ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, u16 *variable_name, efi_guid_t *vendor) { + char *native_name, *variable; + ssize_t name_len, list_len; + char regex[256]; + char * const regexlist[] = {regex}; + u32 attribute; + int i; + efi_status_t ret; + EFI_ENTRY("%p \"%ls\" %pUl", variable_name_size, variable_name, vendor); - return EFI_EXIT(EFI_DEVICE_ERROR); + if (!variable_name_size || !variable_name || !vendor) + EFI_EXIT(EFI_INVALID_PARAMETER); + + if (variable_name[0]) { + /* check null-terminated string */ + for (i = 0; i < *variable_name_size; i++) + if (!variable_name[i]) + break; + if (i >= *variable_name_size) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + /* search for the last-returned variable */ + ret = efi_to_native(&native_name, variable_name, vendor); + if (ret) + return EFI_EXIT(ret); + + name_len = strlen(native_name); + for (variable = efi_variables_list; variable && *variable;) { + if (!strncmp(variable, native_name, name_len) && + variable[name_len] == '=') + break; + + variable = strchr(variable, '\n'); + if (variable) + variable++; + } + + free(native_name); + if (!(variable && *variable)) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + /* next variable */ + variable = strchr(variable, '\n'); + if (variable) + variable++; + if (!(variable && *variable)) + return EFI_EXIT(EFI_NOT_FOUND); + } else { + /* new search */ + free(efi_variables_list); + efi_variables_list = NULL; + efi_cur_variable = NULL; + + snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_.*"); + list_len = hexport_r(&env_htab, '\n', + H_MATCH_REGEX | H_MATCH_KEY, + &efi_variables_list, 0, 1, regexlist); + if (list_len <= 0) + return EFI_EXIT(EFI_NOT_FOUND); + + variable = efi_variables_list; + } + + ret = parse_uboot_variable(variable, variable_name_size, variable_name, + vendor, &attribute); + + return EFI_EXIT(ret); } /* http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES#SetVariable.28.29 */ From patchwork Fri Dec 14 09:47:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 153792 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1856994ljp; Fri, 14 Dec 2018 01:45:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/XV2QyjcYWKbApYcznqcjpS+DaSocqXAm3MrvhHfXvWXFDMiqG72H6MPnldDZt0ozHorIeP X-Received: by 2002:a50:a4fc:: with SMTP id x57mr2336505edb.229.1544780703715; Fri, 14 Dec 2018 01:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544780703; cv=none; d=google.com; s=arc-20160816; b=gNIF6HQGfOJJnY5zZCZ0tPFBEGPHFMZwxR2kjkrTJpOz1aEV5qDYHEOPujSkvaXMPW bV3JkN2yVzIbbXWYTSMQbLilNG7cMLQ7eufOdx3DgvrYPR+ONoHT3GKmNXWvbf5iLxFz 2xUiI+FhjvDe+AixJPZTPCfS9MGBwD1WqIUIw/12G3qovo3Fx+fiSW5mBJG9lvfv4UxX lWkKtzHlM5fDH+hcvpT0MWaaGpmmQABDF2v1HX/dEAOPWoiTQ0hFnN8JkfVGMxJM1zvY NZKrP+2C+INB2zlKs8thC/FDJyFn2u5mT0+gtedgCPetWcQMahlcgOI2qgX6Xfg6ZMhf IVpA== 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=J/ze6NnuP1mTRf2/csTrfwbIPrVTi3NJf7gIGShxcVU=; b=R5sdmjgjNhiHyIrrX7jcb01XG88uDelGE0FU11w7afg5/jaCAiiEkOhWUaP3h0yMIy nuNVhx/OC8Tlq/l3bEtDszaQnLUm9/hG3g++mCsvFk9LCbGLZviwBlZHNTH2sutllel4 YwGUUisaQknSJesYpJlEj0YfqaHKlLOw88mgrU5mKpFhk1vdlxDb6nxvg3++tubIJYHl rPNHsmdLBiwucmDQuQTlhs9TbA+Mi6eEa975dG+TcIBxKPhvXgW2Y68sYItraPV8lpLQ CgHKUqI1gjX7852LS9sKSNgAgwpPXjhkxXNl7muWdK7Hm/KQUdkPtvXGcjHbVb0dZ3Qd kH3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Ra30AYVp; 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 y4si1770694edr.395.2018.12.14.01.45.03; Fri, 14 Dec 2018 01:45:03 -0800 (PST) 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=Ra30AYVp; 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 F02C6C22652; Fri, 14 Dec 2018 09:44:32 +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_MSPIKE_H2, 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 CEABEC22728; Fri, 14 Dec 2018 09:44:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C7BF5C225D0; Fri, 14 Dec 2018 09:44:18 +0000 (UTC) Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by lists.denx.de (Postfix) with ESMTPS id 35EE1C225C8 for ; Fri, 14 Dec 2018 09:44:13 +0000 (UTC) Received: by mail-yb1-f173.google.com with SMTP id d187so2016755ybb.5 for ; Fri, 14 Dec 2018 01:44:13 -0800 (PST) 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=CDOCf6059/4xxW6OStGHy9rjzPfoXP4ZZeC/hh4z/6w=; b=Ra30AYVpcW9PX+VR84peaGU5VlMAFPiQ0/Zq8JTfSkA8j78g4+kNoEtmpFTos84/UY Z+ODaxp7J6PHhMPunMSbrrsUZf3SxSFafE6ExbntEAEWGHQA1/hXCNKElvdjC8/XExxe GfwclDpAgaaH6dQOSFzOmTVUnC3x7o2EovLm4= 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=CDOCf6059/4xxW6OStGHy9rjzPfoXP4ZZeC/hh4z/6w=; b=chg8yz43TFHCINaJWU+J9Zr742j2K3X8Sb9JVMaNZUSQnKUJAxbKU1MWiZjio4hw+6 ILLboWTatKZOAEwYoF+TSWMNSdeL1Z3PGlPty0jhINPLIRNVhetxLa7noMCX3aD+cvS6 LoWA+SRkU7sYqu+1/yuLBDj8ghSAfGOgZ2lXYqV8MUlQmMuMHZSqndZEjF+ByV4xF5QL sFhMBUr4CqlKlyomDBDrCcOh/FXlF2+tAA6c8I2/a5k3itOOpQwfpSaLWpABcY7rsjQq dwha5zxp7CSDOgonS/cIC4kLrAweroMgQsv7UGE7CQGAstbpjpldPgQHJ1hOsuF5Dx2I IQnw== X-Gm-Message-State: AA+aEWbAjY2IXHW5H8o2uU8zjU1hlSVCp4F1J+AJ+HGBM5pOEG7WhARj SN3JV11ZUivvW0jx0bhjO7GzZw== X-Received: by 2002:a25:b783:: with SMTP id n3mr2215642ybh.141.1544780652111; Fri, 14 Dec 2018 01:44:12 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v202sm1565349ywv.19.2018.12.14.01.44.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 01:44:11 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Fri, 14 Dec 2018 18:47:12 +0900 Message-Id: <20181214094712.9051-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181214094712.9051-1-takahiro.akashi@linaro.org> References: <20181214094712.9051-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 2/2] efi_selftest: fix variables test for GetNextVariableName() 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" There is a bug in efi variables test. Fix it with some cosmetic improvements. Please note that efi variables test still fails at QueryVariableInfo() and GetVariable(), but this is not due to a change in this patch. ==8<== Testing EFI API implementation Selected test: 'variables' Setting up 'variables' Setting up 'variables' succeeded Executing 'variables' .../u-boot/lib/efi_selftest/efi_selftest_variables.c(60): TODO: QueryVariableInfo failed .../u-boot/lib/efi_selftest/efi_selftest_variables.c(131): TODO: GetVariable returned wrong length 7 .../u-boot/lib/efi_selftest/efi_selftest_variables.c(133): TODO: GetVariable returned wrong value Executing 'variables' succeeded Boot services terminated Summary: 0 failures ==>8== Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- lib/efi_selftest/efi_selftest_variables.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c index e4c389a872fa..c58434289325 100644 --- a/lib/efi_selftest/efi_selftest_variables.c +++ b/lib/efi_selftest/efi_selftest_variables.c @@ -141,19 +141,22 @@ static int execute(void) if (ret == EFI_NOT_FOUND) break; if (ret != EFI_SUCCESS) { - efi_st_todo("GetNextVariableName failed\n"); - break; + efi_st_error("GetNextVariableName failed (%u)\n", + (unsigned int)ret); + return EFI_ST_FAILURE; } if (!efi_st_memcmp(&guid, &guid_vendor0, sizeof(efi_guid_t)) && !efi_st_strcmp_16_8(varname, "efi_st_var0")) - flag |= 2; + flag |= 1; if (!efi_st_memcmp(&guid, &guid_vendor1, sizeof(efi_guid_t)) && !efi_st_strcmp_16_8(varname, "efi_st_var1")) flag |= 2; } - if (flag != 3) - efi_st_todo( + if (flag != 3) { + efi_st_error( "GetNextVariableName did not return all variables\n"); + return EFI_ST_FAILURE; + } /* Delete variable 1 */ ret = runtime->set_variable(L"efi_st_var1", &guid_vendor1, 0, 0, NULL);