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 1A0A9EB64DC for ; Tue, 11 Jul 2023 04:52:06 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C5F2E861AC; Tue, 11 Jul 2023 06:52:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=siemens.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=siemens.com header.i=@siemens.com header.b="yBXzrxKP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B70E886205; Tue, 11 Jul 2023 06:52:03 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on20626.outbound.protection.outlook.com [IPv6:2a01:111:f400:7d00::626]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AFB8685FE2 for ; Tue, 11 Jul 2023 06:51:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=siemens.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jan.kiszka@siemens.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bm2i+W7hHAaW+FleIjMkiX+SozgxIedG7O8oKzPnEpCV9iW04d22MRp1Uo2tDazu5mGy0dv0Jhler5oCg/ZsqUXOD6SPJ0ARw8iUHxZWpN32eSAzhddvvBIrFENSaSnAQvGSeyEWMAqD+uj7zoeZEge8jMBXpJmrqss3M/4oSJG8BYzm7+jZZccr1UXYMDYX3u4m8BUDGPWG/8TuYLYtC61Y1zKg/VPwfFUF+u82/yOTszQoHH8SQIj5oyQH1XoKyoNiUugWTo54CtJp4aZxaXQpWVa6UHgJljNhkXc1j7UpUhiKoUDpvrdnFw+qN1TVdLviYXivb1dQ5pCX6IOSKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QCVfA2Nx5vqhcb8X98Q3VYD1XWVxDMR/HoFURbutSUU=; b=oKB+8cp4xhR0tGwJ/rNV6PQ6JCcR8k0cNkhSComxaelrHhk7NlaMRFWiRPb8TP/HpSE/DABx3YpjkeT4+mSxQK8c7DWTVOl+K+xwKB58QKrGc48j/17NQ0bCWWG87Qwx3vnNRgORKe6Y+4NSxQABTLXRtknsBntqH//Q48imy4ZyQfcOTTXuj2OTgyrJbf9Ntha3Ju3wtgwSPPa52bgxc8sIItNWJ0nuAy8jgWf9+XBtdst43QIkELK30G96Io2fzaQQfKWGYJIpEeqFJ1w1uc1zMrp+kNjwmnzOaYeHRAConw6LGohN6M1WAyLvfhonxQAgu7DBS1+ec/IwtByhJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=siemens.com; dmarc=pass action=none header.from=siemens.com; dkim=pass header.d=siemens.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=siemens.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QCVfA2Nx5vqhcb8X98Q3VYD1XWVxDMR/HoFURbutSUU=; b=yBXzrxKPM3GULlqtXHDmVmrbI8taJ5I9ejJFPOZJ04keuKE045uc8ly6P3t63Bgg3V6gbxKSWYkWpouZXwWyFfFBWyK37mYh7vPhl4jjN6lLwh4Eudpc/PPewy+jEOjJked/orP2I9K3dYncca9nRtCYQIZ8craCPohGPQMHQzmG1XSQSNvFbER1p8oLDls8U+yfEYPUdW805k3zVZFlbto+jk6rh5MdG2uFZRQcRCI0Pnj4U8ykKUjrdXiSi4OQ5brwA2xWA6qLNMi5/nKIgRvMMwXRL7/Ue9SzjTMTNUtkZsef0NCq812ellz+FQaeJkkHJa1RsCXzcTTL4wSEHQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=siemens.com; Received: from AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:588::19) by PAWPR10MB7174.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:102:2ed::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.30; Tue, 11 Jul 2023 04:51:58 +0000 Received: from AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM ([fe80::f964:e0e9:199:9246]) by AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM ([fe80::f964:e0e9:199:9246%6]) with mapi id 15.20.6565.028; Tue, 11 Jul 2023 04:51:57 +0000 Message-ID: Date: Tue, 11 Jul 2023 06:51:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v5 01/23] binman: ti-board-config: Add support for TI board config binaries Content-Language: en-US To: Neha Malcom Francis , u-boot@lists.denx.de, trini@konsulko.com, sjg@chromium.org, afd@ti.com, vigneshr@ti.com, rogerq@kernel.org, kamlesh@ti.com, bb@ti.com, alpernebiyasak@gmail.com Cc: nm@ti.com, u-kumar1@ti.com, m-chawdhry@ti.com, christian.gmeiner@gmail.com, xypron.glpk@gmx.de References: <20230707123450.30329-1-n-francis@ti.com> <20230707123450.30329-2-n-francis@ti.com> From: Jan Kiszka In-Reply-To: <20230707123450.30329-2-n-francis@ti.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR3P281CA0104.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::20) To AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:588::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS4PR10MB6181:EE_|PAWPR10MB7174:EE_ X-MS-Office365-Filtering-Correlation-Id: 81d0d37e-6c9c-4e26-e9b1-08db81ca8e4b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gIcEkXrwGq4NjLJxsoF7IPVTwMfURf+sTOlGWtl/lKzqS976BQ/uPj7J2FnexGEM7FXCcuJsjbOkt6+2eSRxe3rj2um32DXeLwQSsB5B6hml14UfH9sAkj2nhPHW+pBkfX5qLUL7OTlKqJZk27kEWab91yc9mCoBAaaNuT+T1lYRLyuQoZSLtjTS897KBecWrLzcv9fwvlxiaAoK83X0BZcaAlCAR7p1fQ/JoaocYrvuoAXfNT4inR8uH2FVpELzaLNW0kdqetzgVLH7a1X/a96NePhwxWC3JOozS7gr5ZrFsBI8utkDJWnQ7hvNfpPJ1n9jVwlz7XPqy8ablHXDutx6HifWnhlZKEsYb7PVZshN/g2tsnuebH+0TEsgFOWvkjWmrJ9Q+v3kN0LUx7kErdg8aTghDMWntbvn81t65Zz/A1NuDy+L6xLXqr3dA5XEjk2DWDEsmpU7DaAb/3BvRacr3d7HJIKM8N6P/6IBtDS5e793eNCjemG6dhYn8rm88Cs0JZ502M6OKUwRGp9WTJNeCve0/tdZCNp/08okRuBbvEWtaNrm6lSDEKkBolffAXL8cHl9j8GiXDWb9FuGgGYiqkiZY65/QxfLCUEXJ+jV6Q3uX0qBprUK7IN1CfsmvuRwQQMJ2sMred7vSnJONFGghJUnyc36t76nRl6sLX8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230028)(4636009)(366004)(136003)(396003)(346002)(376002)(39860400002)(451199021)(86362001)(38100700002)(82960400001)(31696002)(31686004)(36756003)(6666004)(6486002)(921005)(478600001)(26005)(186003)(6506007)(2616005)(966005)(6512007)(53546011)(44832011)(7416002)(316002)(2906002)(66556008)(5660300002)(66946007)(66476007)(8936002)(8676002)(83380400001)(4326008)(30864003)(41300700001)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VjBhcE9Rb2s2dURhY0lRWlhoTlhuVU12Q3JSbURDN3ZoakU0VDl2NEJMMHRR?= =?utf-8?B?eEZ3SmJvekFxeUZUcVM3MHg1ZjlmOVZ5eTU2MnplTEhzWlpTTlpKTU5tcVdV?= =?utf-8?B?cnFkSnRtRkR0SSsvUDg2MjJBYUZ3RXFrYlp0dlMvTnlzRUpjU0dubldPOHhi?= =?utf-8?B?S250dzZ6NGlPWDg1U3RoY3FSWXArNW5CV1ZVNGxRTHZqYmlvcTVQS1pNNnEx?= =?utf-8?B?d2hNNmowMU9IU2N3Vjkza0RBRm5zTjdYQnE4bnM1aUdvUW1KOGFLZUhyZlBx?= =?utf-8?B?bVkyWk4rUmlDY1lmSm14ZnFqSWFlcEN3Sm9FdER6SC9JZVpIYlBOWFlaU2s3?= =?utf-8?B?K1RGVVhHR1U1VkhYZHdnaFQzbjBjWXhObVI2OHprVTE4NDR2N1pQSUJDQ0xL?= =?utf-8?B?YzBTcUQ3b3RIeFNibjRHbmVNSnRFNG9Oa052NG9WckxkOVNSQWtHd1NaSUtT?= =?utf-8?B?OGZtcVdVZ0dTZHh5bE51RVdVREpscUx4Uml3Yk5aeTF3NFZ4bnFvZzZxWlFK?= =?utf-8?B?bFFhcEpBT0oyZHl0eDdMZUNlOUd0YjBma1IrR1RacUJlcm0rYVJZVDZNTUl3?= =?utf-8?B?TStRQXlGZE5CY05WNkN4L0xGT0N6U0hXTGlCV0pNeFpqVDBDdkh0U1JJY291?= =?utf-8?B?K01EK1cyWUVIMk9EeGlhWENDeU5Jc2s0b0xEb2pUQ2JLZ3ROS0xISS9HODlU?= =?utf-8?B?UDJqclc1VENGOTFZY004UUpxTXRobGNLMVpkTmF5eWdWaDMydmU5dmZlU1Js?= =?utf-8?B?MVRFYUJORVZrZk1NcHpLV3YzbzF1TTVnQ2lhOHFYQmhrVXBFT05uSXJGaFZL?= =?utf-8?B?TytRdXBPNVlHSUdhanExNXR1YjdRaExpRno2dUxnTEsyV0l4blgyZm13Sncz?= =?utf-8?B?RjdocjZiSUw4YVNJWW5YSzBER1dqajNZdU01TS9Xc1pxNUc2ZGlLSllTbEhU?= =?utf-8?B?eEgvT0dVaFZiQWtXenM2ZGR0MUd3Wm5ITlZqdEtQQk8wL2R2Z0NsZEhwRTlH?= =?utf-8?B?M0Y3UjczTHNXaCtSUW12dDJlMDBkenN1SFhaamxuakg4cGhVR1h0bDR1c1cy?= =?utf-8?B?TnprT1FGeTRDYnM1UmowRkFvaHN4Z1dDMWFGZWR4QXdCMkEvVDhuWW5rVTl6?= =?utf-8?B?Vm5RdDJBNVVDTHNMd0hOUFV2V05FczgyS2IyVDZVV3IySTBqOG02RHFyZDEw?= =?utf-8?B?d1dTaEZETFJKc1BVbHM1VUszelR1V05TY3FEcTliUDg0QTJHeFJUK1hId1pT?= =?utf-8?B?OExWYmdrbitCZWwxU0R3bUxOTzEwSHNiOEdXS28vZm9ZUlZlclYram5DQjRD?= =?utf-8?B?WjdZdW9md0dhR3hlLzBsSHloR0w1N0ZrQ2dDcC9hRjlsbWpMOHI2eFd6NHRs?= =?utf-8?B?YjlidHkrR3d3RUdZRzcrMmtUc1Jlc21ZWTBSU0ZDYm04RHhLR1BmTjN1QTJw?= =?utf-8?B?Q21MTmUzOXJYL1RrYnkyTTNDMmh1RDNVOTE5ZmtXbFNhWWNpZjQrN2gzMFVX?= =?utf-8?B?bTM1aFZpYytvWFBqSUVYbEY5RWRDUXZNUWNBb0ZTcG54Z21qcHZVOVhQVmZW?= =?utf-8?B?a1hqcGU3WkpWdjJrZWtJY1MydFpZK0xUMjltU21jZFA1TUNqY3JZMEFVS3h2?= =?utf-8?B?a2haaDZHU2c0aHNScTZETzE4QWtIbE81aWh3dXFxMEx3Wjl5cEFqaUIrdGx2?= =?utf-8?B?NHRNdi9VNXVmUnhnbW1FSFpQelhGSzVKbjhQRHNoWFdSeVpFT3VLVEdmOEpv?= =?utf-8?B?SzZMR0x2Uk4zNUpMczdaM2tSL2lhME1xakRKeXYvQ0J3UW1zem1sTG1QZlIx?= =?utf-8?B?WFFPMklJR1BsRWVUSnlvMzZETWpkWTVhaFdKUndpT2xMcGNVcmZDTWVvWWQ4?= =?utf-8?B?YnhFS0QxZVBHL3RmaU1Wd1ltL1pOSXh6aFFtZ1dES3U4L3hJZXg5ZEVDZlVD?= =?utf-8?B?azJnU3hNaTdBQ0QxUVhUcWtHKzRsbnBuSkJwU3NhWGpqTUw5djdYZDhwLzda?= =?utf-8?B?SG5UY1V1bHpFcm5wYlE2TmVHQy9HTEZRaFlFdTlwLzB2WmYzSE1YWW1aUmxy?= =?utf-8?B?aTl3eUdFVDI5OFlBQ2RkYmFQV2tTNjZETWdmL2J0OTFrQ2lqWDRKaWl6Zk13?= =?utf-8?B?b2l2MU40bkJUV3I0UEpvWCthZW4yVnhUTzY2UnFxNE1FNFBrd0FxZ3dnSllj?= =?utf-8?B?RkE9PQ==?= X-OriginatorOrg: siemens.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81d0d37e-6c9c-4e26-e9b1-08db81ca8e4b X-MS-Exchange-CrossTenant-AuthSource: AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jul 2023 04:51:57.5047 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 38ae3bcd-9579-4fd4-adda-b42e1495d55a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jE8htsyuLQ+ldYhyhDsHjN34RJSM+irz5wsc2cxkq2/w18rM4CPQ5INhs00GJSnSvKR+J8srJTvY7u44QpIRTg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR10MB7174 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 On 07.07.23 14:34, Neha Malcom Francis wrote: > The ti-board-config entry loads and validates a given YAML config file > against a given schema, and generates the board config binary. K3 > devices require these binaries to be packed into the final system > firmware images. > > Signed-off-by: Neha Malcom Francis > Reviewed-by: Simon Glass > --- > tools/binman/entries.rst | 48 ++++ > tools/binman/etype/ti_board_config.py | 259 ++++++++++++++++++ > tools/binman/ftest.py | 20 ++ > tools/binman/test/277_ti_board_cfg.dts | 14 + > .../binman/test/278_ti_board_cfg_combined.dts | 25 ++ > .../binman/test/279_ti_board_cfg_no_type.dts | 11 + > tools/binman/test/yaml/config.yaml | 19 ++ > tools/binman/test/yaml/schema.yaml | 51 ++++ > tools/binman/test/yaml/schema_notype.yaml | 40 +++ > 9 files changed, 487 insertions(+) > create mode 100644 tools/binman/etype/ti_board_config.py > create mode 100644 tools/binman/test/277_ti_board_cfg.dts > create mode 100644 tools/binman/test/278_ti_board_cfg_combined.dts > create mode 100644 tools/binman/test/279_ti_board_cfg_no_type.dts > create mode 100644 tools/binman/test/yaml/config.yaml > create mode 100644 tools/binman/test/yaml/schema.yaml > create mode 100644 tools/binman/test/yaml/schema_notype.yaml > > diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst > index b71af801fd..14a2d03fad 100644 > --- a/tools/binman/entries.rst > +++ b/tools/binman/entries.rst > @@ -1658,6 +1658,54 @@ by setting the size of the entry to something larger than the text. > > > > +.. _etype_ti_board_config: > + > +Entry: ti-board-config: An entry containing a TI schema validated board config binary > +------------------------------------------------------------------------------------- > + > +This etype supports generation of two kinds of board configuration > +binaries: singular board config binary as well as combined board config > +binary. > + > +Properties / Entry arguments: > + - config-file: File containing board configuration data in YAML > + - schema-file: File containing board configuration YAML schema against > + which the config file is validated > + > +Output files: > + - board config binary: File containing board configuration binary > + > +These above parameters are used only when the generated binary is > +intended to be a single board configuration binary. Example:: > + > + my-ti-board-config { > + ti-board-config { > + config = "board-config.yaml"; > + schema = "schema.yaml"; > + }; > + }; > + > +To generate a combined board configuration binary, we pack the > +needed individual binaries into a ti-board-config binary. In this case, > +the available supported subnode names are board-cfg, pm-cfg, sec-cfg and > +rm-cfg. The final binary is prepended with a header containing details about > +the included board config binaries. Example:: > + > + my-combined-ti-board-config { > + ti-board-config { > + board-cfg { > + config = "board-cfg.yaml"; > + schema = "schema.yaml"; > + }; > + sec-cfg { > + config = "sec-cfg.yaml"; > + schema = "schema.yaml"; > + }; > + } > + } > + > + > + > .. _etype_u_boot: > > Entry: u-boot: U-Boot flat binary > diff --git a/tools/binman/etype/ti_board_config.py b/tools/binman/etype/ti_board_config.py > new file mode 100644 > index 0000000000..0799e5dc59 > --- /dev/null > +++ b/tools/binman/etype/ti_board_config.py > @@ -0,0 +1,259 @@ > +# SPDX-License-Identifier: GPL-2.0+ > +# Copyright (c) 2022 Texas Instruments Incorporated - https://www.ti.com/ > +# Written by Neha Malcom Francis > +# > +# Entry-type module for generating schema validated TI board > +# configuration binary > +# > + > +import os > +import struct > +import yaml > + > +from collections import OrderedDict > +from jsonschema import validate > +from shutil import copyfileobj > + > +from binman.entry import Entry > +from binman.etype.section import Entry_section > +from dtoc import fdt_util > +from u_boot_pylib import tools > + > +BOARDCFG = 0xB > +BOARDCFG_SEC = 0xD > +BOARDCFG_PM = 0xE > +BOARDCFG_RM = 0xC > +BOARDCFG_NUM_ELEMS = 4 > + > +class Entry_ti_board_config(Entry_section): > + """An entry containing a TI schema validated board config binary > + > + This etype supports generation of two kinds of board configuration > + binaries: singular board config binary as well as combined board config > + binary. > + > + Properties / Entry arguments: > + - config-file: File containing board configuration data in YAML > + - schema-file: File containing board configuration YAML schema against > + which the config file is validated > + > + Output files: > + - board config binary: File containing board configuration binary > + > + These above parameters are used only when the generated binary is > + intended to be a single board configuration binary. Example:: > + > + my-ti-board-config { > + ti-board-config { > + config = "board-config.yaml"; > + schema = "schema.yaml"; > + }; > + }; > + > + To generate a combined board configuration binary, we pack the > + needed individual binaries into a ti-board-config binary. In this case, > + the available supported subnode names are board-cfg, pm-cfg, sec-cfg and > + rm-cfg. The final binary is prepended with a header containing details about > + the included board config binaries. Example:: > + > + my-combined-ti-board-config { > + ti-board-config { > + board-cfg { > + config = "board-cfg.yaml"; > + schema = "schema.yaml"; > + }; > + sec-cfg { > + config = "sec-cfg.yaml"; > + schema = "schema.yaml"; > + }; > + } > + } > + """ > + def __init__(self, section, etype, node): > + super().__init__(section, etype, node) > + self._config = None > + self._schema = None > + self._entries = OrderedDict() > + self._num_elems = BOARDCFG_NUM_ELEMS > + self._fmt = ' + self._index = 0 > + self._binary_offset = 0 > + self._sw_rev = 1 > + self._devgrp = 0 > + > + def ReadNode(self): > + super().ReadNode() > + self._config = fdt_util.GetString(self._node, 'config') > + self._schema = fdt_util.GetString(self._node, 'schema') > + # Depending on whether config file is present in node, we determine > + # whether it is a combined board config binary or not > + if self._config is None: > + self.ReadEntries() > + else: > + self._config_file = tools.get_input_filename(self._config) > + self._schema_file = tools.get_input_filename(self._schema) > + > + def ReadEntries(self): > + """Read the subnodes to find out what should go in this image > + """ > + for node in self._node.subnodes: > + if 'type' not in node.props: > + entry = Entry.Create(self, node, 'ti-board-config') > + entry.ReadNode() > + cfg_data = entry.BuildSectionData(True) > + entry._cfg_data = cfg_data > + self._entries[entry.name] = entry > + self._num_elems = len(self._node.subnodes) > + > + def _convert_to_byte_chunk(self, val, data_type): > + """Convert value into byte array > + > + Args: > + val: value to convert into byte array > + data_type: data type used in schema, supported data types are u8, > + u16 and u32 > + > + Returns: > + array of bytes representing value > + """ > + size = 0 > + if (data_type == '#/definitions/u8'): > + size = 1 > + elif (data_type == '#/definitions/u16'): > + size = 2 > + else: > + size = 4 > + if type(val) == int: > + br = val.to_bytes(size, byteorder='little') > + return br > + > + def _compile_yaml(self, schema_yaml, file_yaml): > + """Convert YAML file into byte array based on YAML schema > + > + Args: > + schema_yaml: file containing YAML schema > + file_yaml: file containing config to compile > + > + Returns: > + array of bytes repesenting YAML file against YAML schema > + """ > + br = bytearray() > + for key, node in file_yaml.items(): > + node_schema = schema_yaml['properties'][key] > + node_type = node_schema.get('type') > + if not 'type' in node_schema: > + br += self._convert_to_byte_chunk(node, > + node_schema.get('$ref')) > + elif node_type == 'object': > + br += self._compile_yaml(node_schema, node) > + elif node_type == 'array': > + for item in node: > + if not isinstance(item, dict): > + br += self._convert_to_byte_chunk( > + item, schema_yaml['properties'][key]['items']['$ref']) > + else: > + br += self._compile_yaml(node_schema.get('items'), item) > + return br > + > + def _generate_binaries(self): > + """Generate config binary artifacts from the loaded YAML configuration file > + > + Returns: > + byte array containing config binary artifacts > + or None if generation fails > + """ > + cfg_binary = bytearray() > + for key, node in self.file_yaml.items(): > + node_schema = self.schema_yaml['properties'][key] > + br = self._compile_yaml(node_schema, node) > + cfg_binary += br > + return cfg_binary > + > + def _add_boardcfg(self, bcfgtype, bcfgdata): > + """Add board config to combined board config binary > + > + Args: > + bcfgtype (int): board config type > + bcfgdata (byte array): board config data > + """ > + size = len(bcfgdata) > + desc = struct.pack(self._fmt, bcfgtype, > + self._binary_offset, size, self._devgrp, 0) > + with open(self.descfile, 'ab+') as desc_fh: > + desc_fh.write(desc) > + with open(self.bcfgfile, 'ab+') as bcfg_fh: > + bcfg_fh.write(bcfgdata) > + self._binary_offset += size > + self._index += 1 > + > + def _finalize(self): > + """Generate final combined board config binary > + > + Returns: > + byte array containing combined board config data > + or None if unable to generate > + """ > + with open(self.descfile, 'rb') as desc_fh: > + with open(self.bcfgfile, 'rb') as bcfg_fh: > + with open(self.fh_file, 'ab+') as fh: > + copyfileobj(desc_fh, fh) > + copyfileobj(bcfg_fh, fh) > + data = tools.read_file(self.fh_file) > + return data > + > + def BuildSectionData(self, required): > + if self._config is None: > + self._binary_offset = 0 > + uniq = self.GetUniqueName() > + self.fh_file = tools.get_output_filename('fh.%s' % uniq) > + self.descfile = tools.get_output_filename('desc.%s' % uniq) > + self.bcfgfile = tools.get_output_filename('bcfg.%s' % uniq) > + > + # when binman runs again make sure we start clean > + if os.path.exists(self.fh_file): > + os.remove(self.fh_file) > + if os.path.exists(self.descfile): > + os.remove(self.descfile) > + if os.path.exists(self.bcfgfile): > + os.remove(self.bcfgfile) > + > + with open(self.fh_file, 'wb') as f: > + t_bytes = f.write(struct.pack( > + ' + self._binary_offset += t_bytes > + self._binary_offset += self._num_elems * struct.calcsize(self._fmt) > + > + if 'board-cfg' in self._entries: > + self._add_boardcfg(BOARDCFG, self._entries['board-cfg']._cfg_data) > + > + if 'sec-cfg' in self._entries: > + self._add_boardcfg(BOARDCFG_SEC, self._entries['sec-cfg']._cfg_data) > + > + if 'pm-cfg' in self._entries: > + self._add_boardcfg(BOARDCFG_PM, self._entries['pm-cfg']._cfg_data) > + > + if 'rm-cfg' in self._entries: > + self._add_boardcfg(BOARDCFG_RM, self._entries['rm-cfg']._cfg_data) > + > + data = self._finalize() > + return data > + > + else: > + with open(self._config_file, 'r') as f: > + self.file_yaml = yaml.safe_load(f) > + with open(self._schema_file, 'r') as sch: > + self.schema_yaml = yaml.safe_load(sch) > + > + try: > + validate(self.file_yaml, self.schema_yaml) > + except Exception as e: > + self.Raise(f"Schema validation error: {e}") > + > + data = self._generate_binaries() > + return data > + > + def SetImagePos(self, image_pos): > + Entry.SetImagePos(self, image_pos) > + > + def CheckEntries(self): > + Entry.CheckEntries(self) > diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py > index 43b4f850a6..b9a490a5bd 100644 > --- a/tools/binman/ftest.py > +++ b/tools/binman/ftest.py > @@ -97,6 +97,7 @@ ENV_DATA = b'var1=1\nvar2="2"' > PRE_LOAD_MAGIC = b'UBSH' > PRE_LOAD_VERSION = 0x11223344.to_bytes(4, 'big') > PRE_LOAD_HDR_SIZE = 0x00001000.to_bytes(4, 'big') > +TI_BOARD_CONFIG_DATA = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' > > # Subdirectory of the input dir to use to put test FDTs > TEST_FDT_SUBDIR = 'fdts' > @@ -199,6 +200,9 @@ class TestFunctional(unittest.TestCase): > shutil.copytree(cls.TestFile('files'), > os.path.join(cls._indir, 'files')) > > + shutil.copytree(cls.TestFile('yaml'), > + os.path.join(cls._indir, 'yaml')) > + > TestFunctional._MakeInputFile('compress', COMPRESS_DATA) > TestFunctional._MakeInputFile('compress_big', COMPRESS_DATA_BIG) > TestFunctional._MakeInputFile('bl31.bin', ATF_BL31_DATA) > @@ -6676,6 +6680,22 @@ fdt fdtmap Extract the devicetree blob from the fdtmap > ['fit']) > self.assertIn("Node '/fit': Missing tool: 'mkimage'", str(e.exception)) > > + def testTIBoardConfig(self): > + """Test that a schema validated board config file can be generated""" > + data = self._DoReadFile('277_ti_board_cfg.dts') > + self.assertEqual(TI_BOARD_CONFIG_DATA, data) > + > + def testTIBoardConfigCombined(self): > + """Test that a schema validated combined board config file can be generated""" > + data = self._DoReadFile('278_ti_board_cfg_combined.dts') > + configlen_noheader = TI_BOARD_CONFIG_DATA * 4 > + self.assertGreater(data, configlen_noheader) > + > + def testTIBoardConfigNoDataType(self): > + """Test that error is thrown when data type is not supported""" > + with self.assertRaises(ValueError) as e: > + data = self._DoReadFile('279_ti_board_cfg_no_type.dts') > + self.assertIn("Schema validation error", str(e.exception)) > > if __name__ == "__main__": > unittest.main() > diff --git a/tools/binman/test/277_ti_board_cfg.dts b/tools/binman/test/277_ti_board_cfg.dts > new file mode 100644 > index 0000000000..cda024c1b8 > --- /dev/null > +++ b/tools/binman/test/277_ti_board_cfg.dts > @@ -0,0 +1,14 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/dts-v1/; > + > +/ { > + #address-cells = <1>; > + #size-cells = <1>; > + > + binman { > + ti-board-config { > + config = "yaml/config.yaml"; > + schema = "yaml/schema.yaml"; > + }; > + }; > +}; > diff --git a/tools/binman/test/278_ti_board_cfg_combined.dts b/tools/binman/test/278_ti_board_cfg_combined.dts > new file mode 100644 > index 0000000000..95ef449cbf > --- /dev/null > +++ b/tools/binman/test/278_ti_board_cfg_combined.dts > @@ -0,0 +1,25 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/dts-v1/; > + > +/ { > + binman { > + ti-board-config { > + board-cfg { > + config = "yaml/config.yaml"; > + schema = "yaml/schema.yaml"; > + }; > + sec-cfg { > + config = "yaml/config.yaml"; > + schema = "yaml/schema.yaml"; > + }; > + rm-cfg { > + config = "yaml/config.yaml"; > + schema = "yaml/schema.yaml"; > + }; > + pm-cfg { > + config = "yaml/config.yaml"; > + schema = "yaml/schema.yaml"; > + }; > + }; > + }; > +}; > diff --git a/tools/binman/test/279_ti_board_cfg_no_type.dts b/tools/binman/test/279_ti_board_cfg_no_type.dts > new file mode 100644 > index 0000000000..584b7acc5a > --- /dev/null > +++ b/tools/binman/test/279_ti_board_cfg_no_type.dts > @@ -0,0 +1,11 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/dts-v1/; > + > +/ { > + binman { > + ti-board-config { > + config = "yaml/config.yaml"; > + schema = "yaml/schema_notype.yaml"; > + }; > + }; > +}; > diff --git a/tools/binman/test/yaml/config.yaml b/tools/binman/test/yaml/config.yaml > new file mode 100644 > index 0000000000..79fd67c7f4 > --- /dev/null > +++ b/tools/binman/test/yaml/config.yaml > @@ -0,0 +1,19 @@ > +# SPDX-License-Identifier: GPL-2.0+ > +# Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/ > +# > +# Test config > +# > +--- > + > +main-branch: > + obj: > + a: 0x0 > + b: 0 > + arr: [0, 0, 0, 0] > + another-arr: > + - #1 > + c: 0 > + d: 0 > + - #2 > + c: 0 > + d: 0 > diff --git a/tools/binman/test/yaml/schema.yaml b/tools/binman/test/yaml/schema.yaml > new file mode 100644 > index 0000000000..60bf56f671 > --- /dev/null > +++ b/tools/binman/test/yaml/schema.yaml > @@ -0,0 +1,51 @@ > +# SPDX-License-Identifier: GPL-2.0+ > +# Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/ > +# > +# Test schema > +# > +--- > + > +definitions: > + u8: > + type: integer > + minimum: 0 > + maximum: 0xff > + u16: > + type: integer > + minimum: 0 > + maximum: 0xffff > + u32: > + type: integer > + minimum: 0 > + maximum: 0xffffffff > + > +type: object > +properties: > + main-branch: > + type: object > + properties: > + obj: > + type: object > + properties: > + a: > + $ref: "#/definitions/u32" > + b: > + $ref: "#/definitions/u16" > + arr: > + type: array > + minItems: 4 > + maxItems: 4 > + items: > + $ref: "#/definitions/u8" > + another-arr: > + type: array > + minItems: 2 > + maxItems: 2 > + items: > + type: object > + properties: > + c: > + $ref: "#/definitions/u8" > + d: > + $ref: "#/definitions/u8" > + > diff --git a/tools/binman/test/yaml/schema_notype.yaml b/tools/binman/test/yaml/schema_notype.yaml > new file mode 100644 > index 0000000000..d45d6cdf7e > --- /dev/null > +++ b/tools/binman/test/yaml/schema_notype.yaml > @@ -0,0 +1,40 @@ > +# SPDX-License-Identifier: GPL-2.0+ > +# Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/ > +# > +# Test schema > +# > +--- > + > +definitions: > + u8: > + type: integer > + minimum: 0 > + maximum: 0xff > + u16: > + type: integer > + minimum: 0 > + maximum: 0xffff > + u32: > + type: integer > + minimum: 0 > + maximum: 0xffffffff > + > +type: object > +properties: > + main-branch: > + type: object > + properties: > + obj: > + type: object > + properties: > + a: > + $ref: "#/definitions/u4" > + b: > + $ref: "#/definitions/u16" > + arr: > + type: array > + minItems: 4 > + maxItems: 4 > + items: > + $ref: "#/definitions/u8" > + ... Applying: binman: ti-board-config: Add support for TI board config binaries .git/rebase-apply/patch:538: new blank line at EOF. + .git/rebase-apply/patch:584: new blank line at EOF. + warning: 2 lines add whitespace errors. Jan -- Siemens AG, Technology Competence Center Embedded Linux