[{"id":1771677,"web_url":"http://patchwork.ozlabs.org/comment/1771677/","msgid":"<942b499b-1344-26cd-5c0b-36937d96e1e6@suse.de>","list_archive_url":null,"date":"2017-09-20T08:31:37","subject":"Re: [U-Boot] [PATCH v3 05/21] efi_loader: add device-path utils","submitter":{"id":1212,"url":"http://patchwork.ozlabs.org/api/people/1212/","name":"Alexander Graf","email":"agraf@suse.de"},"content":"On 14.09.17 00:05, Rob Clark wrote:\n> Helpers to construct device-paths from devices, partitions, files, and\n> for parsing and manipulating device-paths.\n> \n> For non-legacy devices, this will use u-boot's device-model to construct\n> device-paths which include bus hierarchy to construct device-paths.  For\n> legacy devices we still fake it, but slightly more convincingly.\n> \n> Signed-off-by: Rob Clark <robdclark@gmail.com>\n\nThis patch gives me checkpatch warnings left and right (unsigned vs \nunsigned int, double blank lines, double assignments, unsafe define, \n...). I'll pull it in for now since it seems to be functionally correct, \nbut please fix up the warnings in a follow-up patch.\n\n\nAlex\n\nWARNING: Adding new packed members is to be done with care\n#56: FILE: include/efi_api.h:340:\n+} __packed;\n\nCHECK: Please don't use multiple blank lines\n#69: FILE: include/efi_loader.h:200:\n\n+\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#74: FILE: include/efi_loader.h:205:\n+unsigned efi_dp_size(const struct efi_device_path *dp);\n\nCHECK: Please don't use multiple blank lines\n#81: FILE: include/efi_loader.h:212:\n+\n+\n\nCHECK: Macro argument reuse '_dp' - possible side-effects?\n#91: FILE: include/efi_loader.h:222:\n+#define EFI_DP_TYPE(_dp, _type, _subtype) \\\n+\t(((_dp)->type == DEVICE_PATH_TYPE_##_type) && \\\n+\t ((_dp)->sub_type == DEVICE_PATH_SUB_TYPE_##_subtype))\n\nWARNING: added, moved or deleted file(s), does MAINTAINERS need updating?\n#136:\nnew file mode 100644\n\nCHECK: Comparison to NULL could be written \"!dp\"\n#195: FILE: lib/efi_loader/efi_device_path.c:55:\n+\tif (dp == NULL)\n\nCHECK: Please don't use multiple blank lines\n#232: FILE: lib/efi_loader/efi_device_path.c:92:\n+\n+\n\nCHECK: Please don't use multiple blank lines\n#301: FILE: lib/efi_loader/efi_device_path.c:161:\n+\n+\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#320: FILE: lib/efi_loader/efi_device_path.c:180:\n+unsigned efi_dp_size(const struct efi_device_path *dp)\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#322: FILE: lib/efi_loader/efi_device_path.c:182:\n+\tunsigned sz = 0;\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#335: FILE: lib/efi_loader/efi_device_path.c:195:\n+\tunsigned sz = efi_dp_size(dp) + sizeof(END);\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#357: FILE: lib/efi_loader/efi_device_path.c:217:\n+\t\tunsigned sz1 = efi_dp_size(dp1);\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#358: FILE: lib/efi_loader/efi_device_path.c:218:\n+\t\tunsigned sz2 = efi_dp_size(dp2);\n\nWARNING: Missing a blank line after declarations\n#360: FILE: lib/efi_loader/efi_device_path.c:220:\n+\t\tvoid *p = dp_alloc(sz1 + sz2 + sizeof(END));\n+\t\tmemcpy(p, dp1, sz1);\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#379: FILE: lib/efi_loader/efi_device_path.c:239:\n+\t\tunsigned sz = node->length;\n\nWARNING: Missing a blank line after declarations\n#381: FILE: lib/efi_loader/efi_device_path.c:241:\n+\t\tvoid *p = dp_alloc(sz + sizeof(END));\n+\t\tmemcpy(p, node, sz);\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#386: FILE: lib/efi_loader/efi_device_path.c:246:\n+\t\tunsigned sz = efi_dp_size(dp);\n\nWARNING: Missing a blank line after declarations\n#388: FILE: lib/efi_loader/efi_device_path.c:248:\n+\t\tvoid *p = dp_alloc(sz + node->length + sizeof(END));\n+\t\tmemcpy(p, dp, sz);\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#401: FILE: lib/efi_loader/efi_device_path.c:261:\n+static unsigned dp_size(struct udevice *dev)\n\nCHECK: multiple assignments should be avoided\n#484: FILE: lib/efi_loader/efi_device_path.c:344:\n+\tstart = buf = dp_alloc(dp_size(dev) + sizeof(END));\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#492: FILE: lib/efi_loader/efi_device_path.c:352:\n+static unsigned dp_part_size(struct blk_desc *desc, int part)\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#494: FILE: lib/efi_loader/efi_device_path.c:354:\n+\tunsigned dpsize;\n\nCHECK: Please don't use multiple blank lines\n#581: FILE: lib/efi_loader/efi_device_path.c:441:\n+\n+\n\nCHECK: multiple assignments should be avoided\n#587: FILE: lib/efi_loader/efi_device_path.c:447:\n+\tstart = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END));\n\nWARNING: Missing a blank line after declarations\n#601: FILE: lib/efi_loader/efi_device_path.c:461:\n+\t\tchar c = *(path++);\n+\t\tif (c == '/')\n\nCHECK: Alignment should match open parenthesis\n#613: FILE: lib/efi_loader/efi_device_path.c:473:\n+struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,\n+\t\tconst char *path)\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#617: FILE: lib/efi_loader/efi_device_path.c:477:\n+\tunsigned dpsize = 0, fpsize;\n\nCHECK: multiple assignments should be avoided\n#625: FILE: lib/efi_loader/efi_device_path.c:485:\n+\tstart = buf = dp_alloc(dpsize + sizeof(END));\n\nWARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n#648: FILE: lib/efi_loader/efi_device_path.c:508:\n+\tunsigned dpsize = 0;\n\nCHECK: multiple assignments should be avoided\n#659: FILE: lib/efi_loader/efi_device_path.c:519:\n+\tstart = buf = dp_alloc(dpsize + sizeof(END));\n\ntotal: 0 errors, 19 warnings, 12 checks, 644 lines checked\n\nNOTE: For some of the reported defects, checkpatch may be able to\n       mechanically convert to the typical style using --fix or \n--fix-inplace.\n\nYour patch has style problems, please review.\n\nNOTE: Ignored message types: COMPLEX_MACRO CONSIDER_KSTRTO MINMAX \nMULTISTATEMENT_MACRO_USE_DO_WHILE NETWORKING_BLOCK_COMMENT_STYLE \nPREFER_ETHER_ADDR_COPY USLEEP_RANGE\n\nNOTE: If any of the errors are false positives, please report\n       them to the maintainer, see CHECKPATCH in MAINTAINERS.","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xxtJV5h9Fz9sNr\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 20 Sep 2017 18:31:53 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 3634DC21DE4; Wed, 20 Sep 2017 08:31:44 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 2DD2FC21C71;\n\tWed, 20 Sep 2017 08:31:42 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid BD5B2C21C71; Wed, 20 Sep 2017 08:31:40 +0000 (UTC)","from mx1.suse.de (mx2.suse.de [195.135.220.15])\n\tby lists.denx.de (Postfix) with ESMTPS id 36D83C21C35\n\tfor <u-boot@lists.denx.de>; Wed, 20 Sep 2017 08:31:40 +0000 (UTC)","from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254])\n\tby mx1.suse.de (Postfix) with ESMTP id 7874B5CB21;\n\tWed, 20 Sep 2017 08:31:39 +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=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED\n\tautolearn=unavailable autolearn_force=no version=3.4.0","X-Virus-Scanned":"by amavisd-new at test-mx.suse.de","To":"Rob Clark <robdclark@gmail.com>,\n\tU-Boot Mailing List <u-boot@lists.denx.de>","References":"<20170913220546.19560-1-robdclark@gmail.com>\n\t<20170913220546.19560-6-robdclark@gmail.com>","From":"Alexander Graf <agraf@suse.de>","Message-ID":"<942b499b-1344-26cd-5c0b-36937d96e1e6@suse.de>","Date":"Wed, 20 Sep 2017 10:31:37 +0200","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0)\n\tGecko/20100101 Thunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170913220546.19560-6-robdclark@gmail.com>","Content-Language":"en-US","Cc":"Heinrich Schuchardt <xypron.glpk@gmx.de>, Peter Jones <pjones@redhat.com>","Subject":"Re: [U-Boot] [PATCH v3 05/21] efi_loader: add device-path utils","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Transfer-Encoding":"base64","Content-Type":"text/plain; charset=\"utf-8\"; Format=\"flowed\"","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}},{"id":1771905,"web_url":"http://patchwork.ozlabs.org/comment/1771905/","msgid":"<CAF6AEGuvPJerDNkqkEDb5QVU2BN5rb5+6mmL-WbWrLE-ftMbug@mail.gmail.com>","list_archive_url":null,"date":"2017-09-20T14:15:02","subject":"Re: [U-Boot] [PATCH v3 05/21] efi_loader: add device-path utils","submitter":{"id":18760,"url":"http://patchwork.ozlabs.org/api/people/18760/","name":"Rob Clark","email":"robdclark@gmail.com"},"content":"On Wed, Sep 20, 2017 at 4:31 AM, Alexander Graf <agraf@suse.de> wrote:\n>\n>\n> On 14.09.17 00:05, Rob Clark wrote:\n>>\n>> Helpers to construct device-paths from devices, partitions, files, and\n>> for parsing and manipulating device-paths.\n>>\n>> For non-legacy devices, this will use u-boot's device-model to construct\n>> device-paths which include bus hierarchy to construct device-paths.  For\n>> legacy devices we still fake it, but slightly more convincingly.\n>>\n>> Signed-off-by: Rob Clark <robdclark@gmail.com>\n>\n>\n> This patch gives me checkpatch warnings left and right (unsigned vs unsigned\n> int, double blank lines, double assignments, unsafe define, ...). I'll pull\n> it in for now since it seems to be functionally correct, but please fix up\n> the warnings in a follow-up patch.\n>\n>\n> Alex\n>\n> WARNING: Adding new packed members is to be done with care\n> #56: FILE: include/efi_api.h:340:\n> +} __packed;\n\nfwiw, the __packed warnings are bogus and should be ignored.  Maybe\nsomeone can fix checkpatch to whitelist efi_api.h (or just drop that\nwarning again).\n\nBR,\n-R\n\n>\n> CHECK: Please don't use multiple blank lines\n> #69: FILE: include/efi_loader.h:200:\n>\n> +\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #74: FILE: include/efi_loader.h:205:\n> +unsigned efi_dp_size(const struct efi_device_path *dp);\n>\n> CHECK: Please don't use multiple blank lines\n> #81: FILE: include/efi_loader.h:212:\n> +\n> +\n>\n> CHECK: Macro argument reuse '_dp' - possible side-effects?\n> #91: FILE: include/efi_loader.h:222:\n> +#define EFI_DP_TYPE(_dp, _type, _subtype) \\\n> +       (((_dp)->type == DEVICE_PATH_TYPE_##_type) && \\\n> +        ((_dp)->sub_type == DEVICE_PATH_SUB_TYPE_##_subtype))\n>\n> WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?\n> #136:\n> new file mode 100644\n>\n> CHECK: Comparison to NULL could be written \"!dp\"\n> #195: FILE: lib/efi_loader/efi_device_path.c:55:\n> +       if (dp == NULL)\n>\n> CHECK: Please don't use multiple blank lines\n> #232: FILE: lib/efi_loader/efi_device_path.c:92:\n> +\n> +\n>\n> CHECK: Please don't use multiple blank lines\n> #301: FILE: lib/efi_loader/efi_device_path.c:161:\n> +\n> +\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #320: FILE: lib/efi_loader/efi_device_path.c:180:\n> +unsigned efi_dp_size(const struct efi_device_path *dp)\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #322: FILE: lib/efi_loader/efi_device_path.c:182:\n> +       unsigned sz = 0;\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #335: FILE: lib/efi_loader/efi_device_path.c:195:\n> +       unsigned sz = efi_dp_size(dp) + sizeof(END);\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #357: FILE: lib/efi_loader/efi_device_path.c:217:\n> +               unsigned sz1 = efi_dp_size(dp1);\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #358: FILE: lib/efi_loader/efi_device_path.c:218:\n> +               unsigned sz2 = efi_dp_size(dp2);\n>\n> WARNING: Missing a blank line after declarations\n> #360: FILE: lib/efi_loader/efi_device_path.c:220:\n> +               void *p = dp_alloc(sz1 + sz2 + sizeof(END));\n> +               memcpy(p, dp1, sz1);\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #379: FILE: lib/efi_loader/efi_device_path.c:239:\n> +               unsigned sz = node->length;\n>\n> WARNING: Missing a blank line after declarations\n> #381: FILE: lib/efi_loader/efi_device_path.c:241:\n> +               void *p = dp_alloc(sz + sizeof(END));\n> +               memcpy(p, node, sz);\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #386: FILE: lib/efi_loader/efi_device_path.c:246:\n> +               unsigned sz = efi_dp_size(dp);\n>\n> WARNING: Missing a blank line after declarations\n> #388: FILE: lib/efi_loader/efi_device_path.c:248:\n> +               void *p = dp_alloc(sz + node->length + sizeof(END));\n> +               memcpy(p, dp, sz);\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #401: FILE: lib/efi_loader/efi_device_path.c:261:\n> +static unsigned dp_size(struct udevice *dev)\n>\n> CHECK: multiple assignments should be avoided\n> #484: FILE: lib/efi_loader/efi_device_path.c:344:\n> +       start = buf = dp_alloc(dp_size(dev) + sizeof(END));\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #492: FILE: lib/efi_loader/efi_device_path.c:352:\n> +static unsigned dp_part_size(struct blk_desc *desc, int part)\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #494: FILE: lib/efi_loader/efi_device_path.c:354:\n> +       unsigned dpsize;\n>\n> CHECK: Please don't use multiple blank lines\n> #581: FILE: lib/efi_loader/efi_device_path.c:441:\n> +\n> +\n>\n> CHECK: multiple assignments should be avoided\n> #587: FILE: lib/efi_loader/efi_device_path.c:447:\n> +       start = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END));\n>\n> WARNING: Missing a blank line after declarations\n> #601: FILE: lib/efi_loader/efi_device_path.c:461:\n> +               char c = *(path++);\n> +               if (c == '/')\n>\n> CHECK: Alignment should match open parenthesis\n> #613: FILE: lib/efi_loader/efi_device_path.c:473:\n> +struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,\n> +               const char *path)\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #617: FILE: lib/efi_loader/efi_device_path.c:477:\n> +       unsigned dpsize = 0, fpsize;\n>\n> CHECK: multiple assignments should be avoided\n> #625: FILE: lib/efi_loader/efi_device_path.c:485:\n> +       start = buf = dp_alloc(dpsize + sizeof(END));\n>\n> WARNING: Prefer 'unsigned int' to bare use of 'unsigned'\n> #648: FILE: lib/efi_loader/efi_device_path.c:508:\n> +       unsigned dpsize = 0;\n>\n> CHECK: multiple assignments should be avoided\n> #659: FILE: lib/efi_loader/efi_device_path.c:519:\n> +       start = buf = dp_alloc(dpsize + sizeof(END));\n>\n> total: 0 errors, 19 warnings, 12 checks, 644 lines checked\n>\n> NOTE: For some of the reported defects, checkpatch may be able to\n>       mechanically convert to the typical style using --fix or\n> --fix-inplace.\n>\n> Your patch has style problems, please review.\n>\n> NOTE: Ignored message types: COMPLEX_MACRO CONSIDER_KSTRTO MINMAX\n> MULTISTATEMENT_MACRO_USE_DO_WHILE NETWORKING_BLOCK_COMMENT_STYLE\n> PREFER_ETHER_ADDR_COPY USLEEP_RANGE\n>\n> NOTE: If any of the errors are false positives, please report\n>       them to the maintainer, see CHECKPATCH in MAINTAINERS.\n>","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"h47Vo+W6\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xy1wg2PdHz9s82\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 00:15:15 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 1CDFBC21F56; Wed, 20 Sep 2017 14:15:08 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 64295C21EAE;\n\tWed, 20 Sep 2017 14:15:05 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 9F99EC21EAE; Wed, 20 Sep 2017 14:15:03 +0000 (UTC)","from mail-lf0-f67.google.com (mail-lf0-f67.google.com\n\t[209.85.215.67])\n\tby lists.denx.de (Postfix) with ESMTPS id 30422C21DA2\n\tfor <u-boot@lists.denx.de>; Wed, 20 Sep 2017 14:15:03 +0000 (UTC)","by mail-lf0-f67.google.com with SMTP id h80so1468918lfe.1\n\tfor <u-boot@lists.denx.de>; Wed, 20 Sep 2017 07:15:03 -0700 (PDT)","by 10.46.41.75 with HTTP; Wed, 20 Sep 2017 07:15:02 -0700 (PDT)"],"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=FREEMAIL_FROM,\n\tRCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID\n\tautolearn=unavailable autolearn_force=no version=3.4.0","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=mime-version:in-reply-to:references:from:date:message-id:subject:to\n\t:cc; bh=PoasT49HbYjHI28v25dgWTxpSs0VYWekrmW22ws2PMs=;\n\tb=h47Vo+W65p9WlAFFeevJbWkLuNMIV4Hsbupchxc/hfPV6fIRqpLPrgSgsX7BWXNBT5\n\tWkoqt0K+OqUROECrmf7zlBkAQkfEQjSD78dKl4wkJZACXY43ZiztmySZkWddNVbsruiQ\n\tZpRcr8uwJAX9dhmMDkyEZvsRK4BKYETandhRpzZz0utaHxennihfmFj/o/GQtnY8cXyo\n\tKCS2Lc1zSBRYIwjJgu0Rcj2jvMwwHP36aASeKq/Q0yww0zshltvOqnjoYV/gBI0qV3xa\n\ti7rG2bI7uwvNUHD59SU/tcRhK5sFURAt7Gceffwkdjt/9f0nWMFdrdUZSpw1RJfQyGFR\n\td6cA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:in-reply-to:references:from:date\n\t:message-id:subject:to:cc;\n\tbh=PoasT49HbYjHI28v25dgWTxpSs0VYWekrmW22ws2PMs=;\n\tb=UEBqCgAEsUVoWU/SfN3vGaafwzLMRPqhH/lteRFUTTNxMFWHUTdYdRzlAZ0Fr/rI+0\n\tU+TlnWsMDvDiZw+xvsgkIPsh/c1n4tV7y0P55X9ob4k6oCJpw+QLJnu1n1rVN4du90pY\n\t6rP37Zm+e9kQ+dDlyivsXAKMGAcCR/j8cSYOQTKovDrevaafMthV8sFd0Gzil0ottSLx\n\tDUeH1QsA1k7Iq1bNJlh5dY2MlORLbsJ2xKC5SwmBkxAwBcERvB1VfG6rXFTXGOjlJ7t+\n\tUJvoXQi6aM2Am2Ifu8NXjh3Cz1LnpcqoKYFd19t3BzWNDcpU1I8TvA1+Y754MCb5PqRB\n\tExLg==","X-Gm-Message-State":"AHPjjUj3ougq7jS4wQlNTKFVfGlXbgTJXIOutOQ+iqik4Yp6z6yjYoOv\n\tabPMVI/dAio+DQGb0sno3bZ1q7JfA8MRZGqFz4w=","X-Google-Smtp-Source":"AOwi7QDNwG6uewyMYE7joLY/tLdc2d7MV/mwCFQWF0cJiXZOPxr5Cptb+MnPEblm+VEGS9eUbUrS8GIAJmZ+YpJb6Xw=","X-Received":"by 10.46.43.157 with SMTP id r29mr2348236ljr.56.1505916902627;\n\tWed, 20 Sep 2017 07:15:02 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<942b499b-1344-26cd-5c0b-36937d96e1e6@suse.de>","References":"<20170913220546.19560-1-robdclark@gmail.com>\n\t<20170913220546.19560-6-robdclark@gmail.com>\n\t<942b499b-1344-26cd-5c0b-36937d96e1e6@suse.de>","From":"Rob Clark <robdclark@gmail.com>","Date":"Wed, 20 Sep 2017 10:15:02 -0400","Message-ID":"<CAF6AEGuvPJerDNkqkEDb5QVU2BN5rb5+6mmL-WbWrLE-ftMbug@mail.gmail.com>","To":"Alexander Graf <agraf@suse.de>","Cc":"Heinrich Schuchardt <xypron.glpk@gmx.de>,\n\tU-Boot Mailing List <u-boot@lists.denx.de>,\n\tPeter Jones <pjones@redhat.com>","Subject":"Re: [U-Boot] [PATCH v3 05/21] efi_loader: add device-path utils","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}},{"id":1772460,"web_url":"http://patchwork.ozlabs.org/comment/1772460/","msgid":"<150597747510.57553.8169382283047572410@achrid.arch.suse.de>","list_archive_url":null,"date":"2017-09-21T07:04:35","subject":"Re: [U-Boot] [U-Boot,v3,05/21] efi_loader: add device-path utils","submitter":{"id":1212,"url":"http://patchwork.ozlabs.org/api/people/1212/","name":"Alexander Graf","email":"agraf@suse.de"},"content":"> Helpers to construct device-paths from devices, partitions, files, and\n> for parsing and manipulating device-paths.\n> \n> For non-legacy devices, this will use u-boot's device-model to construct\n> device-paths which include bus hierarchy to construct device-paths.  For\n> legacy devices we still fake it, but slightly more convincingly.\n> \n> Signed-off-by: Rob Clark <robdclark@gmail.com>\n\nThanks, applied to efi-next\n\nAlex","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xySKv6ZLmz9sBZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 17:05:07 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 91EF6C21F35; Thu, 21 Sep 2017 07:04:53 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id DF160C21F3C;\n\tThu, 21 Sep 2017 07:04:51 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 40DF7C21F05; Thu, 21 Sep 2017 07:04:39 +0000 (UTC)","from mx1.suse.de (mx2.suse.de [195.135.220.15])\n\tby lists.denx.de (Postfix) with ESMTPS id 52722C21E76\n\tfor <u-boot@lists.denx.de>; Thu, 21 Sep 2017 07:04:36 +0000 (UTC)","from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254])\n\tby mx1.suse.de (Postfix) with ESMTP id 1C1DBABDB;\n\tThu, 21 Sep 2017 07:04:36 +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=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED\n\tautolearn=unavailable autolearn_force=no version=3.4.0","X-Virus-Scanned":"by amavisd-new at test-mx.suse.de","From":"Alexander Graf <agraf@suse.de>","To":"Rob Clark <robdclark@gmail.com>","Date":"Thu, 21 Sep 2017 09:04:35 +0200","Message-Id":"<150597747510.57553.8169382283047572410@achrid.arch.suse.de>","X-Mailer":"git-send-email 2.12.3","In-Reply-To":"<20170913220546.19560-6-robdclark@gmail.com>","References":"<20170913220546.19560-6-robdclark@gmail.com>","MIME-Version":": 1.0","Cc":"U-Boot Mailing List <u-boot@lists.denx.de>","Subject":"Re: [U-Boot] [U-Boot,v3,05/21] efi_loader: add device-path utils","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}},{"id":1795292,"web_url":"http://patchwork.ozlabs.org/comment/1795292/","msgid":"<87a592b0-c8f8-b2b0-f96a-7110d5b41aee@gmx.de>","list_archive_url":null,"date":"2017-10-28T15:53:47","subject":"Re: [U-Boot] [PATCH v3 05/21] efi_loader: add device-path utils","submitter":{"id":61270,"url":"http://patchwork.ozlabs.org/api/people/61270/","name":"Heinrich Schuchardt","email":"xypron.glpk@gmx.de"},"content":"On 09/14/2017 12:05 AM, Rob Clark wrote:\n> Helpers to construct device-paths from devices, partitions, files, and\n> for parsing and manipulating device-paths.\n> \n> For non-legacy devices, this will use u-boot's device-model to construct\n> device-paths which include bus hierarchy to construct device-paths.  For\n> legacy devices we still fake it, but slightly more convincingly.\n> \n> Signed-off-by: Rob Clark <robdclark@gmail.com>\n> ---\n>  include/efi_api.h                |  10 +\n>  include/efi_loader.h             |  26 ++\n>  lib/efi_loader/Makefile          |   2 +-\n>  lib/efi_loader/efi_boottime.c    |  13 +-\n>  lib/efi_loader/efi_device_path.c | 563 +++++++++++++++++++++++++++++++++++++++\n>  5 files changed, 611 insertions(+), 3 deletions(-)\n>  create mode 100644 lib/efi_loader/efi_device_path.c\n> \n> diff --git a/include/efi_api.h b/include/efi_api.h\n> index b761cf4822..4e27c82129 100644\n> --- a/include/efi_api.h\n> +++ b/include/efi_api.h\n> @@ -314,6 +314,7 @@ struct efi_device_path_acpi_path {\n>  #define DEVICE_PATH_TYPE_MESSAGING_DEVICE\t0x03\n>  #  define DEVICE_PATH_SUB_TYPE_MSG_USB\t\t0x05\n>  #  define DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR\t0x0b\n> +#  define DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS\t0x0f\n>  #  define DEVICE_PATH_SUB_TYPE_MSG_SD\t\t0x1a\n>  #  define DEVICE_PATH_SUB_TYPE_MSG_MMC\t\t0x1d\n>  \n> @@ -329,6 +330,15 @@ struct efi_device_path_mac_addr {\n>  \tu8 if_type;\n>  } __packed;\n>  \n> +struct efi_device_path_usb_class {\n> +\tstruct efi_device_path dp;\n> +\tu16 vendor_id;\n> +\tu16 product_id;\n> +\tu8 device_class;\n> +\tu8 device_subclass;\n> +\tu8 device_protocol;\n> +} __packed;\n> +\n>  struct efi_device_path_sd_mmc_path {\n>  \tstruct efi_device_path dp;\n>  \tu8 slot_number;\n> diff --git a/include/efi_loader.h b/include/efi_loader.h\n> index 1179234f68..d052b03ab7 100644\n> --- a/include/efi_loader.h\n> +++ b/include/efi_loader.h\n> @@ -197,6 +197,32 @@ extern void *efi_bounce_buffer;\n>  #define EFI_LOADER_BOUNCE_BUFFER_SIZE (64 * 1024 * 1024)\n>  #endif\n>  \n> +\n> +struct efi_device_path *efi_dp_next(const struct efi_device_path *dp);\n> +int efi_dp_match(struct efi_device_path *a, struct efi_device_path *b);\n> +struct efi_object *efi_dp_find_obj(struct efi_device_path *dp,\n> +\t\t\t\t   struct efi_device_path **rem);\n> +unsigned efi_dp_size(const struct efi_device_path *dp);\n> +struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp);\n> +struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,\n> +\t\t\t\t      const struct efi_device_path *dp2);\n> +struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,\n> +\t\t\t\t\t   const struct efi_device_path *node);\n> +\n> +\n> +struct efi_device_path *efi_dp_from_dev(struct udevice *dev);\n> +struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part);\n> +struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,\n> +\t\t\t\t\t const char *path);\n> +struct efi_device_path *efi_dp_from_eth(void);\n> +void efi_dp_split_file_path(struct efi_device_path *full_path,\n> +\t\t\t    struct efi_device_path **device_path,\n> +\t\t\t    struct efi_device_path **file_path);\n> +\n> +#define EFI_DP_TYPE(_dp, _type, _subtype) \\\n> +\t(((_dp)->type == DEVICE_PATH_TYPE_##_type) && \\\n> +\t ((_dp)->sub_type == DEVICE_PATH_SUB_TYPE_##_subtype))\n> +\n>  /* Convert strings from normal C strings to uEFI strings */\n>  static inline void ascii2unicode(u16 *unicode, const char *ascii)\n>  {\n> diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile\n> index 30bf343a36..f35e5ce8a8 100644\n> --- a/lib/efi_loader/Makefile\n> +++ b/lib/efi_loader/Makefile\n> @@ -15,7 +15,7 @@ always := $(efiprogs-y)\n>  \n>  obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o\n>  obj-y += efi_image_loader.o efi_boottime.o efi_runtime.o efi_console.o\n> -obj-y += efi_memory.o efi_device_path_to_text.o\n> +obj-y += efi_memory.o efi_device_path_to_text.o efi_device_path.o\n>  obj-$(CONFIG_LCD) += efi_gop.o\n>  obj-$(CONFIG_DM_VIDEO) += efi_gop.o\n>  obj-$(CONFIG_PARTITIONS) += efi_disk.o\n> diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c\n> index 43f32385fa..b962b62a97 100644\n> --- a/lib/efi_loader/efi_boottime.c\n> +++ b/lib/efi_loader/efi_boottime.c\n> @@ -665,8 +665,17 @@ static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,\n>  \t\t\tstruct efi_device_path **device_path,\n>  \t\t\tefi_handle_t *device)\n>  {\n> -\tEFI_ENTRY(\"%p, %p, %p\", protocol, device_path, device);\n> -\treturn EFI_EXIT(EFI_NOT_FOUND);\n> +\tstruct efi_object *efiobj;\n> +\n> +\tEFI_ENTRY(\"%pUl, %p, %p\", protocol, device_path, device);\n> +\n> +\tefiobj = efi_dp_find_obj(*device_path, device_path);\n\nThe patch is already merged.\n\nefi_dp_find_obj does not implement the logic required by\nLocateDevicePath. Parameter protocol is completely ignored!\n\nThis is what LocateDevicePath is expected to do:\nStart at the full device path and check if the related handle implements\nthe protocol.\nIteratively remove the rightmost node and try again.\nReturn the handle of the longest left subpath implementing the protocol.\n\nGiven handles with device paths\n'/part1' and '/part1/part2' implementing 'protocol' a query\nfor device path '/part1/part2/part3' and 'protocol' should return the\nhandle of '/part1/part2' and remaining path '/part3'.\n\n> +\tif (!efiobj)\n> +\t\treturn EFI_EXIT(EFI_NOT_FOUND);\n> +\n> +\t*device = efiobj->handle;\n> +\n> +\treturn EFI_EXIT(EFI_SUCCESS);\n>  }\n>  \n>  /* Collapses configuration table entries, removing index i */\n> diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c\n> new file mode 100644\n> index 0000000000..5d5c3b3464\n> --- /dev/null\n> +++ b/lib/efi_loader/efi_device_path.c\n> @@ -0,0 +1,563 @@\n> +/*\n> + * EFI device path from u-boot device-model mapping\n> + *\n> + * (C) Copyright 2017 Rob Clark\n> + *\n> + * SPDX-License-Identifier:\tGPL-2.0+\n> + */\n> +\n> +#include <common.h>\n> +#include <blk.h>\n> +#include <dm.h>\n> +#include <usb.h>\n> +#include <mmc.h>\n> +#include <efi_loader.h>\n> +#include <inttypes.h>\n> +#include <part.h>\n> +\n> +/* template END node: */\n> +static const struct efi_device_path END = {\n> +\t.type     = DEVICE_PATH_TYPE_END,\n> +\t.sub_type = DEVICE_PATH_SUB_TYPE_END,\n> +\t.length   = sizeof(END),\n> +};\n> +\n> +#define U_BOOT_GUID \\\n> +\tEFI_GUID(0xe61d73b9, 0xa384, 0x4acc, \\\n> +\t\t 0xae, 0xab, 0x82, 0xe8, 0x28, 0xf3, 0x62, 0x8b)\n> +\n> +/* template ROOT node: */\n> +static const struct efi_device_path_vendor ROOT = {\n> +\t.dp = {\n> +\t\t.type     = DEVICE_PATH_TYPE_HARDWARE_DEVICE,\n> +\t\t.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR,\n> +\t\t.length   = sizeof(ROOT),\n> +\t},\n> +\t.guid = U_BOOT_GUID,\n> +};\n> +\n> +static void *dp_alloc(size_t sz)\n> +{\n> +\tvoid *buf;\n> +\n> +\tif (efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, sz, &buf) != EFI_SUCCESS)\n> +\t\treturn NULL;\n> +\n> +\treturn buf;\n> +}\n> +\n> +/*\n> + * Iterate to next block in device-path, terminating (returning NULL)\n> + * at /End* node.\n> + */\n> +struct efi_device_path *efi_dp_next(const struct efi_device_path *dp)\n> +{\n> +\tif (dp == NULL)\n> +\t\treturn NULL;\n> +\tif (dp->type == DEVICE_PATH_TYPE_END)\n> +\t\treturn NULL;\n> +\tdp = ((void *)dp) + dp->length;\n> +\tif (dp->type == DEVICE_PATH_TYPE_END)\n> +\t\treturn NULL;\n> +\treturn (struct efi_device_path *)dp;\n> +}\n> +\n> +/*\n> + * Compare two device-paths, stopping when the shorter of the two hits\n> + * an End* node.  This is useful to, for example, compare a device-path\n> + * representing a device with one representing a file on the device, or\n> + * a device with a parent device.\n> + */\n> +int efi_dp_match(struct efi_device_path *a, struct efi_device_path *b)\n> +{\n> +\twhile (1) {\n> +\t\tint ret;\n> +\n> +\t\tret = memcmp(&a->length, &b->length, sizeof(a->length));\n> +\t\tif (ret)\n> +\t\t\treturn ret;\n> +\n> +\t\tret = memcmp(a, b, a->length);\n> +\t\tif (ret)\n> +\t\t\treturn ret;\n> +\n> +\t\ta = efi_dp_next(a);\n> +\t\tb = efi_dp_next(b);\n> +\n> +\t\tif (!a || !b)\n> +\t\t\treturn 0;\n> +\t}\n> +}\n> +\n> +\n> +/*\n> + * See UEFI spec (section 3.1.2, about short-form device-paths..\n> + * tl;dr: we can have a device-path that starts with a USB WWID\n> + * or USB Class node, and a few other cases which don't encode\n> + * the full device path with bus hierarchy:\n> + *\n> + *   - MESSAGING:USB_WWID\n> + *   - MESSAGING:USB_CLASS\n> + *   - MEDIA:FILE_PATH\n> + *   - MEDIA:HARD_DRIVE\n> + *   - MESSAGING:URI\n> + */\n> +static struct efi_device_path *shorten_path(struct efi_device_path *dp)\n> +{\n> +\twhile (dp) {\n> +\t\t/*\n> +\t\t * TODO: Add MESSAGING:USB_WWID and MESSAGING:URI..\n> +\t\t * in practice fallback.efi just uses MEDIA:HARD_DRIVE\n> +\t\t * so not sure when we would see these other cases.\n> +\t\t */\n> +\t\tif (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_CLASS) ||\n> +\t\t    EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) ||\n> +\t\t    EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH))\n> +\t\t\treturn dp;\n> +\n> +\t\tdp = efi_dp_next(dp);\n> +\t}\n> +\n> +\treturn dp;\n> +}\n> +\n> +static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path,\n> +\t\t\t\t   struct efi_device_path **rem)\n> +{\n> +\tstruct efi_object *efiobj;\n> +\n> +\tlist_for_each_entry(efiobj, &efi_obj_list, link) {\n> +\t\tint i;\n> +\n> +\t\tfor (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {\n> +\t\t\tstruct efi_handler *handler = &efiobj->protocols[i];\n> +\t\t\tstruct efi_device_path *obj_dp;\n> +\n> +\t\t\tif (!handler->guid)\n> +\t\t\t\tbreak;\n> +\n> +\t\t\tif (guidcmp(handler->guid, &efi_guid_device_path))\n> +\t\t\t\tcontinue;\n> +\n> +\t\t\tobj_dp = handler->protocol_interface;\n> +\n> +\t\t\tdo {\n> +\t\t\t\tif (efi_dp_match(dp, obj_dp) == 0) {\n> +\t\t\t\t\tif (rem) {\n> +\t\t\t\t\t\t*rem = ((void *)dp) +\n> +\t\t\t\t\t\t\tefi_dp_size(obj_dp);\n> +\t\t\t\t\t}\n> +\t\t\t\t\treturn efiobj;\n> +\t\t\t\t}\n> +\n> +\t\t\t\tobj_dp = shorten_path(efi_dp_next(obj_dp));\n> +\t\t\t} while (short_path && obj_dp);\n> +\t\t}\n> +\t}\n\nTo which part of the UEFI spec does this logic relate?\nI would like to see a comment in the coding.\n\nAs this has to be refactored when moving to a linked list for protocols\na unit test (e.g. in lib/efi_selftest/) would be very helpful.\n\nBest regards\n\nHeinrich\n\n\n> +\n> +\treturn NULL;\n> +}\n> +\n> +\n> +/*\n> + * Find an efiobj from device-path, if 'rem' is not NULL, returns the\n> + * remaining part of the device path after the matched object.\n> + */\n> +struct efi_object *efi_dp_find_obj(struct efi_device_path *dp,\n> +\t\t\t\t   struct efi_device_path **rem)\n> +{\n> +\tstruct efi_object *efiobj;\n> +\n> +\tefiobj = find_obj(dp, false, rem);\n> +\n> +\tif (!efiobj)\n> +\t\tefiobj = find_obj(dp, true, rem);\n> +\n> +\treturn efiobj;\n> +}\n> +\n> +/* return size not including End node: */\n> +unsigned efi_dp_size(const struct efi_device_path *dp)\n> +{\n> +\tunsigned sz = 0;\n> +\n> +\twhile (dp) {\n> +\t\tsz += dp->length;\n> +\t\tdp = efi_dp_next(dp);\n> +\t}\n> +\n> +\treturn sz;\n> +}\n> +\n> +struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp)\n> +{\n> +\tstruct efi_device_path *ndp;\n> +\tunsigned sz = efi_dp_size(dp) + sizeof(END);\n> +\n> +\tif (!dp)\n> +\t\treturn NULL;\n> +\n> +\tndp = dp_alloc(sz);\n> +\tmemcpy(ndp, dp, sz);\n> +\n> +\treturn ndp;\n> +}\n> +\n> +struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,\n> +\t\t\t\t      const struct efi_device_path *dp2)\n> +{\n> +\tstruct efi_device_path *ret;\n> +\n> +\tif (!dp1) {\n> +\t\tret = efi_dp_dup(dp2);\n> +\t} else if (!dp2) {\n> +\t\tret = efi_dp_dup(dp1);\n> +\t} else {\n> +\t\t/* both dp1 and dp2 are non-null */\n> +\t\tunsigned sz1 = efi_dp_size(dp1);\n> +\t\tunsigned sz2 = efi_dp_size(dp2);\n> +\t\tvoid *p = dp_alloc(sz1 + sz2 + sizeof(END));\n> +\t\tmemcpy(p, dp1, sz1);\n> +\t\tmemcpy(p + sz1, dp2, sz2);\n> +\t\tmemcpy(p + sz1 + sz2, &END, sizeof(END));\n> +\t\tret = p;\n> +\t}\n> +\n> +\treturn ret;\n> +}\n> +\n> +struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,\n> +\t\t\t\t\t   const struct efi_device_path *node)\n> +{\n> +\tstruct efi_device_path *ret;\n> +\n> +\tif (!node && !dp) {\n> +\t\tret = efi_dp_dup(&END);\n> +\t} else if (!node) {\n> +\t\tret = efi_dp_dup(dp);\n> +\t} else if (!dp) {\n> +\t\tunsigned sz = node->length;\n> +\t\tvoid *p = dp_alloc(sz + sizeof(END));\n> +\t\tmemcpy(p, node, sz);\n> +\t\tmemcpy(p + sz, &END, sizeof(END));\n> +\t\tret = p;\n> +\t} else {\n> +\t\t/* both dp and node are non-null */\n> +\t\tunsigned sz = efi_dp_size(dp);\n> +\t\tvoid *p = dp_alloc(sz + node->length + sizeof(END));\n> +\t\tmemcpy(p, dp, sz);\n> +\t\tmemcpy(p + sz, node, node->length);\n> +\t\tmemcpy(p + sz + node->length, &END, sizeof(END));\n> +\t\tret = p;\n> +\t}\n> +\n> +\treturn ret;\n> +}\n> +\n> +#ifdef CONFIG_DM\n> +/* size of device-path not including END node for device and all parents\n> + * up to the root device.\n> + */\n> +static unsigned dp_size(struct udevice *dev)\n> +{\n> +\tif (!dev || !dev->driver)\n> +\t\treturn sizeof(ROOT);\n> +\n> +\tswitch (dev->driver->id) {\n> +\tcase UCLASS_ROOT:\n> +\tcase UCLASS_SIMPLE_BUS:\n> +\t\t/* stop traversing parents at this point: */\n> +\t\treturn sizeof(ROOT);\n> +\tcase UCLASS_MMC:\n> +\t\treturn dp_size(dev->parent) +\n> +\t\t\tsizeof(struct efi_device_path_sd_mmc_path);\n> +\tcase UCLASS_MASS_STORAGE:\n> +\tcase UCLASS_USB_HUB:\n> +\t\treturn dp_size(dev->parent) +\n> +\t\t\tsizeof(struct efi_device_path_usb_class);\n> +\tdefault:\n> +\t\t/* just skip over unknown classes: */\n> +\t\treturn dp_size(dev->parent);\n> +\t}\n> +}\n> +\n> +static void *dp_fill(void *buf, struct udevice *dev)\n> +{\n> +\tif (!dev || !dev->driver)\n> +\t\treturn buf;\n> +\n> +\tswitch (dev->driver->id) {\n> +\tcase UCLASS_ROOT:\n> +\tcase UCLASS_SIMPLE_BUS: {\n> +\t\t/* stop traversing parents at this point: */\n> +\t\tstruct efi_device_path_vendor *vdp = buf;\n> +\t\t*vdp = ROOT;\n> +\t\treturn &vdp[1];\n> +\t}\n> +#if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)\n> +\tcase UCLASS_MMC: {\n> +\t\tstruct efi_device_path_sd_mmc_path *sddp =\n> +\t\t\tdp_fill(buf, dev->parent);\n> +\t\tstruct mmc *mmc = mmc_get_mmc_dev(dev);\n> +\t\tstruct blk_desc *desc = mmc_get_blk_desc(mmc);\n> +\n> +\t\tsddp->dp.type     = DEVICE_PATH_TYPE_MESSAGING_DEVICE;\n> +\t\tsddp->dp.sub_type = (desc->if_type == IF_TYPE_MMC) ?\n> +\t\t\tDEVICE_PATH_SUB_TYPE_MSG_MMC :\n> +\t\t\tDEVICE_PATH_SUB_TYPE_MSG_SD;\n> +\t\tsddp->dp.length   = sizeof(*sddp);\n> +\t\tsddp->slot_number = dev->seq;\n> +\n> +\t\treturn &sddp[1];\n> +\t}\n> +#endif\n> +\tcase UCLASS_MASS_STORAGE:\n> +\tcase UCLASS_USB_HUB: {\n> +\t\tstruct efi_device_path_usb_class *udp =\n> +\t\t\tdp_fill(buf, dev->parent);\n> +\t\tstruct usb_device *udev = dev_get_parent_priv(dev);\n> +\t\tstruct usb_device_descriptor *desc = &udev->descriptor;\n> +\n> +\t\tudp->dp.type     = DEVICE_PATH_TYPE_MESSAGING_DEVICE;\n> +\t\tudp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS;\n> +\t\tudp->dp.length   = sizeof(*udp);\n> +\t\tudp->vendor_id   = desc->idVendor;\n> +\t\tudp->product_id  = desc->idProduct;\n> +\t\tudp->device_class    = desc->bDeviceClass;\n> +\t\tudp->device_subclass = desc->bDeviceSubClass;\n> +\t\tudp->device_protocol = desc->bDeviceProtocol;\n> +\n> +\t\treturn &udp[1];\n> +\t}\n> +\tdefault:\n> +\t\tdebug(\"unhandled device class: %s (%u)\\n\",\n> +\t\t      dev->name, dev->driver->id);\n> +\t\treturn dp_fill(buf, dev->parent);\n> +\t}\n> +}\n> +\n> +/* Construct a device-path from a device: */\n> +struct efi_device_path *efi_dp_from_dev(struct udevice *dev)\n> +{\n> +\tvoid *buf, *start;\n> +\n> +\tstart = buf = dp_alloc(dp_size(dev) + sizeof(END));\n> +\tbuf = dp_fill(buf, dev);\n> +\t*((struct efi_device_path *)buf) = END;\n> +\n> +\treturn start;\n> +}\n> +#endif\n> +\n> +static unsigned dp_part_size(struct blk_desc *desc, int part)\n> +{\n> +\tunsigned dpsize;\n> +\n> +#ifdef CONFIG_BLK\n> +\tdpsize = dp_size(desc->bdev->parent);\n> +#else\n> +\tdpsize = sizeof(ROOT) + sizeof(struct efi_device_path_usb);\n> +#endif\n> +\n> +\tif (part == 0) /* the actual disk, not a partition */\n> +\t\treturn dpsize;\n> +\n> +\tif (desc->part_type == PART_TYPE_ISO)\n> +\t\tdpsize += sizeof(struct efi_device_path_cdrom_path);\n> +\telse\n> +\t\tdpsize += sizeof(struct efi_device_path_hard_drive_path);\n> +\n> +\treturn dpsize;\n> +}\n> +\n> +static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)\n> +{\n> +\tdisk_partition_t info;\n> +\n> +#ifdef CONFIG_BLK\n> +\tbuf = dp_fill(buf, desc->bdev->parent);\n> +#else\n> +\t/*\n> +\t * We *could* make a more accurate path, by looking at if_type\n> +\t * and handling all the different cases like we do for non-\n> +\t * legacy (ie CONFIG_BLK=y) case.  But most important thing\n> +\t * is just to have a unique device-path for if_type+devnum.\n> +\t * So map things to a fictional USB device:\n> +\t */\n> +\tstruct efi_device_path_usb *udp;\n> +\n> +\tmemcpy(buf, &ROOT, sizeof(ROOT));\n> +\tbuf += sizeof(ROOT);\n> +\n> +\tudp = buf;\n> +\tudp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;\n> +\tudp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB;\n> +\tudp->dp.length = sizeof(*udp);\n> +\tudp->parent_port_number = desc->if_type;\n> +\tudp->usb_interface = desc->devnum;\n> +\tbuf = &udp[1];\n> +#endif\n> +\n> +\tif (part == 0) /* the actual disk, not a partition */\n> +\t\treturn buf;\n> +\n> +\tpart_get_info(desc, part, &info);\n> +\n> +\tif (desc->part_type == PART_TYPE_ISO) {\n> +\t\tstruct efi_device_path_cdrom_path *cddp = buf;\n> +\n> +\t\tcddp->boot_entry = part - 1;\n> +\t\tcddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;\n> +\t\tcddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_CDROM_PATH;\n> +\t\tcddp->dp.length = sizeof(*cddp);\n> +\t\tcddp->partition_start = info.start;\n> +\t\tcddp->partition_end = info.size;\n> +\n> +\t\tbuf = &cddp[1];\n> +\t} else {\n> +\t\tstruct efi_device_path_hard_drive_path *hddp = buf;\n> +\n> +\t\thddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;\n> +\t\thddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH;\n> +\t\thddp->dp.length = sizeof(*hddp);\n> +\t\thddp->partition_number = part - 1;\n> +\t\thddp->partition_start = info.start;\n> +\t\thddp->partition_end = info.size;\n> +\t\tif (desc->part_type == PART_TYPE_EFI)\n> +\t\t\thddp->partmap_type = 2;\n> +\t\telse\n> +\t\t\thddp->partmap_type = 1;\n> +\t\thddp->signature_type = desc->sig_type;\n> +\t\tif (hddp->signature_type != 0)\n> +\t\t\tmemcpy(hddp->partition_signature, &desc->guid_sig,\n> +\t\t\t       sizeof(hddp->partition_signature));\n> +\n> +\t\tbuf = &hddp[1];\n> +\t}\n> +\n> +\treturn buf;\n> +}\n> +\n> +\n> +/* Construct a device-path from a partition on a blk device: */\n> +struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part)\n> +{\n> +\tvoid *buf, *start;\n> +\n> +\tstart = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END));\n> +\n> +\tbuf = dp_part_fill(buf, desc, part);\n> +\n> +\t*((struct efi_device_path *)buf) = END;\n> +\n> +\treturn start;\n> +}\n> +\n> +/* convert path to an UEFI style path (ie. DOS style backslashes and utf16) */\n> +static void path_to_uefi(u16 *uefi, const char *path)\n> +{\n> +\twhile (*path) {\n> +\t\tchar c = *(path++);\n> +\t\tif (c == '/')\n> +\t\t\tc = '\\\\';\n> +\t\t*(uefi++) = c;\n> +\t}\n> +\t*uefi = '\\0';\n> +}\n> +\n> +/*\n> + * If desc is NULL, this creates a path with only the file component,\n> + * otherwise it creates a full path with both device and file components\n> + */\n> +struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,\n> +\t\tconst char *path)\n> +{\n> +\tstruct efi_device_path_file_path *fp;\n> +\tvoid *buf, *start;\n> +\tunsigned dpsize = 0, fpsize;\n> +\n> +\tif (desc)\n> +\t\tdpsize = dp_part_size(desc, part);\n> +\n> +\tfpsize = sizeof(struct efi_device_path) + 2 * (strlen(path) + 1);\n> +\tdpsize += fpsize;\n> +\n> +\tstart = buf = dp_alloc(dpsize + sizeof(END));\n> +\n> +\tif (desc)\n> +\t\tbuf = dp_part_fill(buf, desc, part);\n> +\n> +\t/* add file-path: */\n> +\tfp = buf;\n> +\tfp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;\n> +\tfp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;\n> +\tfp->dp.length = fpsize;\n> +\tpath_to_uefi(fp->str, path);\n> +\tbuf += fpsize;\n> +\n> +\t*((struct efi_device_path *)buf) = END;\n> +\n> +\treturn start;\n> +}\n> +\n> +#ifdef CONFIG_NET\n> +struct efi_device_path *efi_dp_from_eth(void)\n> +{\n> +\tstruct efi_device_path_mac_addr *ndp;\n> +\tvoid *buf, *start;\n> +\tunsigned dpsize = 0;\n> +\n> +\tassert(eth_get_dev());\n> +\n> +#ifdef CONFIG_DM_ETH\n> +\tdpsize += dp_size(eth_get_dev());\n> +#else\n> +\tdpsize += sizeof(ROOT);\n> +#endif\n> +\tdpsize += sizeof(*ndp);\n> +\n> +\tstart = buf = dp_alloc(dpsize + sizeof(END));\n> +\n> +#ifdef CONFIG_DM_ETH\n> +\tbuf = dp_fill(buf, eth_get_dev());\n> +#else\n> +\tmemcpy(buf, &ROOT, sizeof(ROOT));\n> +\tbuf += sizeof(ROOT);\n> +#endif\n> +\n> +\tndp = buf;\n> +\tndp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;\n> +\tndp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;\n> +\tndp->dp.length = sizeof(*ndp);\n> +\tmemcpy(ndp->mac.addr, eth_get_ethaddr(), ARP_HLEN);\n> +\tbuf = &ndp[1];\n> +\n> +\t*((struct efi_device_path *)buf) = END;\n> +\n> +\treturn start;\n> +}\n> +#endif\n> +\n> +/*\n> + * Helper to split a full device path (containing both device and file\n> + * parts) into it's constituent parts.\n> + */\n> +void efi_dp_split_file_path(struct efi_device_path *full_path,\n> +\t\t\t    struct efi_device_path **device_path,\n> +\t\t\t    struct efi_device_path **file_path)\n> +{\n> +\tstruct efi_device_path *p, *dp, *fp;\n> +\n> +\tdp = efi_dp_dup(full_path);\n> +\tp = dp;\n> +\twhile (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH))\n> +\t\tp = efi_dp_next(p);\n> +\tfp = efi_dp_dup(p);\n> +\n> +\tp->type = DEVICE_PATH_TYPE_END;\n> +\tp->sub_type = DEVICE_PATH_SUB_TYPE_END;\n> +\tp->length = sizeof(*p);\n> +\n> +\t*device_path = dp;\n> +\t*file_path = fp;\n> +}\n>","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3yPQLy4hCkz9sNV\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun, 29 Oct 2017 02:55:37 +1100 (AEDT)","by lists.denx.de (Postfix, from userid 105)\n\tid 101F2C21D95; Sat, 28 Oct 2017 15:55:35 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 9B137C21C45;\n\tSat, 28 Oct 2017 15:55:28 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 2A87CC21C45; Sat, 28 Oct 2017 15:55:28 +0000 (UTC)","from mout.gmx.net (mout.gmx.net [212.227.15.15])\n\tby lists.denx.de (Postfix) with ESMTPS id AE3D4C21C41\n\tfor <u-boot@lists.denx.de>; Sat, 28 Oct 2017 15:55:27 +0000 (UTC)","from [192.168.123.53] ([94.114.42.150]) by mail.gmx.com (mrgmx001\n\t[212.227.17.190]) with ESMTPSA (Nemesis) id\n\t0Mey7N-1dp1qN3lBB-00OWih; Sat, 28 Oct 2017 17:54:27 +0200"],"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=FREEMAIL_FROM,\n\tRCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no\n\tversion=3.4.0","To":"Rob Clark <robdclark@gmail.com>, Alexander Graf <agraf@suse.de>","References":"<20170913220546.19560-1-robdclark@gmail.com>\n\t<20170913220546.19560-6-robdclark@gmail.com>","From":"Heinrich Schuchardt <xypron.glpk@gmx.de>","Message-ID":"<87a592b0-c8f8-b2b0-f96a-7110d5b41aee@gmx.de>","Date":"Sat, 28 Oct 2017 17:53:47 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170913220546.19560-6-robdclark@gmail.com>","Content-Language":"en-US","X-Provags-ID":"V03:K0:l0LPuPL2tIg22Kci/RVlyzplUy12EYLkZJJcRJFplySpyol3AV1\n\tLJ4Gv897A6vKudB7BvQF/A4jTL9mjWajlHi0FnUJv6a3L8adP4Os1wQiCzg8EN+c89OG1wo\n\t2UIxiAVScE/gUnsu2MkfwQTcjVH2EzSuNBw6+MjQZFKtO9eglbEA09td0PfHIO6i+wijBHY\n\t/UP24Fzk02CwkjyZQP7/A==","X-UI-Out-Filterresults":"notjunk:1; V01:K0:C+Xbsq2dopU=:NP7y4D2TplTIYmSLUDnKdo\n\tT4An0GKkKBM4YU0NlJJZ2u+ljJsMqNvIdyaEODd6UtopUSEXSRF9h/bQ576XAglCC3laxdH/J\n\tcl/J0NBEpGUr7F+YoWaZyl3mhNIReCCTCaK+E+1dJ9ZcA97YcMzIj9tVDXE2TV0y/pYOn/stp\n\tOahyIh/wx1igthP8o6OPy1+h6UcpvIamh0syvDqOupBRipiUSeIbny1rYr0uZTBMFTsGGIkLN\n\tCR4HLujKWahyQHy4K3n8ZBtT/pbaVBaW1qfdNNvzXjWETAP70ec8+4qvAImxIFWwk8e3VN99o\n\tMSqIyIX2YIdvMVmOlij7tSNB2Ieo0jIEk330Zt3QTwpmpPtl++rXZxFUJ8OzhIxnxsh+6m6M9\n\tFzi56Q7yCSttD2G10E1gJgGYjQJ5jHa9j/tur5gA2SfN98zwqhsj1kEEZSmKV6z42EQG2Kast\n\tFoz8Czjp2Wh9YoC6cjvPcSj3KzKX0z5TTSVlfcO9laQKsT1CAGViCCHSKM18u2B0Mv+OHO/Ow\n\tfnQVUvZveqzoohg9gNLLgcmVHlD3MSlPwEC61tpH/sTqvVwz6GnhMHY50+lo6vVPV65EkhHMX\n\tvR4DFhkQtwWI2niMxsgAiSSwMOUV1huDVtzCoX78ItHxQQtq3V5vaIF41kAJ/HUKmwbEWPkGo\n\tWc6w3ZrhLnZPjFeK/v7AElay6CHIippY8J6ey+41HAR5eqHbhXloomVcCxBAOI2xQlSqurPni\n\txPF8KXSgqVyt6HfaGnWA53+cSHt2TYsokVjPzGywfvbkAVxQxrSFxY/eUYM1KcSA17hvAltGm\n\tAJyxX0nWcRq+ft/Vlzf9bpGyUBZY6g5PnpgYkIPsbeXT0XIzzQ=","Cc":"U-Boot Mailing List <u-boot@lists.denx.de>,\n\tPeter Jones <pjones@redhat.com>","Subject":"Re: [U-Boot] [PATCH v3 05/21] efi_loader: add device-path utils","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}}]