Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0318606A31C for ; Mon, 30 Nov 2026 09:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=buildroot.org header.i=@buildroot.org header.a=rsa-sha256 header.s=default header.b=EJMolFfj; dkim=fail reason="signature verification failed" (2048-bit key) header.d=aruba.it header.i=@aruba.it header.a=rsa-sha256 header.s=a1 header.b=IXHzYgC8 Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id B412B80BD6; Mon, 30 Nov 2026 09:57:22 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id PIT2OkwO1eRj; Mon, 30 Nov 2026 09:57:19 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp1.osuosl.org 5949280C86 Authentication-Results: smtp1.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1796032639; b=Jf5ywMWHl+cV8IPDt/RDlklpgeyA8zxTcZIGHRlHhKlE0OeMAfftQHqbR7A/1/fY7Gao XLSFQcB6uUlMBV9Pd+gezu2CGzBujnz3ctwU4I+BGECQSNBEk8DS9YeRwdUJHHvcT++WL exzp5xcS6Z/iLn9mTmtQR4VG8hEo9yBKwBG76iYvyvFTzlvItGNaKDZeWGRSscOdZq1Rw EscUeejY5258ynTCHl6fDUr7laGiNarm2bkN5zxhzQz0Oq4Bh1ydmcY3aOPY/3TE8/UxL ymWEdAiKWefLO9Deyf8FLSQdLNSRWbJ8/rZk4aRXM7WcRdO6A8gHWb352dN4lBSFYVA== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796032639; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:Received-SPF:Received:Received: DKIM-Signature:From:To:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:X-CMAE-Envelope:Subject:X-BeenThere: X-Mailman-Version:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:Cc:Content-Type: Content-Transfer-Encoding:Errors-To:Sender; bh=2/Lqp4nkXNL3+OxgYsXZrZ16pFOh7lJQuOtjghJwEOc=; b=p1caoNXDCA4vCs4PbAH2F3IBA2pZ3s5Igo4BkRnS5e7F3qRYuaF+IMVPe5F7oXk1BHFB RYGprpe5Ri/Rl3vaBkG63YHCuHTiHWPNPUhrQBjgHpgr0Fb2BX0oPpbz0ltqSEqMbN6S6 N7QVxH12pRgKrIHX75bvChynXQ5Lq8AKmTs6q0R04kfWUe1HSSrTqs3t3dlkjI4zznPiz T2gKwp+NotTkp9S9Hvzkqt6RN3njicibM37u1PUDekc93tY576N7jNHr1HVoim7M3Mjyu idz7q/BxCMUWJeYMcwxhBLQxyDu2cLh65DSONC7czeBdjn2QG8tARNWSD6vWZGnPZ7Q== ARC-Authentication-Results: i=1; smtp1.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=buildroot.org; s=default; t=1796032639; bh=2/Lqp4nkXNL3+OxgYsXZrZ16pFOh7lJQuOtjghJwEOc=; h=From:To:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=EJMolFfj1HmWXMygsSum7paUGl/kD+0DOiT/gC23XHr+y31dbsgsaJ5ywstU8iKX2 VrpqGqQamB6tNZMntY+UUehh5hqhwl8xpwT0SF5ivVQ9rQjPDb39+R8fK3mqxZTgMW da7lueomttFQXEdmQBWTTKPc8nEDvbcFc6UElP/LDR//qsaeW+h6JbPk2EoxG4px9O 8xB5g91owNS9xL1ZqFv1c7sRXrlYqk9dJLwnhpbJLY6UBwSbxYZUF3ZKiRGvSbzSM3 8alZB+5PIYz4M8UfixBIrH6VtIPg+vW65q2DE1Vxeou6YJjCEgPAoA9mrC0xVj1ZaS ByhVg9ZBvwFuA== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp1.osuosl.org (Postfix) with ESMTP id 5949280C86; Mon, 30 Nov 2026 09:57:19 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists1.osuosl.org (Postfix) with ESMTP id 6D83C712 for ; Mon, 30 Nov 2026 09:57:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 534FE405D8 for ; Mon, 30 Nov 2026 09:57:14 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id ZBW1aIukgC3j for ; Mon, 30 Nov 2026 09:57:11 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp4.osuosl.org 54286405CD Authentication-Results: smtp4.osuosl.org; arc=none smtp.remote-ip=62.149.156.41 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=62.149.156.41; helo=smtpcmd0641.aruba.it; envelope-from=giulio.benetti@benettiengineering.com; receiver= Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=benettiengineering.com Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=aruba.it header.i=@aruba.it header.a=rsa-sha256 header.s=a1 header.b=IXHzYgC8 Received: from smtpcmd0641.aruba.it (smtpcmd0641.aruba.it [62.149.156.41]) by smtp4.osuosl.org (Postfix) with ESMTPS id 54286405CD for ; Mon, 30 Nov 2026 09:57:09 +0000 (UTC) Received: from localhost.localdomain ([95.249.253.35]) by Aruba SMTP with ESMTPSA id Xy86xHaIcghIEXy8AxTjMx; Mon, 30 Nov 2026 10:57:07 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aruba.it; s=a1; t=1796032627; bh=Z4h5W/uoGYBYTM+e3No8PpOrf5noe8DfvmTUza7xMVU=; h=From:To:Subject:Date:MIME-Version; b=IXHzYgC8XguUpymiE2JcTqE/iO3bqEnS0Xn4TVtKYkKPicCJjL4z3Rk4E75MHK5zv xrr1xRTF5tw5YE/cGcxMqRwAS0B3aFUXb3b93mPzqvnJKxqI6S2+upEq6CpautSlaI sSL1ytIYprvUX8EuHsNsEKQ4Zytg47T87d6vaA5+ljzJmEqrVkyilswhtxUPKSVL2J jeSG1eLVq72y568OyuVQFCouqWyfkmXWZbfZgk/VhQt2QNHFN0eypp//rU8Mx0Rg0O YZ7qwDRRfFYwQ9Gc2dkXZKN38tgyUSbGMe/I5E0oWqIrBcSzQVpGsBuyvHsMRILXtE 96pqkmGJEfAHQ== From: Giulio Benetti To: buildroot@buildroot.org Date: Mon, 30 Nov 2026 10:56:17 +0100 Message-ID: <20261130095702.2521737-2-giulio.benetti@benettiengineering.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130095702.2521737-1-giulio.benetti@benettiengineering.com> References: <20261130095702.2521737-1-giulio.benetti@benettiengineering.com> X-Archived-By: MIME-Version: 1.0 X-CMAE-Envelope: MS4xfKBcxMit2dxRKlKtuyeMshOPoiYemRNyTYJ8z84KKNwn7DMf3KgiVJQEyJtvgh81uv2GfZPt5QRAPJhgkoIfjs6bSwHokiCs3jt6c94t4eNAFx4G6Cmy pNVhkwdXNynEfndgB+Otf5aiQw1QRJzTWk5xPPunVh3O1dLXhQTY6OU6AxqTsYt+T2kE3098kfoasvz+KE2vxHsNPb/th3GxY/F7HAfrGkLUvVbvHVv+Rsvv cTInUREVnnlA3gpG/HYNt0hFIYpWpP3jKF+4LZDxF0NaF3eYK+7yc73uPxw7mkwk7CH9me+lnoQ/fmOpifqEdtaPd2iFFCRqiCBOKwUgW4rYKRaWdxI5Bccv vBa/EGdDEFO31s6mSl+SXgK66N85E6XxY7otYuvDvjkk99ArdNAR1L7a8aV6Q+ls7nQXS1g1Cp1o45tGPl8aO6a7w28mda4pXDENFKyUA5H8mZa2/Fdc7Iqp /dZ6f80RG8r65ck4dmWET3gbVtBhmzhCFVfqAv2QRVag6UERk+AUZZbhLavCMYu0gLnxXGCap+2zKcCDw2OsYAB1OgDLpUuhH821dIM5EOOOZf28YtcxbJL+ /MWOAX0DwTcYfzMfXrzwFOdEGln/uPvgwKS1MWjvCblMB4FIMbeakPB6Uz7GEvZYdh3ON8OEHomJFWVmh7lxGJW7dYzeb0NCJrSGfNrbS33HKUElsE7O5SjS 0O0+45JF+UQJmr1snXwD1pKf65tyepU7K+GF8Y+IpUtmenNAMoT16jiFj00hB9lrmRQWRUhU+QxhSd0y4YCHxGdLj/EypS1SeGNBG8rec+R3Clrapw7XBdMl QEFnHvqNzHiS+EnuFEm4UvFO4DljPeMWG3XlnoqXiNk72VmGzO4YAM5MAkg5dUWu1d35gaMeomK8hzYYylLs0BaX1mGtiGyRfBkrdH7EEpnkUJK7pTVTU4Gp 8qWzH3e7FP5VsqciX6//1bKzZ5rfSdjzk4xwSHXslbvKYqqerZlfVTVh/iTaaChJWBuwd2ycjpiSP+NbNixqHFpwgbIycqbwjUIBOauRsRQztTSzOkhQyhuf rJtG699CElFkAy/LDDN6kUK9lGqNoLrh8RvIk8H9a5ZeYIoIR30C2qpdc7BAC8fWApVDqpwJh1D1bpp18UjaW2jJsqTTwLci2gacATCxDBS/ANVLfGpohUNa MTgfM/n1pQY+RarEkF3039v7t8LOv19aTAy4+X640FlIhbaL2TjT4XdWGuYskP/D+gWq/r+MI+Dxlf6/k6+lKe/MsFStQW3pGTlHZ2tZSFUZ6aejeHw0WTh8 yuctKpMWz/Gfvz+R9wtwdDv/h9riVEpC3aHVt5LVPGYZ56PRg2HsrQf5qFJA+x2W0qzX+p0FOkS8Buk26TlQ0PK9NklNEQ== Subject: [Buildroot] [PATCH 01/46] utils/check-package: add checks for genimage*.cfg files X-BeenThere: buildroot@buildroot.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Discussion and development of buildroot List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Vincent=20Stehl=C3=A9?= , Bryan Brattlof , Ricardo Martincoski , Jiaxun Yang , Marcin Niestroj , Francois Dugast , Thomas Petazzoni , Heiko Thiery , Dario Binacchi , Sergey Matyukevich , =?UTF-8?q?Vincent=20Stehl=C3=A9?= , Ludovic Desroches , Francois Perrad , Jagan Teki , Thomas Bonnefille , Jamie Gibbons , Michael Trimarchi , Kilian Zinnecker , Joel Stanley , David Lechner , Alistair Francis , Eugen Hristev , Julien Olivain , Damien Le Moal , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Romain Naour , Kory Maincent , Leo Yu-Chi Liang , Simon Doppler , Michael Walle , Dick Olsson , Giulio Benetti Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "buildroot" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The coding style of the genimage.cfg files is described in the "The genimage.cfg file" section of the manual, but nothing enforces it. Add a library checking these rules: - indentation with tabs, according to the nesting level - position of the curly brackets - empty line after a node, except for the last one - one space before and after '=' - filename beginning with genimage - notation of the offset and size options - GB, MB, KB units in comments - partition-type-uuid set for every partition of a GPT image, unquoted, using the genimage shortcut when there is one, and in lower-case otherwise The table of shortcuts comes from genimage's image-hd.c. Files generated from a template (genimage.cfg.in, genimage.cfg.template*) are not checked, since they contain placeholders. Add the existing files that do not follow the rules to .checkpackageignore. Assisted-by: Claude Opus 5.5 Signed-off-by: Giulio Benetti --- .checkpackageignore | 46 ++ utils/check-package | 7 + utils/checkpackagelib/lib_genimage.py | 407 ++++++++++++++ utils/checkpackagelib/test_lib_genimage.py | 623 +++++++++++++++++++++ 4 files changed, 1083 insertions(+) create mode 100644 utils/checkpackagelib/lib_genimage.py create mode 100644 utils/checkpackagelib/test_lib_genimage.py diff --git a/.checkpackageignore b/.checkpackageignore index 6a64d06fc9..1e1147a6cf 100644 --- a/.checkpackageignore +++ b/.checkpackageignore @@ -1,48 +1,89 @@ +board/aarch64-efi/genimage-efi.cfg lib_genimage.EmptyLineAfterNode +board/amarula/vyasa/genimage.cfg lib_genimage.CommentUnits board/amarula/vyasa/post-build.sh Shellcheck +board/andes/ae350/genimage_sdcard.cfg lib_genimage.EmptyLineAfterNode board/arcturus/aarch64-ucls1012a/post-build.sh Shellcheck board/arcturus/aarch64-ucls1012a/post-image.sh Shellcheck +board/arm/fvp-ebbr/genimage.cfg lib_genimage.PartitionTypeUuidShortcut +board/aspeed/ast2500-evb/genimage.cfg lib_genimage.EmptyLineAfterNode lib_genimage.OptionAssignment +board/aspeed/ast2600-evb/genimage.cfg lib_genimage.EmptyLineAfterNode board/aspeed/common/post-image.sh Shellcheck board/asus/tinker/post-build.sh Shellcheck board/atmel/flasher.sh Shellcheck +board/avnet/rzboard_v2l/genimage.cfg lib_genimage.EmptyLineAfterNode lib_genimage.GptPartitionTypeUuid board/beagleboard/beaglebone-qt5/patches/linux/0001-keep-jtag-clock-alive-for-debugger.patch lib_patch.Upstream +board/beagleboard/beagleplay/genimage.cfg lib_genimage.Indent +board/beagleboard/beaglev_fire/genimage.cfg lib_genimage.EmptyLineAfterNode lib_genimage.GptPartitionTypeUuid lib_genimage.Indent lib_genimage.PartitionTypeUuidCase lib_genimage.PartitionTypeUuidShortcut board/boundarydevices/common/post-build.sh Shellcheck board/boundarydevices/common/post-image.sh Shellcheck board/broadcom/northstar/post-image.sh Shellcheck board/bsh/imx8mn-bsh-smm-s2-pro/flash.sh Shellcheck lib_shellscript.EmptyLastLine +board/bsh/imx8mn-bsh-smm-s2-pro/genimage.cfg lib_genimage.GptPartitionTypeUuid board/bsh/imx8mn-bsh-smm-s2-pro/post-build.sh Shellcheck board/bsh/imx8mn-bsh-smm-s2-pro/post-image.sh Shellcheck board/bsh/imx8mn-bsh-smm-s2/flash.sh Shellcheck lib_shellscript.EmptyLastLine board/bsh/imx8mn-bsh-smm-s2/post-build.sh Shellcheck +board/canaan/k210-soc/genimage.cfg lib_genimage.EmptyLineAfterNode board/canaan/k210-soc/post-build.sh Shellcheck board/chromebook/elm/sign.sh Shellcheck board/chromebook/mksd.sh Shellcheck board/ci20/patches/uboot/0001-mips-Remove-default-endiannes.patch lib_patch.Upstream +board/compulab/iot-gate-imx8-ebbr/genimage.cfg lib_genimage.PartitionTypeUuidCase +board/coolpi/coolpi-4b/genimage.cfg lib_genimage.EmptyLineAfterNode lib_genimage.GptPartitionTypeUuid board/freescale/common/imx/imx8-bootloader-prepare.sh Shellcheck board/freescale/common/mxs/post-image.sh Shellcheck board/friendlyarm/nanopi-r2s/post-build.sh Shellcheck +board/grinn/liteboard/genimage.cfg lib_genimage.CommentUnits board/hardkernel/odroidc2/post-image.sh Shellcheck board/hardkernel/odroidc2/rootfs_overlay/etc/init.d/S09modload Shellcheck lib_sysv.Variables +board/khadas/vim3/genimage.cfg lib_genimage.OptionAssignment +board/kontron/bl-imx8mm/genimage.cfg lib_genimage.GptPartitionTypeUuid board/kontron/bl-imx8mm/post-build.sh Shellcheck +board/kontron/smarc-sal28/genimage.cfg lib_genimage.GptPartitionTypeUuid board/kontron/smarc-sal28/post-build.sh Shellcheck +board/lego/ev3/genimage.cfg lib_genimage.CommentUnits lib_genimage.EmptyLineAfterNode board/lego/ev3/post-image.sh Shellcheck +board/loongarch64-efi/genimage-efi.cfg lib_genimage.EmptyLineAfterNode +board/mender/x86_64/genimage-efi.cfg lib_genimage.EmptyLineAfterNode lib_genimage.PartitionTypeUuidShortcut +board/microchip/mpfs_icicle/genimage.cfg lib_genimage.EmptyLineAfterNode lib_genimage.GptPartitionTypeUuid lib_genimage.Indent lib_genimage.PartitionTypeUuidCase +board/microchip/sama7g5ek/genimage.cfg lib_genimage.EmptyLineAfterNode +board/minnowboard/genimage.cfg lib_genimage.EmptyLineAfterNode board/minnowboard/post-build.sh Shellcheck board/nexbox/a95x/post-build.sh Shellcheck board/nexbox/a95x/post-image.sh Shellcheck +board/octavo/osd32mp1-brk/genimage.cfg lib_genimage.GptPartitionTypeUuid board/octavo/osd32mp1-brk/patches/uboot/0001-Add-OSD32MP1-BRK-device-tree-support.patch lib_patch.NumberedSubject lib_patch.Upstream board/octavo/osd32mp1-brk/patches/uboot/0002-Add-OSD32MP1-BRK-build-config.patch lib_patch.NumberedSubject lib_patch.Upstream +board/octavo/osd32mp1-red/genimage.cfg lib_genimage.GptPartitionTypeUuid board/octavo/osd32mp1-red/patches/uboot/0001-Add-OSD32MP1-RED-Device-Tree-support.patch lib_patch.NumberedSubject lib_patch.Upstream board/octavo/osd32mp1-red/patches/uboot/0002-configs-stm32mp15_trusted_defconfig-disable-environm.patch lib_patch.NumberedSubject lib_patch.Upstream +board/olimex/stmp1_olinuxino/genimage.cfg lib_genimage.GptPartitionTypeUuid board/olpc/post-build.sh Shellcheck +board/orangepi/common/genimage.cfg lib_genimage.GptPartitionTypeUuid board/orangepi/common/post-build.sh Shellcheck +board/orangepi/orangepi-5-plus/genimage.cfg lib_genimage.PartitionTypeUuidShortcut board/orangepi/orangepi-zero/patches/linux/0001-ARM-dts-orange-pi-zero-interrupt-triggering-xr819.patch lib_patch.Upstream board/orangepi/orangepi-zero/patches/linux/0002-ARM-dts-orange-pi-zero-enable-spi-nor.patch lib_patch.Upstream board/orangepi/orangepi-zero/patches/linux/0003-ARM-dts-orange-pi-zero-enable-spidev.patch lib_patch.Upstream board/orangepi/orangepi-zero/patches/linux/0004-ARM-dts-orange-pi-zero-enable-uart.patch lib_patch.Upstream +board/pc/genimage-efi.cfg lib_genimage.PartitionTypeUuidShortcut +board/pine64/rockpro64-ebbr/genimage.cfg lib_genimage.PartitionTypeUuidCase +board/pine64/rockpro64/genimage.cfg lib_genimage.GptPartitionTypeUuid lib_genimage.PartitionTypeUuidShortcut +board/pine64/star64/genimage.cfg lib_genimage.GptPartitionTypeUuid lib_genimage.Indent lib_genimage.PartitionTypeUuidCase +board/qemu/aarch64-ebbr/genimage.cfg lib_genimage.PartitionTypeUuidShortcut board/qemu/aarch64-sbsa/assemble-flash-images Shellcheck +board/qemu/aarch64-sbsa/genimage.cfg lib_genimage.PartitionTypeUuidShortcut +board/qemu/arm-ebbr/genimage.cfg lib_genimage.PartitionTypeUuidShortcut +board/qemu/loongarch64-virt-efi/genimage.cfg lib_genimage.EmptyLineAfterNode +board/qemu/riscv64-virt-efi/genimage.cfg lib_genimage.PartitionTypeUuidShortcut +board/radxa/rock5b/genimage.cfg lib_genimage.PartitionTypeUuidShortcut board/raspberrypi/post-build.sh Shellcheck board/raspberrypi/post-image.sh Shellcheck +board/seeed/stm32mp157c-odyssey/genimage.cfg lib_genimage.GptPartitionTypeUuid board/seeed/stm32mp157c-odyssey/patches/linux/0001-ARM-dts-stm32-fix-stm32mp157c-odyssey-card-detect.patch lib_patch.Upstream board/sheevaplug/patches/uboot/0001-Remove-redundant-YYLOC-global-declaration.patch lib_patch.Upstream +board/sifive/common/genimage_sdcard.cfg lib_genimage.PartitionTypeUuidShortcut +board/sipeed/licheepi_nano/genimage.cfg lib_genimage.CurlyBrackets lib_genimage.EmptyLastLine lib_genimage.EmptyLineAfterNode board/solidrun/clearfog/post-build.sh Shellcheck board/solidrun/macchiatobin/post-build-mainline.sh Shellcheck board/solidrun/macchiatobin/post-build.sh Shellcheck @@ -52,7 +93,9 @@ board/stmicroelectronics/stm32f429-disco/flash.sh Shellcheck board/stmicroelectronics/stm32f469-disco/flash_sd.sh Shellcheck board/stmicroelectronics/stm32f469-disco/flash_xip.sh Shellcheck board/synopsys/axs10x/post-build.sh Shellcheck +board/ti/am574x-idk/genimage.cfg lib_genimage.Indent board/udoo/common/post-build.sh Shellcheck +board/visionfive2/genimage.cfg lib_genimage.PartitionTypeUuidShortcut boot/afboot-stm32/0003-Makefile-disable-stack-protector.patch lib_patch.Upstream boot/optee-os/3.13.0/0001-core-zlib-fix-build-warning-when-_LFS64_LARGEFILE-is.patch lib_patch.Upstream boot/syslinux/0001-bios-Fix-alignment-change-with-gcc-5.patch lib_patch.Upstream @@ -980,6 +1023,9 @@ support/scripts/fix-configure-powerpc64.sh lib_shellscript.EmptyLastLine support/scripts/generate-gitlab-ci-yml Shellcheck support/scripts/mkmakefile Shellcheck lib_shellscript.ConsecutiveEmptyLines support/scripts/setlocalversion Shellcheck +support/testing/tests/boot/test_grub/genimage-aarch64-efi.cfg lib_genimage.PartitionTypeUuidShortcut support/testing/tests/core/post-build.sh Shellcheck support/testing/tests/package/test_opkg/post-build.sh Shellcheck +support/testing/tests/package/test_xen/aarch64/genimage.cfg lib_genimage.PartitionTypeUuidCase +support/testing/tests/package/test_xen/arm/genimage.cfg lib_genimage.PartitionTypeUuidCase support/testing/tests/utils/test_get_developers/0001-package-binutils-change-.mk.patch lib_patch.NumberedSubject lib_patch.Upstream diff --git a/utils/check-package b/utils/check-package index aa10280f4d..f567e735c5 100755 --- a/utils/check-package +++ b/utils/check-package @@ -19,6 +19,7 @@ import sys import checkpackagelib.base import checkpackagelib.lib_config import checkpackagelib.lib_defconfig +import checkpackagelib.lib_genimage import checkpackagelib.lib_hash import checkpackagelib.lib_ignore import checkpackagelib.lib_mk @@ -159,6 +160,10 @@ SYSV_INIT_SCRIPT_FILENAME = re.compile(r"/S\d\d[^/]+$") # in a br2-external tree. BR_DEFCONFIG_FILENAME = re.compile(r"^(.+/)?configs/[^/]+_defconfig$") +# Match any name containing genimage, so that the ones with a wrong prefix are +# reported. +GENIMAGE_CFG_FILENAME = re.compile(r"genimage[^/]*\.cfg$") + def get_lib_from_filename(fname): if flags.intree_only: @@ -176,6 +181,8 @@ def get_lib_from_filename(fname): return checkpackagelib.lib_config if BR_DEFCONFIG_FILENAME.search(fname): return checkpackagelib.lib_defconfig + if GENIMAGE_CFG_FILENAME.search(fname): + return checkpackagelib.lib_genimage if fname.endswith(".hash"): return checkpackagelib.lib_hash if fname.endswith(".mk") or fname.endswith(".mk.in"): diff --git a/utils/checkpackagelib/lib_genimage.py b/utils/checkpackagelib/lib_genimage.py new file mode 100644 index 0000000000..dc27183cda --- /dev/null +++ b/utils/checkpackagelib/lib_genimage.py @@ -0,0 +1,407 @@ +# See utils/checkpackagelib/readme.txt before editing this file. + +import os +import re + +from checkpackagelib.base import _CheckFunction +from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401 +from checkpackagelib.lib import EmptyLastLine # noqa: F401 +from checkpackagelib.lib import NewlineAtEof # noqa: F401 +from checkpackagelib.lib import TrailingSpace # noqa: F401 +from checkpackagelib.lib import Utf8Characters # noqa: F401 +from checkpackagelib.tool import NotExecutable # noqa: F401 + +# used in more than one check +STRING_OR_COMMENT = re.compile(r"(\"[^\"]*\"|'[^']*')|(#|//).*") + + +def strip_comment(text): + return STRING_OR_COMMENT.sub(lambda m: m.group(1) or "", text).strip() + + +def strip_comment_and_strings(text): + return STRING_OR_COMMENT.sub(lambda m: '""' if m.group(1) else "", text).strip() + + +class _Structure(_CheckFunction): + """Keeps track of the curly brackets, to know where each line is located""" + BRACKET = re.compile(r"[{}]") + LIST = re.compile(r"=\s*$") + + def before(self): + # One entry per open curly bracket: the words of the node's name, or + # None for a list, e.g. 'files = {' + self.stack = [] + + def track(self, code): + """Update the stack, return the list of entries that were closed""" + closed = [] + start = 0 + for m in self.BRACKET.finditer(code): + if m.group() == "{": + name = code[start:m.start()] + self.stack.append(None if self.LIST.search(name) else name.split()) + elif self.stack: + closed.append(self.stack.pop()) + start = m.end() + return closed + + +class CommentUnits(_CheckFunction): + COMMENT = re.compile(r"(?:\"[^\"]*\"|'[^']*'|[^\"'#])*?(?:#|//)(.*)") + UNIT = re.compile(r"\b\d+ ?([kmg]b?)\b", re.IGNORECASE) + ALLOWED = ["GB", "MB", "KB"] + + def check_line(self, lineno, text): + comment = self.COMMENT.match(text) + if not comment: + return + for unit in self.UNIT.findall(comment.group(1)): + if unit not in self.ALLOWED: + return ["{}:{}: use GB, MB or KB in comments ({}#writing-genimage-cfg)" + .format(self.filename, lineno, self.url_to_manual), + text] + + +class CurlyBrackets(_Structure): + def check_line(self, lineno, text): + code = strip_comment_and_strings(text) + in_list = bool(self.stack) and self.stack[-1] is None + closed = self.track(code) + + if code.startswith("{"): + return ["{}:{}: open curly bracket must be on the same line as the name ({}#writing-genimage-cfg)" + .format(self.filename, lineno, self.url_to_manual), + text] + # lists can be on a single line + if any(entry is not None for entry in closed) and code != "}": + return ["{}:{}: closing curly bracket must be alone on its line ({}#writing-genimage-cfg)" + .format(self.filename, lineno, self.url_to_manual), + text] + opens_node = "{" in code and not in_list and "=" not in code.split("{")[0] + if opens_node and not code.endswith("{"): + return ["{}:{}: node content must start on a new line ({}#writing-genimage-cfg)" + .format(self.filename, lineno, self.url_to_manual), + text] + + +class EmptyLineAfterNode(_Structure): + def before(self): + super().before() + self.after_node = False + + def check_line(self, lineno, text): + code = strip_comment_and_strings(text) + missing = self.after_node and text.strip() != "" and not code.startswith("}") + closed = self.track(code) + self.after_node = bool(closed) and closed[-1] is not None + + if missing: + return ["{}:{}: missing empty line after the previous node ({}#writing-genimage-cfg)" + .format(self.filename, lineno, self.url_to_manual), + text] + + +class Filename(_CheckFunction): + def before(self): + if not os.path.basename(self.filename).startswith("genimage"): + return ["{}:0: filename must begin with genimage ({}#writing-genimage-cfg)" + .format(self.filename, self.url_to_manual)] + + +class GptPartitionTypeUuid(_Structure): + """Checks that each partition of a GPT image has a partition-type-uuid""" + OPTION = re.compile(r"^([a-z-]+)\s*=\s*[\"']?([^\"'\s]*)") + FALSE = ["false", "no", "off"] + + def before(self): + super().before() + self.gpt = False + self.partition = None + self.missing = [] + + def check_line(self, lineno, text): + code = strip_comment_and_strings(text) + closed = self.track(code) + node = self.stack[-1][0] if self.stack and self.stack[-1] else None + + if closed: + for entry in closed: + if not entry: + continue + if entry[0] == "partition" and self.partition: + if self.partition["needs-type"]: + self.missing.append(self.partition) + self.partition = None + elif entry[0] == "image": + gpt, missing = self.gpt, self.missing + self.gpt, self.missing = False, [] + if gpt and missing: + return ["{}:{}: GPT partition without partition-type-uuid: {} ({}#writing-genimage-cfg)" + .format(self.filename, missing[0]["lineno"], + ", ".join(p["name"] for p in missing), + self.url_to_manual), + missing[0]["text"]] + return + + if node == "partition" and code.endswith("{"): + self.partition = {"name": " ".join(strip_comment(text).rstrip("{").split()[1:]), + "lineno": lineno, "text": text, "needs-type": True} + return + + option = self.OPTION.search(strip_comment(text)) + if not option: + return + name, value = option.groups() + if node == "hdimage": + # 'gpt = true' is the deprecated form + if name == "partition-table-type": + self.gpt = value in ["gpt", "hybrid"] + elif name == "gpt": + self.gpt = value.lower() not in self.FALSE + elif node == "partition" and self.partition: + if name == "partition-type-uuid": + self.partition["needs-type"] = False + elif name == "in-partition-table" and value.lower() in self.FALSE: + self.partition["needs-type"] = False + + +class Indent(_Structure): + def check_line(self, lineno, text): + if text.strip() == "": + return + code = strip_comment_and_strings(text) + expected = len(self.stack) + if code.startswith("}"): + expected = max(0, expected - 1) + self.track(code) + + if text[:len(text) - len(text.lstrip())] != "\t" * expected: + return ["{}:{}: should be indented with {} tab(s) ({}#writing-genimage-cfg)" + .format(self.filename, lineno, expected, self.url_to_manual), + text] + + +class OptionAssignment(_CheckFunction): + ASSIGNMENT = re.compile(r"^[\w-]+(\s*)\+?=(\s*)(.*)$") + + def check_line(self, lineno, text): + m = self.ASSIGNMENT.search(strip_comment(text)) + if not m: + return + space_before, space_after, value = m.groups() + if space_before != " " or (value and space_after != " "): + return ["{}:{}: use one space before and after '=' ({}#writing-genimage-cfg)" + .format(self.filename, lineno, self.url_to_manual), + text] + + +class SizeNotation(_CheckFunction): + OPTION = re.compile(r"^(?:offset|size)\s*=\s*[\"']?(\d[^\"'\s]*)") + ALLOWED = re.compile(r"^(0x[0-9a-fA-F]+|\d+[GMK]?)$") + # genimage also accepts a percentage of the available space as size + PERCENTAGE = re.compile(r"^\d+%$") + + def check_line(self, lineno, text): + m = self.OPTION.search(strip_comment(text)) + if not m: + return + value = m.group(1) + if self.PERCENTAGE.match(value): + return + if not self.ALLOWED.match(value): + return ["{}:{}: use G, M, K, a 0x prefix or a byte count ({}#writing-genimage-cfg)" + .format(self.filename, lineno, self.url_to_manual), + text] + if value[-1] in "GMK": + return + count = int(value, 16) if value.startswith("0x") else int(value) + if count == 0 or count % 1024: + return + for suffix, unit in [("G", 1 << 30), ("M", 1 << 20), ("K", 1 << 10)]: + if count % unit == 0: + return ["{}:{}: use {}{} instead of {} ({}#writing-genimage-cfg)" + .format(self.filename, lineno, count // unit, suffix, value, self.url_to_manual), + text] + + +class _PartitionTypeUuid(_CheckFunction): + OPTION = re.compile(r"^partition-type-uuid\s*=\s*(\S+)") + GUID = re.compile(r"^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$", re.IGNORECASE) + # See gpt_partition_type_shortcuts in genimage's image-hd.c + SHORTCUTS = { + "0fc63daf-8483-4772-8e79-3d69d8477de4": "L", + "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f": "S", + "933ac7e1-2eb4-4f13-b844-0e14e2aef915": "H", + "c12a7328-f81f-11d2-ba4b-00a0c93ec93b": "U", + "a19d880f-05fc-4d3b-a006-743f0f84911e": "R", + "e6d6d379-f507-44c2-a23c-238f2a3df928": "V", + "ebd0a0a2-b9e5-4433-87c0-68b6b72699c7": "F", + "4778ed65-bf42-45fa-9c5b-287a1dc4aab1": "barebox-state", + "6c3737f2-07f8-45d1-ad45-15d260aab24d": "barebox-env", + "3de21764-95bd-54bd-a5c3-4abe786f38a8": "u-boot-env", + "6523f8ae-3eb1-4e2a-a05a-18b695ae656f": "root-alpha", + "d27f46ed-2919-4cb8-bd25-9531f3c16534": "root-arc", + "69dad710-2ce4-4e3c-b16c-21a1d49abed3": "root-arm", + "b921b045-1df0-41c3-af44-4c6f280d3fae": "root-arm64", + "993d8d3d-f80e-4225-855a-9daf8ed7ea97": "root-ia64", + "77055800-792c-4f94-b39a-98c91b762bb6": "root-loongarch64", + "e9434544-6e2c-47cc-bae2-12d6deafb44c": "root-mips", + "d113af76-80ef-41b4-bdb6-0cff4d3d4a25": "root-mips64", + "37c58c8a-d913-4156-a25f-48b1b64e07f0": "root-mips-le", + "700bda43-7a34-4507-b179-eeb93d7a7ca3": "root-mips64-le", + "1aacdb3b-5444-4138-bd9e-e5c2239b2346": "root-parisc", + "1de3f1ef-fa98-47b5-8dcd-4a860a654d78": "root-ppc", + "912ade1d-a839-4913-8964-a10eee08fbd2": "root-ppc64", + "c31c45e6-3f39-412e-80fb-4809c4980599": "root-ppc64-le", + "60d5a7fe-8e7d-435c-b714-3dd8162144e1": "root-riscv32", + "72ec70a6-cf74-40e6-bd49-4bda08e8f224": "root-riscv64", + "08a7acea-624c-4a20-91e8-6e0fa67d23f9": "root-s390", + "5eead9a9-fe09-4a1e-a1d7-520d00531306": "root-s390x", + "c50cdd70-3862-4cc3-90e1-809a8c93ee2c": "root-tilegx", + "44479540-f297-41b2-9af7-d131d5f0458a": "root-x86", + "4f68bce3-e8cd-4db1-96e7-fbcaf984b709": "root-x86-64", + "e18cf08c-33ec-4c0d-8246-c6c6fb3da024": "usr-alpha", + "7978a683-6316-4922-bbee-38bff5a2fecc": "usr-arc", + "7d0359a3-02b3-4f0a-865c-654403e70625": "usr-arm", + "b0e01050-ee5f-4390-949a-9101b17104e9": "usr-arm64", + "4301d2a6-4e3b-4b2a-bb94-9e0b2c4225ea": "usr-ia64", + "e611c702-575c-4cbe-9a46-434fa0bf7e3f": "usr-loongarch64", + "773b2abc-2a99-4398-8bf5-03baac40d02b": "usr-mips", + "57e13958-7331-4365-8e6e-35eeee17c61b": "usr-mips64", + "0f4868e9-9952-4706-979f-3ed3a473e947": "usr-mips-le", + "c97c1f32-ba06-40b4-9f22-236061b08aa8": "usr-mips64-le", + "dc4a4480-6917-4262-a4ec-db9384949f25": "usr-parisc", + "7d14fec5-cc71-415d-9d6c-06bf0b3c3eaf": "usr-ppc", + "2c9739e2-f068-46b3-9fd0-01c5a9afbcca": "usr-ppc64", + "15bb03af-77e7-4d4a-b12b-c0d084f7491c": "usr-ppc64-le", + "b933fb22-5c3f-4f91-af90-e2bb0fa50702": "usr-riscv32", + "beaec34b-8442-439b-a40b-984381ed097d": "usr-riscv64", + "cd0f869b-d0fb-4ca0-b141-9ea87cc78d66": "usr-s390", + "8a4f5770-50aa-4ed3-874a-99b710db6fea": "usr-s390x", + "55497029-c7c1-44cc-aa39-815ed1558630": "usr-tilegx", + "75250d76-8cc6-458e-bd66-bd47cc81a812": "usr-x86", + "8484680c-9521-48c6-9c11-b0720656f69e": "usr-x86-64", + "fc56d9e9-e6e5-4c06-be32-e74407ce09a5": "root-alpha-verity", + "24b2d975-0f97-4521-afa1-cd531e421b8d": "root-arc-verity", + "7386cdf2-203c-47a9-a498-f2ecce45a2d6": "root-arm-verity", + "df3300ce-d69f-4c92-978c-9bfb0f38d820": "root-arm64-verity", + "86ed10d5-b607-45bb-8957-d350f23d0571": "root-ia64-verity", + "f3393b22-e9af-4613-a948-9d3bfbd0c535": "root-loongarch64-verity", + "7a430799-f711-4c7e-8e5b-1d685bd48607": "root-mips-verity", + "579536f8-6a33-4055-a95a-df2d5e2c42a8": "root-mips64-verity", + "d7d150d2-2a04-4a33-8f12-16651205ff7b": "root-mips-le-verity", + "16b417f8-3e06-4f57-8dd2-9b5232f41aa6": "root-mips64-le-verity", + "d212a430-fbc5-49f9-a983-a7feef2b8d0e": "root-parisc-verity", + "906bd944-4589-4aae-a4e4-dd983917446a": "root-ppc64-le-verity", + "9225a9a3-3c19-4d89-b4f6-eeff88f17631": "root-ppc64-verity", + "98cfe649-1588-46dc-b2f0-add147424925": "root-ppc-verity", + "ae0253be-1167-4007-ac68-43926c14c5de": "root-riscv32-verity", + "b6ed5582-440b-4209-b8da-5ff7c419ea3d": "root-riscv64-verity", + "7ac63b47-b25c-463b-8df8-b4a94e6c90e1": "root-s390-verity", + "b325bfbe-c7be-4ab8-8357-139e652d2f6b": "root-s390x-verity", + "966061ec-28e4-4b2e-b4a5-1f0a825a1d84": "root-tilegx-verity", + "2c7357ed-ebd2-46d9-aec1-23d437ec2bf5": "root-x86-64-verity", + "d13c5d3b-b5d1-422a-b29f-9454fdc89d76": "root-x86-verity", + "8cce0d25-c0d0-4a44-bd87-46331bf1df67": "usr-alpha-verity", + "fca0598c-d880-4591-8c16-4eda05c7347c": "usr-arc-verity", + "c215d751-7bcd-4649-be90-6627490a4c05": "usr-arm-verity", + "6e11a4e7-fbca-4ded-b9e9-e1a512bb664e": "usr-arm64-verity", + "6a491e03-3be7-4545-8e38-83320e0ea880": "usr-ia64-verity", + "f46b2c26-59ae-48f0-9106-c50ed47f673d": "usr-loongarch64-verity", + "6e5a1bc8-d223-49b7-bca8-37a5fcceb996": "usr-mips-verity", + "81cf9d90-7458-4df4-8dcf-c8a3a404f09b": "usr-mips64-verity", + "46b98d8d-b55c-4e8f-aab3-37fca7f80752": "usr-mips-le-verity", + "3c3d61fe-b5f3-414d-bb71-8739a694a4ef": "usr-mips64-le-verity", + "5843d618-ec37-48d7-9f12-cea8e08768b2": "usr-parisc-verity", + "ee2b9983-21e8-4153-86d9-b6901a54d1ce": "usr-ppc64-le-verity", + "bdb528a5-a259-475f-a87d-da53fa736a07": "usr-ppc64-verity", + "df765d00-270e-49e5-bc75-f47bb2118b09": "usr-ppc-verity", + "cb1ee4e3-8cd0-4136-a0a4-aa61a32e8730": "usr-riscv32-verity", + "8f1056be-9b05-47c4-81d6-be53128e5b54": "usr-riscv64-verity", + "b663c618-e7bc-4d6d-90aa-11b756bb1797": "usr-s390-verity", + "31741cc4-1a2a-4111-a581-e00b447d2d06": "usr-s390x-verity", + "2fb4bf56-07fa-42da-8132-6b139f2026ae": "usr-tilegx-verity", + "77ff5f63-e7b6-4633-acf4-1565b864c0e6": "usr-x86-64-verity", + "8f461b0d-14ee-4e81-9aa9-049b6fb97abd": "usr-x86-verity", + "d46495b7-a053-414f-80f7-700c99921ef8": "root-alpha-verity-sig", + "143a70ba-cbd3-4f06-919f-6c05683a78bc": "root-arc-verity-sig", + "42b0455f-eb11-491d-98d3-56145ba9d037": "root-arm-verity-sig", + "6db69de6-29f4-4758-a7a5-962190f00ce3": "root-arm64-verity-sig", + "e98b36ee-32ba-4882-9b12-0ce14655f46a": "root-ia64-verity-sig", + "5afb67eb-ecc8-4f85-ae8e-ac1e7c50e7d0": "root-loongarch64-verity-sig", + "bba210a2-9c5d-45ee-9e87-ff2ccbd002d0": "root-mips-verity-sig", + "43ce94d4-0f3d-4999-8250-b9deafd98e6e": "root-mips64-verity-sig", + "c919cc1f-4456-4eff-918c-f75e94525ca5": "root-mips-le-verity-sig", + "904e58ef-5c65-4a31-9c57-6af5fc7c5de7": "root-mips64-le-verity-sig", + "15de6170-65d3-431c-916e-b0dcd8393f25": "root-parisc-verity-sig", + "d4a236e7-e873-4c07-bf1d-bf6cf7f1c3c6": "root-ppc64-le-verity-sig", + "f5e2c20c-45b2-4ffa-bce9-2a60737e1aaf": "root-ppc64-verity-sig", + "1b31b5aa-add9-463a-b2ed-bd467fc857e7": "root-ppc-verity-sig", + "3a112a75-8729-4380-b4cf-764d79934448": "root-riscv32-verity-sig", + "efe0f087-ea8d-4469-821a-4c2a96a8386a": "root-riscv64-verity-sig", + "3482388e-4254-435a-a241-766a065f9960": "root-s390-verity-sig", + "c80187a5-73a3-491a-901a-017c3fa953e9": "root-s390x-verity-sig", + "b3671439-97b0-4a53-90f7-2d5a8f3ad47b": "root-tilegx-verity-sig", + "41092b05-9fc8-4523-994f-2def0408b176": "root-x86-64-verity-sig", + "5996fc05-109c-48de-808b-23fa0830b676": "root-x86-verity-sig", + "5c6e1c76-076a-457a-a0fe-f3b4cd21ce6e": "usr-alpha-verity-sig", + "94f9a9a1-9971-427a-a400-50cb297f0f35": "usr-arc-verity-sig", + "d7ff812f-37d1-4902-a810-d76ba57b975a": "usr-arm-verity-sig", + "c23ce4ff-44bd-4b00-b2d4-b41b3419e02a": "usr-arm64-verity-sig", + "8de58bc2-2a43-460d-b14e-a76e4a17b47f": "usr-ia64-verity-sig", + "b024f315-d330-444c-8461-44bbde524e99": "usr-loongarch64-verity-sig", + "97ae158d-f216-497b-8057-f7f905770f54": "usr-mips-verity-sig", + "05816ce2-dd40-4ac6-a61d-37d32dc1ba7d": "usr-mips64-verity-sig", + "3e23ca0b-a4bc-4b4e-8087-5ab6a26aa8a9": "usr-mips-le-verity-sig", + "f2c2c7ee-adcc-4351-b5c6-ee9816b66e16": "usr-mips64-le-verity-sig", + "450dd7d1-3224-45ec-9cf2-a43a346d71ee": "usr-parisc-verity-sig", + "c8bfbd1e-268e-4521-8bba-bf314c399557": "usr-ppc64-le-verity-sig", + "0b888863-d7f8-4d9e-9766-239fce4d58af": "usr-ppc64-verity-sig", + "7007891d-d371-4a80-86a4-5cb875b9302e": "usr-ppc-verity-sig", + "c3836a13-3137-45ba-b583-b16c50fe5eb4": "usr-riscv32-verity-sig", + "d2f9000a-7a18-453f-b5cd-4d32f77a7b32": "usr-riscv64-verity-sig", + "17440e4f-a8d0-467f-a46e-3912ae6ef2c5": "usr-s390-verity-sig", + "3f324816-667b-46ae-86ee-9b0c0c6c11b4": "usr-s390x-verity-sig", + "4ede75e2-6ccc-4cc8-b9c7-70334b087510": "usr-tilegx-verity-sig", + "e7bb33fb-06cf-4e81-8273-e543b413e2e2": "usr-x86-64-verity-sig", + "974a71c0-de41-43c3-be5d-5c5ccd1ad2c0": "usr-x86-verity-sig", + "bc13c2ff-59e6-4262-a352-b275fd6f7172": "xbootldr", + "3b8f8425-20e0-4f3b-907f-1a25a76f98e8": "srv", + "4d21b016-b534-45c2-a9fb-5c16e091fd2d": "var", + "7ec6f557-3bc5-4aca-b293-16ef5df639d1": "tmp", + "773f91ef-66d4-49b5-bd83-d683bf40ad16": "user-home", + } + + def get_value(self, text): + m = self.OPTION.search(strip_comment(text)) + return m.group(1) if m else "" + + +class PartitionTypeUuidCase(_PartitionTypeUuid): + def check_line(self, lineno, text): + value = self.get_value(text).strip("\"'") + if not self.GUID.match(value) or value.lower() in self.SHORTCUTS: + return + if value != value.lower(): + return ["{}:{}: partition-type-uuid must be in lower-case ({}#writing-genimage-cfg)" + .format(self.filename, lineno, self.url_to_manual), + text, + value.lower()] + + +class PartitionTypeUuidQuotes(_PartitionTypeUuid): + def check_line(self, lineno, text): + if self.get_value(text).startswith(("\"", "'")): + return ["{}:{}: partition-type-uuid must not be quoted ({}#writing-genimage-cfg)" + .format(self.filename, lineno, self.url_to_manual), + text] + + +class PartitionTypeUuidShortcut(_PartitionTypeUuid): + def check_line(self, lineno, text): + shortcut = self.SHORTCUTS.get(self.get_value(text).strip("\"'").lower()) + if shortcut: + return ["{}:{}: use the {} shortcut for partition-type-uuid ({}#writing-genimage-cfg)" + .format(self.filename, lineno, shortcut, self.url_to_manual), + text] diff --git a/utils/checkpackagelib/test_lib_genimage.py b/utils/checkpackagelib/test_lib_genimage.py new file mode 100644 index 0000000000..ff2c14cff2 --- /dev/null +++ b/utils/checkpackagelib/test_lib_genimage.py @@ -0,0 +1,623 @@ +import pytest +import checkpackagelib.test_util as util +import checkpackagelib.lib_genimage as m + + +CommentUnits = [ + ('empty file', + 'any', + '', + []), + ('good', + 'any', + '# 1MB - 8KB, 2 GB\n', + []), + ('no comment', + 'any', + '\tsize = 30M\n', + []), + ('not a size', + 'any', + '# 1 kernel, 2 Macs, i.MX6\n', + []), + ('in a string', + 'any', + '\timage = "a#4M"\n', + []), + ('lower-case', + 'any', + '# 1 kB free\n', + [['any:1: use GB, MB or KB in comments (url#writing-genimage-cfg)', + '# 1 kB free\n']]), + ('no B', + 'any', + '\tsize = 1K # 16M\n', + [['any:1: use GB, MB or KB in comments (url#writing-genimage-cfg)', + '\tsize = 1K # 16M\n']]), + ('mixed', + 'any', + '# 1MB + 16mb\n', + [['any:1: use GB, MB or KB in comments (url#writing-genimage-cfg)', + '# 1MB + 16mb\n']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', CommentUnits) +def test_CommentUnits(testname, filename, string, expected): + warnings = util.check_file(m.CommentUnits, filename, string) + assert warnings == expected + + +CurlyBrackets = [ + ('empty file', + 'any', + '', + []), + ('good', + 'any', + 'image a {\n' + '\thdimage {\n' + '\t}\n' + '}\n', + []), + ('list', + 'any', + 'files = {\n' + '"a",\n' + '}\n', + []), + ('list on one line', + 'any', + 'holes = {"(440; 512)"}\n', + []), + ('list closed after last item', + 'any', + 'files = {\n' + '"a" }\n', + []), + ('brackets in string and comment', + 'any', + 'image = "}{" # }{\n', + []), + ('comment after brackets', + 'any', + 'image a { # x\n' + '} # y\n', + []), + ('open on next line', + 'any', + 'image a\n' + '{\n' + '}\n', + [['any:2: open curly bracket must be on the same line as the name (url#writing-genimage-cfg)', + '{\n']]), + ('empty node', + 'any', + 'flash {}\n', + [['any:1: closing curly bracket must be alone on its line (url#writing-genimage-cfg)', + 'flash {}\n']]), + ('close after option', + 'any', + 'image a {\n' + '\tsize = 1M }\n', + [['any:2: closing curly bracket must be alone on its line (url#writing-genimage-cfg)', + '\tsize = 1M }\n']]), + ('content after open', + 'any', + 'image a { size = 1M\n' + '}\n', + [['any:1: node content must start on a new line (url#writing-genimage-cfg)', + 'image a { size = 1M\n']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', CurlyBrackets) +def test_CurlyBrackets(testname, filename, string, expected): + warnings = util.check_file(m.CurlyBrackets, filename, string) + assert warnings == expected + + +EmptyLineAfterNode = [ + ('empty file', + 'any', + '', + []), + ('good', + 'any', + 'image a {\n' + '\tvfat {\n' + '\t}\n' + '\n' + '\tsize = 1M\n' + '}\n' + '\n' + 'image b {\n' + '}\n', + []), + ('last node', + 'any', + 'image a {\n' + '\tvfat {\n' + '\t}\n' + '}\n', + []), + ('list', + 'any', + 'vfat {\n' + '\tfiles = {\n' + '\t"a"\n' + '\t}\n' + '\tlabel = "x"\n' + '}\n', + []), + ('option', + 'any', + 'image a {\n' + '\tvfat {\n' + '\t}\n' + '\tsize = 1M\n' + '}\n', + [['any:4: missing empty line after the previous node (url#writing-genimage-cfg)', + '\tsize = 1M\n']]), + ('node', + 'any', + 'vfat {\n' + '\tfile a {\n' + '\t}\n' + '\tfile b {\n' + '\t}\n' + '}\n', + [['any:4: missing empty line after the previous node (url#writing-genimage-cfg)', + '\tfile b {\n']]), + ('comment', + 'any', + 'image a {\n' + '}\n' + '# x\n', + [['any:3: missing empty line after the previous node (url#writing-genimage-cfg)', + '# x\n']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', EmptyLineAfterNode) +def test_EmptyLineAfterNode(testname, filename, string, expected): + warnings = util.check_file(m.EmptyLineAfterNode, filename, string) + assert warnings == expected + + +Filename = [ + ('genimage.cfg', + 'board/x/genimage.cfg', + '', + []), + ('genimage-efi.cfg', + 'board/x/genimage-efi.cfg', + '', + []), + ('genimage_sdcard.cfg', + 'board/x/genimage_sdcard.cfg', + '', + []), + ('wrong prefix', + 'board/x/sdcard-genimage.cfg', + '', + [['board/x/sdcard-genimage.cfg:0: filename must begin with genimage (url#writing-genimage-cfg)']]), + ('only the directory', + 'genimage/a.cfg', + '', + [['genimage/a.cfg:0: filename must begin with genimage (url#writing-genimage-cfg)']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', Filename) +def test_Filename(testname, filename, string, expected): + warnings = util.check_file(m.Filename, filename, string) + assert warnings == expected + + +GptPartitionTypeUuid = [ + ('empty file', + 'any', + '', + []), + ('good', + 'any', + 'image a {\n' + '\thdimage {\n' + '\t\tpartition-table-type = "gpt"\n' + '\t}\n' + '\n' + '\tpartition b {\n' + '\t\tpartition-type-uuid = U\n' + '\t}\n' + '}\n', + []), + ('mbr', + 'any', + 'image a {\n' + '\thdimage {\n' + '\t}\n' + '\tpartition b {\n' + '\t\tpartition-type = 0xC\n' + '\t}\n' + '}\n', + []), + ('not in partition table', + 'any', + 'image a {\n' + '\thdimage {\n' + '\t\tpartition-table-type = "gpt"\n' + '\t}\n' + '\n' + '\tpartition b {\n' + '\t\tin-partition-table = "no"\n' + '\t}\n' + '}\n', + []), + ('gpt only in first image', + 'any', + 'image a {\n' + '\thdimage {\n' + '\t\tpartition-table-type = "gpt"\n' + '\t}\n' + '\n' + '}\n' + 'image a {\n' + '\thdimage {\n' + '\t}\n' + '\tpartition b {\n' + '\t}\n' + '}\n', + []), + ('missing', + 'any', + 'image a {\n' + '\thdimage {\n' + '\t\tpartition-table-type = "gpt"\n' + '\t}\n' + '\n' + '\tpartition b {\n' + '\t\timage = "x"\n' + '\t}\n' + '\tpartition c {\n' + '\t\tpartition-type-uuid = L\n' + '\t}\n' + '\tpartition d {\n' + '\t}\n' + '}\n', + [['any:6: GPT partition without partition-type-uuid: b, d (url#writing-genimage-cfg)', + '\tpartition b {\n']]), + ('hdimage last', + 'any', + 'image a {\n' + '\tpartition b {\n' + '\t}\n' + '\thdimage {\n' + '\t\tpartition-table-type = "gpt"\n' + '\t}\n' + '\n' + '}\n', + [['any:2: GPT partition without partition-type-uuid: b (url#writing-genimage-cfg)', + '\tpartition b {\n']]), + ('deprecated gpt option', + 'any', + 'image a {\n' + '\thdimage {\n' + '\t\tgpt = true\n' + '\t}\n' + '\tpartition b {\n' + '\t}\n' + '}\n', + [['any:5: GPT partition without partition-type-uuid: b (url#writing-genimage-cfg)', + '\tpartition b {\n']]), + ('explicitly in partition table', + 'any', + 'image a {\n' + '\thdimage {\n' + '\t\tpartition-table-type = "gpt"\n' + '\t}\n' + '\n' + '\tpartition b {\n' + '\t\tin-partition-table = true\n' + '\t}\n' + '}\n', + [['any:6: GPT partition without partition-type-uuid: b (url#writing-genimage-cfg)', + '\tpartition b {\n']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', GptPartitionTypeUuid) +def test_GptPartitionTypeUuid(testname, filename, string, expected): + warnings = util.check_file(m.GptPartitionTypeUuid, filename, string) + assert warnings == expected + + +Indent = [ + ('empty file', + 'any', + '', + []), + ('good', + 'any', + '# x\n' + 'image a {\n' + '\tvfat {\n' + '\t\tfiles = {\n' + '\t\t\t"a",\n' + '\t\t}\n' + '\t}\n' + '\n' + '\t# x\n' + '\tsize = 1M\n' + '}\n', + []), + ('spaces', + 'any', + 'image a {\n' + ' size = 1M\n' + '}\n', + [['any:2: should be indented with 1 tab(s) (url#writing-genimage-cfg)', + ' size = 1M\n']]), + ('tabs and space', + 'any', + 'image a {\n' + '\t size = 1M\n' + '}\n', + [['any:2: should be indented with 1 tab(s) (url#writing-genimage-cfg)', + '\t size = 1M\n']]), + ('too many', + 'any', + '\timage a {\n' + '}\n', + [['any:1: should be indented with 0 tab(s) (url#writing-genimage-cfg)', + '\timage a {\n']]), + ('closing', + 'any', + 'image a {\n' + '\tvfat {\n' + '}\n' + '}\n', + [['any:3: should be indented with 1 tab(s) (url#writing-genimage-cfg)', + '}\n']]), + ('comment', + 'any', + 'image a {\n' + '# x\n' + '}\n', + [['any:2: should be indented with 1 tab(s) (url#writing-genimage-cfg)', + '# x\n']]), + ('unbalanced', + 'any', + '}\n' + '}\n', + []), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', Indent) +def test_Indent(testname, filename, string, expected): + warnings = util.check_file(m.Indent, filename, string) + assert warnings == expected + + +OptionAssignment = [ + ('empty file', + 'any', + '', + []), + ('good', + 'any', + '\tsize = 1M\n' + '\tfiles = {\n', + []), + ('append', + 'any', + '\tfiles += {\n', + []), + ('equal in string', + 'any', + '\texec-pre = "a=b"\n', + []), + ('in comment', + 'any', + '# a=b\n', + []), + ('in list', + 'any', + '\t\t"a=b",\n', + []), + ('no spaces', + 'any', + '\timage="a"\n', + [["any:1: use one space before and after '=' (url#writing-genimage-cfg)", + '\timage="a"\n']]), + ('two spaces after', + 'any', + '\tsize = 1M\n', + [["any:1: use one space before and after '=' (url#writing-genimage-cfg)", + '\tsize = 1M\n']]), + ('tab before', + 'any', + '\tsize\t= 1M\n', + [["any:1: use one space before and after '=' (url#writing-genimage-cfg)", + '\tsize\t= 1M\n']]), + ('no space before', + 'any', + '\tfiles= {\n', + [["any:1: use one space before and after '=' (url#writing-genimage-cfg)", + '\tfiles= {\n']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', OptionAssignment) +def test_OptionAssignment(testname, filename, string, expected): + warnings = util.check_file(m.OptionAssignment, filename, string) + assert warnings == expected + + +PartitionTypeUuidCase = [ + ('empty file', + 'any', + '', + []), + ('lower-case', + 'any', + 'partition-type-uuid = 2e54b353-1271-4842-806f-e436d6af6985\n', + []), + ('shortcut', + 'any', + 'partition-type-uuid = U\n', + []), + ('has a shortcut', + 'any', + 'partition-type-uuid = 0FC63DAF-8483-4772-8E79-3D69D8477DE4\n', + []), + ('upper-case', + 'any', + 'partition-type-uuid = 2E54B353-1271-4842-806F-E436D6AF6985\n', + [['any:1: partition-type-uuid must be in lower-case (url#writing-genimage-cfg)', + 'partition-type-uuid = 2E54B353-1271-4842-806F-E436D6AF6985\n', + '2e54b353-1271-4842-806f-e436d6af6985']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', PartitionTypeUuidCase) +def test_PartitionTypeUuidCase(testname, filename, string, expected): + warnings = util.check_file(m.PartitionTypeUuidCase, filename, string) + assert warnings == expected + + +PartitionTypeUuidQuotes = [ + ('empty file', + 'any', + '', + []), + ('good', + 'any', + 'partition-type-uuid = U\n', + []), + ('other option', + 'any', + 'partition-uuid = "U"\n', + []), + ('quoted', + 'any', + 'partition-type-uuid = "U"\n', + [['any:1: partition-type-uuid must not be quoted (url#writing-genimage-cfg)', + 'partition-type-uuid = "U"\n']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', PartitionTypeUuidQuotes) +def test_PartitionTypeUuidQuotes(testname, filename, string, expected): + warnings = util.check_file(m.PartitionTypeUuidQuotes, filename, string) + assert warnings == expected + + +PartitionTypeUuidShortcut = [ + ('empty file', + 'any', + '', + []), + ('shortcut', + 'any', + 'partition-type-uuid = U\n', + []), + ('no shortcut', + 'any', + 'partition-type-uuid = 2e54b353-1271-4842-806f-e436d6af6985\n', + []), + ('placeholder', + 'any', + 'partition-type-uuid = %UUID%\n', + []), + ('letter', + 'any', + 'partition-type-uuid = c12a7328-f81f-11d2-ba4b-00a0c93ec93b\n', + [['any:1: use the U shortcut for partition-type-uuid (url#writing-genimage-cfg)', + 'partition-type-uuid = c12a7328-f81f-11d2-ba4b-00a0c93ec93b\n']]), + ('upper-case', + 'any', + 'partition-type-uuid = 0FC63DAF-8483-4772-8E79-3D69D8477DE4\n', + [['any:1: use the L shortcut for partition-type-uuid (url#writing-genimage-cfg)', + 'partition-type-uuid = 0FC63DAF-8483-4772-8E79-3D69D8477DE4\n']]), + ('root', + 'any', + 'partition-type-uuid = b921b045-1df0-41c3-af44-4c6f280d3fae\n', + [['any:1: use the root-arm64 shortcut for partition-type-uuid (url#writing-genimage-cfg)', + 'partition-type-uuid = b921b045-1df0-41c3-af44-4c6f280d3fae\n']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', PartitionTypeUuidShortcut) +def test_PartitionTypeUuidShortcut(testname, filename, string, expected): + warnings = util.check_file(m.PartitionTypeUuidShortcut, filename, string) + assert warnings == expected + + +SizeNotation = [ + ('empty file', + 'any', + '', + []), + ('suffixes', + 'any', + 'size = 1G\n' + 'offset = 1M\n' + 'size = 1K # x\n', + []), + ('zero', + 'any', + 'offset = 0\n', + []), + ('hexadecimal', + 'any', + 'offset = 0x201\n', + []), + ('byte count', + 'any', + 'offset = 512\n', + []), + ('percentage', + 'any', + 'size = 50%\n', + []), + ('placeholder', + 'any', + 'offset = %IMXOFFSET%\n', + []), + ('other option', + 'any', + 'pebsize = 65536\n', + []), + ('quoted', + 'any', + 'size = "1M"\n', + []), + ('lower-case', + 'any', + 'size = 1k\n', + [['any:1: use G, M, K, a 0x prefix or a byte count (url#writing-genimage-cfg)', + 'size = 1k\n']]), + ('unit', + 'any', + 'size = 1MB\n', + [['any:1: use G, M, K, a 0x prefix or a byte count (url#writing-genimage-cfg)', + 'size = 1MB\n']]), + ('useless byte count', + 'any', + 'offset = 1024\n', + [['any:1: use 1K instead of 1024 (url#writing-genimage-cfg)', + 'offset = 1024\n']]), + ('useless hexadecimal', + 'any', + 'offset = 0x100000\n', + [['any:1: use 1M instead of 0x100000 (url#writing-genimage-cfg)', + 'offset = 0x100000\n']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', SizeNotation) +def test_SizeNotation(testname, filename, string, expected): + warnings = util.check_file(m.SizeNotation, filename, string) + assert warnings == expected -- 2.47.3 _______________________________________________ buildroot mailing list buildroot@buildroot.org https://lists.buildroot.org/mailman/listinfo/buildroot