mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	firmware: Simplify directory creation
When building the firmware blobs, use a simple loop to create directories in $(objtree), like in Makefile.build. This simplifies the rules and also makes it possible to set $(objtree) to '.' later. Before this change, a dependency on $(objtree)/<dir> would be satisfied by <dir> in $(srctree). When installing the firmware blobs, call mkdir like in Makefile.modinst. Cc: David Woodhouse <dwmw2@infradead.org> Acked-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Michal Marek <mmarek@suse.cz>
This commit is contained in:
		
							parent
							
								
									3fbb43df98
								
							
						
					
					
						commit
						5180d5f483
					
				
					 2 changed files with 16 additions and 38 deletions
				
			
		| 
						 | 
					@ -138,12 +138,6 @@ fw-shipped-$(CONFIG_YAM) += yam/1200.bin yam/9600.bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fw-shipped-all := $(fw-shipped-y) $(fw-shipped-m) $(fw-shipped-)
 | 
					fw-shipped-all := $(fw-shipped-y) $(fw-shipped-m) $(fw-shipped-)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Directories which we _might_ need to create, so we have a rule for them.
 | 
					 | 
				
			||||||
firmware-dirs := $(sort $(addprefix $(objtree)/$(obj)/,$(dir $(fw-external-y) $(fw-shipped-all))))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
quiet_cmd_mkdir = MKDIR   $(patsubst $(objtree)/%,%,$@)
 | 
					 | 
				
			||||||
      cmd_mkdir = mkdir -p $@
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
quiet_cmd_ihex  = IHEX    $@
 | 
					quiet_cmd_ihex  = IHEX    $@
 | 
				
			||||||
      cmd_ihex  = $(OBJCOPY) -Iihex -Obinary $< $@
 | 
					      cmd_ihex  = $(OBJCOPY) -Iihex -Obinary $< $@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -184,21 +178,10 @@ wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
 | 
				
			||||||
		include/config/superh32.h include/config/superh64.h \
 | 
							include/config/superh32.h include/config/superh64.h \
 | 
				
			||||||
		include/config/x86_32.h include/config/x86_64.h)
 | 
							include/config/x86_32.h include/config/x86_64.h)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Workaround for make < 3.81, where .SECONDEXPANSION doesn't work.
 | 
					$(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps)
 | 
				
			||||||
# It'll end up depending on these targets, so make them a PHONY rule which
 | 
					 | 
				
			||||||
# depends on _all_ the directories in $(firmware-dirs), and it'll work out OK.
 | 
					 | 
				
			||||||
PHONY += $(objtree)/$$(%) $(objtree)/$(obj)/$$(%)
 | 
					 | 
				
			||||||
$(objtree)/$$(%) $(objtree)/$(obj)/$$(%): $(firmware-dirs)
 | 
					 | 
				
			||||||
	@true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# For the $$(dir %) trick, where we need % to be expanded first.
 | 
					 | 
				
			||||||
.SECONDEXPANSION:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps) \
 | 
					 | 
				
			||||||
		| $(objtree)/$$(dir %)
 | 
					 | 
				
			||||||
	$(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
 | 
						$(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
 | 
				
			||||||
$(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \
 | 
					$(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \
 | 
				
			||||||
		include/config/extra/firmware/dir.h | $(objtree)/$$(dir %)
 | 
							include/config/extra/firmware/dir.h
 | 
				
			||||||
	$(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@))
 | 
						$(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# The .o files depend on the binaries directly; the .S files don't.
 | 
					# The .o files depend on the binaries directly; the .S files don't.
 | 
				
			||||||
| 
						 | 
					@ -207,7 +190,7 @@ $(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/%
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# .ihex is used just as a simple way to hold binary files in a source tree
 | 
					# .ihex is used just as a simple way to hold binary files in a source tree
 | 
				
			||||||
# where binaries are frowned upon. They are directly converted with objcopy.
 | 
					# where binaries are frowned upon. They are directly converted with objcopy.
 | 
				
			||||||
$(obj)/%: $(obj)/%.ihex | $(objtree)/$(obj)/$$(dir %)
 | 
					$(obj)/%: $(obj)/%.ihex
 | 
				
			||||||
	$(call cmd,ihex)
 | 
						$(call cmd,ihex)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Don't depend on ihex2fw if we're installing and it already exists.
 | 
					# Don't depend on ihex2fw if we're installing and it already exists.
 | 
				
			||||||
| 
						 | 
					@ -226,16 +209,13 @@ endif
 | 
				
			||||||
# is actually meaningful, because the firmware has to be loaded in a certain
 | 
					# is actually meaningful, because the firmware has to be loaded in a certain
 | 
				
			||||||
# order rather than as a single binary blob. Thus, we convert them into our
 | 
					# order rather than as a single binary blob. Thus, we convert them into our
 | 
				
			||||||
# more compact binary representation of ihex records (<linux/ihex.h>)
 | 
					# more compact binary representation of ihex records (<linux/ihex.h>)
 | 
				
			||||||
$(obj)/%.fw: $(obj)/%.HEX $(ihex2fw_dep) | $(objtree)/$(obj)/$$(dir %)
 | 
					$(obj)/%.fw: $(obj)/%.HEX $(ihex2fw_dep)
 | 
				
			||||||
	$(call cmd,ihex2fw)
 | 
						$(call cmd,ihex2fw)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# .H16 is our own modified form of Intel HEX, with 16-bit length for records.
 | 
					# .H16 is our own modified form of Intel HEX, with 16-bit length for records.
 | 
				
			||||||
$(obj)/%.fw: $(obj)/%.H16 $(ihex2fw_dep) | $(objtree)/$(obj)/$$(dir %)
 | 
					$(obj)/%.fw: $(obj)/%.H16 $(ihex2fw_dep)
 | 
				
			||||||
	$(call cmd,h16tofw)
 | 
						$(call cmd,h16tofw)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(firmware-dirs):
 | 
					 | 
				
			||||||
	$(call cmd,mkdir)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
obj-y				 += $(patsubst %,%.gen.o, $(fw-external-y))
 | 
					obj-y				 += $(patsubst %,%.gen.o, $(fw-external-y))
 | 
				
			||||||
obj-$(CONFIG_FIRMWARE_IN_KERNEL) += $(patsubst %,%.gen.o, $(fw-shipped-y))
 | 
					obj-$(CONFIG_FIRMWARE_IN_KERNEL) += $(patsubst %,%.gen.o, $(fw-shipped-y))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,25 +24,23 @@ ifndef CONFIG_FIRMWARE_IN_KERNEL
 | 
				
			||||||
mod-fw += $(fw-shipped-y)
 | 
					mod-fw += $(fw-shipped-y)
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ifneq ($(KBUILD_SRC),)
 | 
				
			||||||
 | 
					# Create output directory if not already present
 | 
				
			||||||
 | 
					_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					firmware-dirs := $(sort $(addprefix $(objtree)/$(obj)/,$(dir $(fw-external-y) $(fw-shipped-all))))
 | 
				
			||||||
 | 
					# Create directories for firmware in subdirectories
 | 
				
			||||||
 | 
					_dummy := $(foreach d,$(firmware-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
 | 
				
			||||||
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
installed-mod-fw := $(addprefix $(INSTALL_FW_PATH)/,$(mod-fw))
 | 
					installed-mod-fw := $(addprefix $(INSTALL_FW_PATH)/,$(mod-fw))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
installed-fw := $(addprefix $(INSTALL_FW_PATH)/,$(fw-shipped-all))
 | 
					installed-fw := $(addprefix $(INSTALL_FW_PATH)/,$(fw-shipped-all))
 | 
				
			||||||
installed-fw-dirs := $(sort $(dir $(installed-fw))) $(INSTALL_FW_PATH)/./
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Workaround for make < 3.81, where .SECONDEXPANSION doesn't work.
 | 
					 | 
				
			||||||
PHONY += $(INSTALL_FW_PATH)/$$(%) install-all-dirs
 | 
					 | 
				
			||||||
$(INSTALL_FW_PATH)/$$(%): install-all-dirs
 | 
					 | 
				
			||||||
	@true
 | 
					 | 
				
			||||||
install-all-dirs: $(installed-fw-dirs)
 | 
					 | 
				
			||||||
	@true
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
quiet_cmd_install = INSTALL $(subst $(srctree)/,,$@)
 | 
					quiet_cmd_install = INSTALL $(subst $(srctree)/,,$@)
 | 
				
			||||||
      cmd_install = $(INSTALL) -m0644 $< $@
 | 
					      cmd_install = mkdir -p $(@D); $(INSTALL) -m0644 $< $@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(installed-fw-dirs):
 | 
					$(installed-fw): $(INSTALL_FW_PATH)/%: $(obj)/%
 | 
				
			||||||
	$(call cmd,mkdir)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$(installed-fw): $(INSTALL_FW_PATH)/%: $(obj)/% | $(INSTALL_FW_PATH)/$$(dir %)
 | 
					 | 
				
			||||||
	$(call cmd,install)
 | 
						$(call cmd,install)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PHONY +=  __fw_install __fw_modinst FORCE
 | 
					PHONY +=  __fw_install __fw_modinst FORCE
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue