From patchwork Tue Aug 1 17:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Masney X-Patchwork-Id: 13337125 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFE6FC001DF for ; Tue, 1 Aug 2023 17:50:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231478AbjHARu0 (ORCPT ); Tue, 1 Aug 2023 13:50:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231389AbjHARuZ (ORCPT ); Tue, 1 Aug 2023 13:50:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 330C41FD6 for ; Tue, 1 Aug 2023 10:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690912179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GYUWXb5VBW1ndzfLEcQ3Dy13isLM6VUOP91Qx2qKRhg=; b=KTpjpZR+i/NGJdjx3AOW/D2UJSdcbka5+uG6x6z6w84iasxDUp3cWVakMRLwXVSSJ70Ulp 3IoBmOUbTWCTt1EdZSoKACqHCSjP/lphF8giGQdcgqsgwR3DTUNZ5Sho3oLPt6x5wRaHnr 0Z+5YRYjEfEKUFSePJWxUgIIlkq1qII= Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-339-A79MoLrIPOCsaZxHmjxjCA-1; Tue, 01 Aug 2023 13:49:38 -0400 X-MC-Unique: A79MoLrIPOCsaZxHmjxjCA-1 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-5847479b559so68633207b3.1 for ; Tue, 01 Aug 2023 10:49:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690912177; x=1691516977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GYUWXb5VBW1ndzfLEcQ3Dy13isLM6VUOP91Qx2qKRhg=; b=UdMeBlwrz+qZaVq1dTxTBFgEOIx7HQKzNPpSgixcHzGANWkwLo7JoKNRHsp58VoR2Z zwgrInxid+BY3Vk3N8aeTYNu3uE9N/JR5F9Xe6Q0ugduBhf6GebbNWvh06A+WIPJmr8k JfxOnV4CfA4y/RuCVmYaXZQLnW/VdU+AHcosO+poXzWvjXBwYhxug96q8QHsDWxv8STd jDT2ugHo7GQ6YB4Ok25Wb4jAOTPzM0WLMUBUwzBxaVHYkunjg53usob/0pTDeEt6XAHP bq/FOl68fPEGan+OEJPvuSLTS44EMSSYbfUdujXZoLcA8o4NULgNYutYRnUZBqVIwsjT p0Xw== X-Gm-Message-State: ABy/qLauXpKJqZnSNUJZWQHQ6wA+LdoRQMGXtj/dCpw90n9llV0PQj+o fy4Yunz5hAwQe3wdYdsF8nqJko6vYBQIWhOr+xClI4zDkHXuIGjvkgkonXNT0Lj0+YeZCdBHdax XSjjn2Sq6/04D656jnO0PYqRl X-Received: by 2002:a81:83cf:0:b0:570:6fbd:2daf with SMTP id t198-20020a8183cf000000b005706fbd2dafmr16026116ywf.37.1690912177471; Tue, 01 Aug 2023 10:49:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlEx/rTzRu8VRjCf/p3Bv17M0mRYJt5gkfqTtA7hsbvwsSFovUUUg5LKF0PGAKJJ27eO3PqixA== X-Received: by 2002:a81:83cf:0:b0:570:6fbd:2daf with SMTP id t198-20020a8183cf000000b005706fbd2dafmr16026104ywf.37.1690912177215; Tue, 01 Aug 2023 10:49:37 -0700 (PDT) Received: from brian-x1.. ([2600:381:222b:e67:295d:9324:c84:3382]) by smtp.gmail.com with ESMTPSA id k187-20020a0dc8c4000000b005773afca47bsm3881728ywd.27.2023.08.01.10.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 10:49:36 -0700 (PDT) From: Brian Masney To: masahiroy@kernel.org Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: [PATCH 1/2] scripts: add mod-to-kconfig.sh Date: Tue, 1 Aug 2023 13:49:21 -0400 Message-ID: <20230801174922.333700-2-bmasney@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801174922.333700-1-bmasney@redhat.com> References: <20230801174922.333700-1-bmasney@redhat.com> MIME-Version: 1.0 Content-type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Add a useful script that can be used to convert a kernel module path to the relevant Kconfig symbol name. Examples showing how to use this is in the help at the top of the script. Signed-off-by: Brian Masney --- scripts/kconfig/mod-to-kconfig.sh | 93 +++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 scripts/kconfig/mod-to-kconfig.sh diff --git a/scripts/kconfig/mod-to-kconfig.sh b/scripts/kconfig/mod-to-kconfig.sh new file mode 100755 index 000000000000..1b69b638ebf5 --- /dev/null +++ b/scripts/kconfig/mod-to-kconfig.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2023 Red Hat, Inc. All Rights Reserved. +# Written by Brian Masney +# +# This script takes as input one or more kernel module names, and outputs +# the relevant Kconfig symbol name. This script was originally intended to help +# identify which Kconfig options are enabled inside an initramfs. +# +# x1:~/src/linux$ find /usr/lib/modules/`uname -r` -name *.ko.xz | \ +# ./scripts/kconfig/mod-to-kconfig.sh +# CONFIG_CRYPTO_USER +# CONFIG_CRYPTO_ESSIV +# CONFIG_CRYPTO_CHACHA20 +# CONFIG_CRYPTO_TWOFISH +# ... +# +# You can also use this to walk the modules.builtin file: +# +# x1:~/src/linux$ ./scripts/kconfig/mod-to-kconfig.sh < \ +# /usr/lib/modules/`uname -r`/modules.builtin +# +# Pipe the output of this script into scripts/kconfig/lookup.sh if you want to +# view the full Kconfig entries. +# +# Note that there is a fair bit of variability in the Makefiles across the +# kernel and this script won't match everything. It's only been written to +# cover the 95% use case. + +process_module() +{ + # We may have a full path, like /usr/lib/modules/`uname -r`/kernel/...`, + # or a relative path, like kernel/... that's found in modules.builtin. + local DIR + DIR=$(dirname "$1") + if [[ "${DIR}" =~ ^/ ]] ; then + DIR=${DIR##*/kernel/} + else + DIR=${DIR##kernel/} + fi + + # Handle compressed module names + local MOD_NAME + MOD_NAME=$(basename "$1") + MOD_NAME="${MOD_NAME/.xz/}" # CONFIG_FW_LOADER_COMPRESS_XZ + MOD_NAME="${MOD_NAME/.zst/}" # CONFIG_FW_LOADER_COMPRESS_ZSTD + MOD_NAME="${MOD_NAME/.ko/}" + MOD_NAME="${MOD_NAME/.c/}" + + local MAKEFILE + MAKEFILE="${DIR}/Makefile" + if [ ! -f "${MAKEFILE}" ] ; then + echo "Skipping $1 since ${MAKEFILE} is not found" >&2 + return 1 + fi + + # There's probably a more elegant way you could do this with sed or awk, + # however personally I find this approach more readable in this + # particular case. + local CONFIG + CONFIG=$(grep --before-context=200 -w -E "${MOD_NAME}(\.o|/)" \ + "${DIR}/Makefile" | grep CONFIG_ | tail -n 1 | \ + awk -F\( '{print $2}' | awk -F\) '{print $1}') + if [ "${CONFIG}" = "" ] ; then + echo "Skipping $1 since CONFIG cannot be determined" >&2 + return 1 + fi + echo "${CONFIG}" +} + +# Run this script from the toplevel kernel source directory. +SCRIPT_PATH=$(readlink -f "$0") +cd "$(dirname "${SCRIPT_PATH}")/../.." || exit 1 + +RET=0 +if [[ $# == 0 ]] ; then + # Read module paths from stdin + while read -r MODULE_PATH ; do + if ! process_module "${MODULE_PATH}" ; then + RET=1 + fi + done +else + # Read module paths from the command line arguments + for NUM in $(seq 1 "$#") ; do + if ! process_module "${!NUM}" ; then + RET=1 + fi + done +fi + +exit "${RET}" From patchwork Tue Aug 1 17:49:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Masney X-Patchwork-Id: 13337127 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAA91C00528 for ; Tue, 1 Aug 2023 17:50:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231985AbjHARuk (ORCPT ); Tue, 1 Aug 2023 13:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231970AbjHARuf (ORCPT ); Tue, 1 Aug 2023 13:50:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 393ECE61 for ; Tue, 1 Aug 2023 10:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690912183; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c9F/mZ8r3UfV+OIZ7ILNLdJAv9iDV2O+GTrVi9NsxDI=; b=NmgGgBtTkEwQLV9xU/+IAs41LEO9M4WR70DHDbgyIjVKvaZWSSURYhuiLeNGPuMJrx8DNU qNcM5yC4sbeZSFCOzP4N5OhSL+QRlzuaJokm/lNENZDHxjY5h7GqaneyU1mIFWqIYil6VL V4aLyJMmsaKwVAi3yfGLfuyPrDo2n+U= Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-lJ4QiS8gMKOBahLBywOQgw-1; Tue, 01 Aug 2023 13:49:39 -0400 X-MC-Unique: lJ4QiS8gMKOBahLBywOQgw-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-583a89cccf6so54274007b3.1 for ; Tue, 01 Aug 2023 10:49:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690912179; x=1691516979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c9F/mZ8r3UfV+OIZ7ILNLdJAv9iDV2O+GTrVi9NsxDI=; b=dSnL+Md2Wz+kYVcC1f3Rk3Ls0fROfsGGgbueFyi2IWmxGifDs2hZQo5az8sfX83V/c aKojanT0xHEYobpVlGVmqHWAm3eUzrKr03VIl7A4rGmZP58eWpMy/0ejj3Bo81LOHGSq UKlzA2WUJ5nO0q8JgMDs/q0WhHlWiRTDyYHH/4QA2r39eoibRzkgBdIsNjgAEXZWVl2R ZFNpaI+IwD4ZGIgpP6i7UTBZcvHl5AXLtpgPtjInpVfOazZNvs79qOKXnZsMabXfXGqv mrEqsYcNVk92BHRpzr6u1im0pkU++094SZSSPbMuSPPY/8754UZBU3OLyjFPnPQ0pOmR hcUw== X-Gm-Message-State: ABy/qLbNSQUkAx2XD3H+Ud4PUm1uByqIZyml/KO/WcWerQPP5VBdqke9 nqEVyZBQnJ7npOFpLSB2jm/fWw/haPoxsDDSic9DAAXSDHw9PExtsjvIJrbG10+vBa8SB4IDmMx RfLbCBpWqufxZMLXlboh+Iv5Y X-Received: by 2002:a81:6c92:0:b0:583:d722:9ae9 with SMTP id h140-20020a816c92000000b00583d7229ae9mr11884617ywc.41.1690912179345; Tue, 01 Aug 2023 10:49:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlGKuCd2ijiy8jn5tU9B4qxUFyex8KCYNiPvYKYYRM54/JwQpKLWyFpWCyqJn+yuNOiafcQkBw== X-Received: by 2002:a81:6c92:0:b0:583:d722:9ae9 with SMTP id h140-20020a816c92000000b00583d7229ae9mr11884609ywc.41.1690912179086; Tue, 01 Aug 2023 10:49:39 -0700 (PDT) Received: from brian-x1.. ([2600:381:222b:e67:295d:9324:c84:3382]) by smtp.gmail.com with ESMTPSA id k187-20020a0dc8c4000000b005773afca47bsm3881728ywd.27.2023.08.01.10.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 10:49:38 -0700 (PDT) From: Brian Masney To: masahiroy@kernel.org Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: [PATCH 2/2] scripts: add kconfig lookup script Date: Tue, 1 Aug 2023 13:49:22 -0400 Message-ID: <20230801174922.333700-3-bmasney@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801174922.333700-1-bmasney@redhat.com> References: <20230801174922.333700-1-bmasney@redhat.com> MIME-Version: 1.0 Content-type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Add a script that allows looking up the full Kconfig entry based on the symbol name. Documentation and example usage is found at the top of the script itself. Signed-off-by: Brian Masney --- scripts/kconfig/lookup.sh | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 scripts/kconfig/lookup.sh diff --git a/scripts/kconfig/lookup.sh b/scripts/kconfig/lookup.sh new file mode 100755 index 000000000000..d1ff52b23835 --- /dev/null +++ b/scripts/kconfig/lookup.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2023 Red Hat, Inc. All Rights Reserved. +# Written by Brian Masney +# +# This script takes as input one or more Kconfig symbols and outputs the full +# entry from the Kconfig file. It can be invoked by reading a list of symbol +# names from either stdin or as command line arguments. Example output: +# +# x1:~/src/linux$ ./scripts/kconfig/lookup.sh TSL2772 SOUND +# # drivers/iio/light/Kconfig +# config TSL2772 +# tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors" +# depends on I2C +# help +# Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672, +# tmd2672, tsl2772, tmd2772 devices. +# Provides iio_events and direct access via sysfs. +# +# # arch/um/drivers/Kconfig +# config SOUND +# tristate +# default UML_SOUND +# +# # sound/Kconfig +# menuconfig SOUND +# tristate "Sound card support" +# depends on HAS_IOMEM +# help +# If you have a sound card in your computer, i.e. if it can say more +# than an occasional beep, say Y. + + +process_kconfig() +{ + KCONFIG="${1/CONFIG_/}" + + FOUND=0 + for KCONFIG_FILE in $(git grep -E "^(config|menuconfig) ${KCONFIG}$" | \ + awk -F: '{print $1}') ; do + echo "# ${KCONFIG_FILE}" + awk "/^(config|menuconfig) ${KCONFIG}$/{ m=1; print; next; } \ + /^(choice|comment|config|end|if|menuconfig|source)/ { m=0; } m" \ + "${KCONFIG_FILE}" + FOUND=1 + done + + if [[ "${FOUND}" = "0" ]] ; then + echo "Skipping ${KCONFIG} since Kconfig symbol is not found" >&2 + return 1 + fi + +} + +# Run this script from the toplevel kernel source directory. +SCRIPT_PATH=$(readlink -f "$0") +cd "$(dirname "${SCRIPT_PATH}")/../.." || exit 1 + +RET=0 +if [[ $# == 0 ]] ; then + # Read Kconfig names from stdin + while read -r KCONFIG ; do + if ! process_kconfig "${KCONFIG}" ; then + RET=1 + fi + done +else + # Read Kconfig names from the command line arguments + for NUM in $(seq 1 "$#") ; do + if ! process_kconfig "${!NUM}" ; then + RET=1 + fi + done +fi + +exit "${RET}"