Lost trying to apply custom patch related to target/linux/ath79/image

Hi,

cc @rogerpueyo

I'm pretty lost trying to apply a patch to my custom firmware. That should go inside openwrt's git repo, to: target/linux/ath79/image

The way I'm using to include the patch it is just copying the patch with name 999-ath79-update-ubnt-version.patch to the directory patches

so I tried:

target/linux/ath79/patches-4.14/ gives error and says it cannot apply patch (then it is not there)

I also tried target/linux/ath79/image does not complain, but looks like is not being applied

Firmware version: 'WA.ar934x.v8.5.0-42.OpenWrt-r11063-85e04e9f46'
Output file: '/root/temba/imagebuilder_local/openwrt-imagebuilder-ath79-generic.Linux-x86_64__Openwrt__temba19/build_dir/target-mips_24kc_musl/linux-ath79_generic/tmp/openwrt-ath79-generic-ubnt_nanostation-ac-loco-squashfs-factory.bin'
Part count: 2
     kernel:  1048576 bytes (free:        0)
     rootfs:  4456710 bytes (free: 10616570)

with command

make -C ./imagebuilder_local/openwrt-imagebuilder-ath79-generic.Linux-x86_64__Openwrt__temba19 image PROFILE=ubnt_nanostation-ac-loco PACKAGES='bmx6 bmx6-json b
mx6-sms bmx6-uci-config bmx6-table luci luci-app-bmx6 luci-compat tcpdump-mini iperf3 netperf ip netcat mtr xl2tpd wireguard luci-app-wireguard gre' FILES=./files

I also verified that the patch is not being applied checking the file vi /root/temba/Openwrt__temba19/build_dir/target-mips_24kc_musl/openwrt-imagebuilder-ath79-generic.Linux-x86_64/target/linux/ath79/image/generic-ubnt.mk

I also tried compiling just a part:

make -j1 V=s target/linux/ath79/image/clean
make -j1 V=s target/linux/ath79/clean

both failed

I could only make:

make -j1 V=s target/linux/clean
make -j1 V=s target/linux/compile

In the past, I ran a patch in target/linux/generic/files/drivers/net/phy/patches/ and it worked (?)

Thanks

Hi,

I'd start by using grep to find all the occurrences for UBNT_VERSION, and see where it remains as 8.5.0 and where it changed to 8.5.3.

Cheers

this?

root@cooker2:~/temba/Openwrt__temba19/build_dir/target-mips_24kc_musl/openwrt-imagebuilder-ath79-generic.Linux-x86_64/target/linux/ath79# grep -ir UBNT_VERSION *      
image/generic-ubnt.mk:DEVICE_VARS += UBNT_BOARD UBNT_CHIP UBNT_TYPE UBNT_VERSION UBNT_REVISION                                                                         
image/generic-ubnt.mk:          -B $(UBNT_BOARD) -v $(UBNT_TYPE).$(UBNT_CHIP).v$(UBNT_VERSION)-$(UBNT_REVISION) \                                                      
image/generic-ubnt.mk:# UBNT_VERSION e.g. one of (6.0.0, 8.5.0)
image/generic-ubnt.mk:  UBNT_VERSION := 6.0.0
image/generic-ubnt.mk:  UBNT_VERSION := 8.5.0
image/generic-ubnt.mk:  UBNT_VERSION := 6.0.4
image/patches/999-ath79-update-ubnt-version.patch:Subject: [PATCH] ath79: update WA/XC devices UBNT_VERSION to 8.5.3                                                   
image/patches/999-ath79-update-ubnt-version.patch:Ubiquiti WA devices with newer hw version 2011K require UBNT_VERSION                                                 
image/patches/999-ath79-update-ubnt-version.patch:-# UBNT_VERSION e.g. one of (6.0.0, 8.5.0)                                                                           
image/patches/999-ath79-update-ubnt-version.patch:+# UBNT_VERSION e.g. one of (6.0.0, 8.5.3)                                                                           
image/patches/999-ath79-update-ubnt-version.patch:-  UBNT_VERSION := 8.5.0
image/patches/999-ath79-update-ubnt-version.patch:+  UBNT_VERSION := 8.5.3

edited the file directly and worked (so my workflow works)

Firmware version: 'WA.ar934x.v8.5.3-42.OpenWrt-r11063-85e04e9f46'
Output file: '/root/temba/imagebuilder_local/openwrt-imagebuilder-ath79-generic.Linux-x86_64__Openwrt__temba19/build_dir/target-mips_24kc_musl/linux-ath79_generic/tmp/openwrt-ath79-generic-ubnt_nanostation-ac-loco-squashfs-factory.bin'
Part count: 2
     kernel:  1048576 bytes (free:        0)
     rootfs:  4456710 bytes (free: 10616570)

and the patch works, of course

root@cooker2:~/temba/Openwrt__temba19/target/linux/ath79/image# patch generic-ubnt.mk patches/999-ath79-update-ubnt-version.patch                                      
patching file generic-ubnt.mk

so that confirms that I am not putting the patch in the appropriate place that I don't know where it should be.

man patch

You can't use a patch file to patch a Makefile.. I tried :slight_smile:

https://forum.openwrt.org/t/patching-a-package-makfile/60845/2

You'll need to edit the image/generic-ubnt.mk file in your target/linux/ath79/ directly, then you can either create a repo for your custom device up on github. If you do that, you can re-assign it as your origin repo and have the OpenWrt as your upstream, allowing you to merge upstream changes (if any) down the line.

1 Like

You can patch ANY text file with the patch command. Whether that fits into the make scheme is another matter. But given the issue at hand from the OP, the PR was being applied incorrectly. For me

wget https://github.com/openwrt/openwrt/pull/3063.patch
patch -p1 < 3063.patch

certainly does work. And of course there are other ways to get a PR into your tree.

This PR found its way into master a couple of days back, but that is another matter.

Correct, but not in the context of the OpenWrt build system, which was the what @guifipedro was asking based on the

They are trying to patch the target/linux/ath79 directory, which is called long before any patches included in it are applied.. The Makefile can't patch itself.

So, he either does it manually each time he updates his source tree (until it's done upstream) or he does it manually and then goes the custom github repo for the device and sets OpenWrt's as the upstream so it can be gracefully merged. Even then, you'll usually ahve to deal with conflicts

Just to clarify, it's why I posted to the thread in which I asked the same question. I didn't want to deal with manually patching each time I did a git pull, so I was trying to use the patches in the same way. I settled on just creating the origin as my own repo and upstream as OpenWrt and merging the changes

1 Like

thanks all, specially @Grommish for understanding me here (because I recognize I did not explain very well)

@Grommish I don't get how you managed the situation. First you were merging all the time the changes with git pull. Can you explain again what you did after that? You still have to git pull or "merge" in some way, right?

In my case, I would like to deal with the patches in a more simple way (as I am expecting very few patches, that most of them are merged at some point)

so I had to move from a copy_patch way for these makefiles to apply_patch approach that I wrote today (so, the way I implemented it, it is less lines and easier to just copy the patches to patches/ directory when possible

copy_patch() {
  local patch_var="${1}"
  local target_path="${2}"
  local patch_file="${3}"

  local patch_path="../patches"

  if [ ${patch_var} = 'y' ]; then
    mkdir -p "${target_path}"
    cp -v "${patch_path}/${patch_file}" "${target_path}"
  else
    rm -fv "${target_path}/${patch_file}"
  fi
}



apply_patch() {
  local patch_var="${1}"
  local target_path="${2}"
  local patch_path="${3}"
  local target_file="${4}"
  local patch_file="${5}"

  if [ "${patch_var}" = 'y' ]; then
    if [ -f "${target_path}/${target_file}.orig" ]; then
      if [ -f "${target_path}/${target_file}.rej" ]; then
        echo "${patch_path}/${patch_file} looks bad, there is a ${target_path}/${target_file}.rej"
      else
        echo "${patch_path}/${patch_file} already applied"
      fi
    else
      patch -b "${target_path}/${target_file}" "${patch_path}/${patch_file}"
    fi
  else
    if [ -f "${target_path}/${target_file}.orig" ]; then
      mv -v "${target_path}/${target_file}.orig" "${target_path}/${target_file}"
      rm -v "${target_path}/${target_file}.rej"
    else
      echo "${patch_path}/${patch_file} not applied"
    fi
  fi

}

source: https://gitlab.com/guifi-exo/temba/-/blob/19x/imagebuilder-customfuns-lib.sh

and for your curiosity here are the patches I apply https://gitlab.com/guifi-exo/temba/-/tree/19x/patches

In my case, I have a personal repo for both the main OpenWrt repo and a separate one for my packages (as I have to alter some of them code-wise)

My dev-box is currently in pieces, but in general, you'll start in your openwrt root directory:

I only use github, so adjust to your git provider of choice:

Create a new repo (mine is https://github.com/Grommish/Itus_Shield_v2), and in your buildroot:

git remote rename origin upstream
git remote add origin <giturl>
git pull upstream <branch>
git push origin <branch>

I did a similar thing for feeds/packages tree (https://github.com/Grommish/OpenWrt_Feeds_Packages)

You make your changes to target/linux/ath79/images/Makefile, then git add target/linux/ath79/images/Makefile and a git commit. git push origin <branch> will send it to your repo.

To update, do a git pull upstream <branch>, it'll merge (usually fast-forward) and allow you to do the merge commit, which you then push to your repo git push origin <branch>

Here is a commit I made changing my Makefile, for reference.. https://github.com/Grommish/Itus_Shield_v2/commit/ddfd2ea845828fc27b196f4049161d78c82052fb#diff-1ed03b59bfbbd8b8d8fbb048ec2f8eb4

You can see this commit (https://github.com/Grommish/Itus_Shield_v2/commit/8f80f26460d4a5b1541e97e07edeabfa142e0ea2) to see what it looks like for the upstream merge

If you are doing packages, you setup the repo in feeds/packages/ the same way, and then you can do the git pull upstream <branch> in feeds/packages after you run the .script/feeds update -a

This way, I don't have to try and understand the inside of the Openwrt build system, I just know it works.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.