OpenWrt Forum Archive

Topic: Why copy target/linux/*/files _before_ applying patches?

The content of this topic has been archived on 1 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I've ran into a problem. I would like to change some files in the linux kernel for my target. In this case, it is an Atmel AVR32 development board named atngw100.

What I did, is adding a file target/linux/avr32/files-2.6.25/arch/avr32/boards/atngw100/setup.c that is changed to my needs. I prefer this over a patch in this phase of development.

The problem is that during build, this file is copied to the build_dir before the patches target/linux/avr32/patches/* are applied. One of these patches also modifies that setup.c. Obviously, because of my changes, that patch fails, breaking the build.

Now I'm wondering whether the patches shouldn't be applied _before_ the target/*/files* are copied. In my view, that would be more logical because the files there should overwrite what is already in OpenWRT. Actually, I made my modifications on top of the patched setup.c file and not the pristine 2.6.25.9 linux source file.

(side note: tested on OpenWRT trunk, r11629. I guess that this feature hasn't changed since then)

As a "quick fix", I'm considering to change  the copy & patch order of Kernel/Patch/Default (see include/quilt.mk). Is that the right way to go?

Any comments?

Regards,

Bas.

Here is an example on how it works the way I would like it to work:

Index: include/quilt.mk
===================================================================
--- include/quilt.mk    (revision 100)
+++ include/quilt.mk    (working copy)
@@ -69,12 +69,12 @@
define Kernel/Patch/Default
    $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
    if [ -d $(GENERIC_FILES_DIR) ]; then $(CP) $(GENERIC_FILES_DIR)/* $(LINUX_DIR)/; fi
+    $(call PatchDir,$(GENERIC_PATCH_DIR),generic/)
+    $(call PatchDir,$(PATCH_DIR),platform/)
    if [ -d $(FILES_DIR) ]; then \
        $(CP) $(FILES_DIR)/* $(LINUX_DIR)/; \
        find $(LINUX_DIR)/ -name \*.rej | xargs rm -f; \
    fi
-    $(call PatchDir,$(GENERIC_PATCH_DIR),generic/)
-    $(call PatchDir,$(PATCH_DIR),platform/)
endef

So first general files copied, patches applied and then some files that are overwritten. I admit that it is somewhat asymmetric because the order of copying and patching is different in the general and architecture specific files. But if I change the order of the general files&patches, patching fails. So some patches do modify copied files from the generic source that are copied.

I think one proper way would be to not allow any patch to modify a copied file. Because these files already are version managed. So they should be applied as-is and not be patched again.
But the following scheme might work better in the real world of OpenWRT:

1) Copy general files that should be added
2) Apply general patches
3) Copy general files that can override others
4) Copy arch specific files that should be added
5) Apply arch specific patches
6) Copy arch specific files thay can override others

1,2 and part of 5 are OpenWRT controlled. An OpenWRT user (sw developer) can use 4, 5 (by adding patches) and 6 to modify architecture specific kernel stuff. In an ideal world, one would even consider pre and post files and patches, making it 8 different items.

Regards,

Bas.

The discussion might have continued from here.