From patchwork Fri Dec 21 03:12:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 154370 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp417344ljp; Thu, 20 Dec 2018 19:13:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN6wJ7CL2lm3bBRSfoXhlv6Tw+KT+ZRP35BbQXYezJgJ9lkoJuIauWOmcNS0IMUSB8dLhH7V X-Received: by 2002:a17:902:930b:: with SMTP id bc11mr822409plb.17.1545361986362; Thu, 20 Dec 2018 19:13:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545361986; cv=none; d=google.com; s=arc-20160816; b=vW56APo96gTA0z1W7qCHXx/PF6Y4aZevhGpuilkm5QtoHVzpTlpT1OyPs4/g5zQc/A 3g7b9mBjcWPOJx9qLtZizaHDMkwM1HjqfMj3LWA0utcGKqtdM/ouAVybofhF0GETrqfU RKaMVD3/OYQdiLukdyBfpssOi4ey+u908trL11v+hHBtF8cgUphJNNpiAphm2OC7dVq1 99F553PVwse14BOmdgLfryMseFwFgM9l/xFlfAsxGGRVnkaqi1Dn0SqSSvOBJGeU3nTF Xhl80yNngsPxWGKPR5uni/PAh3lZKi3fBQI7YrYLx7fVMx+R3Pd8if9INqnxpkLxhjvC fNuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=7BUcAm2kzh0Oah2K4UpaMEeLxvXGjrdT7tbi0/n1Edg=; b=vgQP0RvgOmmmjD3E/sZIicSi1e6LtGI2WzW5aECiuPRjiFHnJ+brmMsBtWjdQHxTyY T2yiYaa4H9+yv9sk5qhjlRA8lkI2j24iX7vEWyqQd6ZkxOwbkaK8NXS0HTSjl+dasKCx bWuAcRGjpjc63JJwA1pAqpQSS8V4bPvO8oBBpk7j2nPIbEpcgy1iMkUPmWBC+VSw82x/ 3OL6DQ0mf0SlcF5m8FzCikWEtxf//ekPtGgO7UEl2Rf605cFFkdRZViTKveRPmADGrFG gvdkYUPjcKbp5lfC8uxGQ8o1y4JR1nNTIbJa0TLmeMyxDvqqWQE+kUIYZ46yjV09RNP+ Peqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=gnVyb9KH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si19788863pgg.1.2018.12.20.19.13.06; Thu, 20 Dec 2018 19:13:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=gnVyb9KH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390883AbeLUDND (ORCPT + 31 others); Thu, 20 Dec 2018 22:13:03 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:53266 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731899AbeLUDM7 (ORCPT ); Thu, 20 Dec 2018 22:12:59 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-12.nifty.com with ESMTP id wBL3Ci1q003819; Fri, 21 Dec 2018 12:12:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com wBL3Ci1q003819 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1545361965; bh=7BUcAm2kzh0Oah2K4UpaMEeLxvXGjrdT7tbi0/n1Edg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gnVyb9KH6yRmJOX41ZPUv0rd2BP3fB2xGmD5eq2LQDmAcuLqczoe2QoICGZwUJKiV OUw16z3JdKl3BSKtfxvlxWkZgHRckpyHENNOQuJZ6qowoGRAXA2hrXyfQQlMCHRjwh 6TaYsoBtn/VEGEPwaFzM2zLNz90bJb2T4U60S4Ue0VUnpE+UCrmcAPxfinAg2aB/VV olZkbE/HrPNF4Jna61XSI2JK3RwE3IyvPTUhK6XRSXjp5+mO0gmOFDl6tacHgI+6XD ctgB9eTFzWaytP8eHHi7kU3T/LKv0K/oaDpVAOjPrfMnQLVOniBC7ZniraYD8FUgIg CX5qgEySgNvmQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] firmware: rewrite Makefile Date: Fri, 21 Dec 2018 12:12:41 +0900 Message-Id: <1545361961-31990-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545361961-31990-1-git-send-email-yamada.masahiro@socionext.com> References: <1545361961-31990-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Clean up the Makefile. Equivalent *.gen.S files are produced. - Use filechk to remove ugly wordsize_deps - Get FWNAME, FWSTR, ASM_WORD, ASM_ALIGN, and PROGBITS out of the recipe for readability - Move mkdir into the recipe - Clean up generated directories by 'make clean' Signed-off-by: Masahiro Yamada --- For this patch to work correctly, the following prerequisite is necessary: https://patchwork.kernel.org/patch/10707461/ So, I will queue this series to kbuild tree. BTW, my next plan is to move firmware/ to more relevant place, for example, drivers/base/firmware_loader/builtin. firmware/Makefile | 89 ++++++++++++++++++++++--------------------------------- 1 file changed, 35 insertions(+), 54 deletions(-) -- 2.7.4 diff --git a/firmware/Makefile b/firmware/Makefile index 2964138..18d1c84 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,61 +1,42 @@ # SPDX-License-Identifier: GPL-2.0 -# -# kbuild file for firmware/ -# -# Create $(fwabs) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a +# Create $(fwdir) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a # leading /, it's relative to $(srctree). fwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR)) -fwabs := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir)) - -fw-external-y := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE)) - -quiet_cmd_fwbin = MK_FW $@ - cmd_fwbin = FWNAME="$(patsubst firmware/%.gen.S,%,$@)"; \ - FWSTR="$(subst /,_,$(subst .,_,$(subst -,_,$(patsubst \ - firmware/%.gen.S,%,$@))))"; \ - ASM_WORD=$(if $(CONFIG_64BIT),.quad,.long); \ - ASM_ALIGN=$(if $(CONFIG_64BIT),3,2); \ - PROGBITS=$(if $(CONFIG_ARM),%,@)progbits; \ - echo "/* Generated by firmware/Makefile */" > $@;\ - echo " .section .rodata" >>$@;\ - echo " .p2align $${ASM_ALIGN}" >>$@;\ - echo "_fw_$${FWSTR}_bin:" >>$@;\ - echo " .incbin \"$(2)\"" >>$@;\ - echo "_fw_end:" >>$@;\ - echo " .section .rodata.str,\"aMS\",$${PROGBITS},1" >>$@;\ - echo " .p2align $${ASM_ALIGN}" >>$@;\ - echo "_fw_$${FWSTR}_name:" >>$@;\ - echo " .string \"$$FWNAME\"" >>$@;\ - echo " .section .builtin_fw,\"a\",$${PROGBITS}" >>$@;\ - echo " .p2align $${ASM_ALIGN}" >>$@;\ - echo " $${ASM_WORD} _fw_$${FWSTR}_name" >>$@;\ - echo " $${ASM_WORD} _fw_$${FWSTR}_bin" >>$@;\ - echo " $${ASM_WORD} _fw_end - _fw_$${FWSTR}_bin" >>$@; - -# One of these files will change, or come into existence, whenever -# the configuration changes between 32-bit and 64-bit. The .S files -# need to change when that happens. -wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \ - include/config/ppc32.h include/config/ppc64.h \ - include/config/superh32.h include/config/superh64.h \ - include/config/x86_32.h include/config/x86_64.h \ - firmware/Makefile) - -$(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \ - include/config/extra/firmware/dir.h - $(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@)) +fwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir)) + +obj-y := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE))) + +FWNAME = $(patsubst $(obj)/%.gen.S,%,$@) +FWSTR = $(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME)))) +ASM_WORD = $(if $(CONFIG_64BIT),.quad,.long) +ASM_ALIGN = $(if $(CONFIG_64BIT),3,2) +PROGBITS = $(if $(CONFIG_ARM),%,@)progbits + +filechk_fwbin = { \ + echo "/* Generated by $(src)/Makefile */" ;\ + echo " .section .rodata" ;\ + echo " .p2align $(ASM_ALIGN)" ;\ + echo "_fw_$(FWSTR)_bin:" ;\ + echo " .incbin \"$(fwdir)/$(FWNAME)\"" ;\ + echo "_fw_end:" ;\ + echo " .section .rodata.str,\"aMS\",$(PROGBITS),1" ;\ + echo " .p2align $(ASM_ALIGN)" ;\ + echo "_fw_$(FWSTR)_name:" ;\ + echo " .string \"$(FWNAME)\"" ;\ + echo " .section .builtin_fw,\"a\",$(PROGBITS)" ;\ + echo " .p2align $(ASM_ALIGN)" ;\ + echo " $(ASM_WORD) _fw_$(FWSTR)_name" ;\ + echo " $(ASM_WORD) _fw_$(FWSTR)_bin" ;\ + echo " $(ASM_WORD) _fw_end - _fw_$(FWSTR)_bin" ;\ +} + +$(obj)/%.gen.S: FORCE + @mkdir -p $(dir $@) + $(call filechk,fwbin) # The .o files depend on the binaries directly; the .S files don't. -$(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/% - -obj-y += $(patsubst %,%.gen.o, $(fw-external-y)) - -ifeq ($(KBUILD_SRC),) -# Makefile.build only creates subdirectories for O= builds, but external -# firmware might live outside the kernel source tree -_dummy := $(foreach d,$(addprefix $(obj)/,$(dir $(fw-external-y))), $(shell [ -d $(d) ] || mkdir -p $(d))) -endif +$(addprefix $(obj)/, $(obj-y)): $(obj)/%.gen.o: $(fwdir)/% -targets := $(patsubst $(obj)/%,%, \ - $(shell find $(obj) -name \*.gen.S 2>/dev/null)) +targets := $(shell cd $(obj) && find * -name '*.gen.S') +clean-dirs := $(shell cd $(obj) && find * -maxdepth 0 -type d)