Chapter 28. Applying a patch

Patches are normally provided in the form of a single patch file. Save this file to a location from where it can be referenced and loaded by the patch application.

28.1. Pre-process patchfile

Patches can be specific to a single version of eCosPro or can be applicable to a number of versions. If a patch is specific to a single version, the patchfile provided should already be directed at that specific version and will not require pre-processing, and this section may be skipped. If the patch provided is already version specific, skip forward to Section 28.2, “Applying a patch”.

If a patchfile is intended to be applied against a number of different versions of eCosPro you will need to pre-process the patchfile to create a new patchfile that is specific to your version. This is because the naming convention of directories used by CDL (see Chapter 22, CDL Concepts) includes the version number of individual packages, and patchfiles include the path to the files which are to be changed. As the naming convention for versions used is simple and the path names of files can be simply changed within the patchfile, a generic patchfile directed at the version "patchfile" is usually provided rather than providing a patchfile for each version of eCosPro affected.

To pre-process the patchfile, open a command prompt with the "Shell Environment" shortcut in the eCosPro group and change to the directory that contains the downloaded patchfile. Then run the command below replacing X, Y and Z below with the major, minor and sub-minor version numbers of your release respectively. For example, for eCosPro version 3.1.15 the major version number is 3, the minor version is 1, and the sub-minor version number is 15.

Figure 28.1. Pre-process patch on Linux

test@ubuntu:~$ cd /tmp/download
test@ubuntu:/tmp/download$ sed 's@/current/@/vX_Y_Z/@' < issue-1001234.pat > issue-1001234-new.pat
test@ubuntu:/tmp/download$

Figure 28.2. Pre-process patch on Windows

C:\> cd C:\TEMP
C:\TEMP> sed 's@/current/@/vX_Y_Z/@' < issue-1001234.pat > issue-1001234-new.pat
C:\TEMP>

For example, use v3_1_15 for version 3.1.15, v3_1_3 for version 3.1.3 and so on.

Figure 28.3. Example of the pre-process of a patch on Linux for version 3.1.15

test@ubuntu:~$ cd /tmp/download
test@ubuntu:/tmp/download$ sed 's@/current/@/v3_1_15/@' < issue-1001234.pat > issue-1001234-new.pat
test@ubuntu:/tmp/download$

28.2. Applying a patch

Application of a patch usually involves the following three steps:

  1. Open a Shell
  2. Change to a directory within the source code tree
  3. Apply the patch

28.2.1. Patch Prefix (-pn)

Patches are usually created against the sources of a release, and within a sub-directory of the source tree. As such, the patch prefix can vary in accordance to where in the directory tree the patch was created. The patch author will usually provide instructions on how to apply the patch, which will normally include this directory from which the patch should be applied and the patch prefix (number of directories, separated by slashes ’/‚, to be stripped from each file name found within the patch).

For example, supposing the file name in the patch file was /a/packages/kernel/v4_1_1/src/sched/mlqueue.cxx setting -p0 gives the entire file name unmodified, -p1 gives a/packages/kernel/v4_1_1/src/sched/mlqueue.cxx without the leading slash, -p6 gives sched/mlqueue.cxx.

28.2.2. Example: Applying a patch on Linux

This example makes the following assumptions:

  • the patch provided has been stored in the file /tmp/download/issue-1001234-new.pat (replace /tmp/download/issue-1001234-new.pat with the path and filename to the downloaded or pre-processed patchfile).
  • The patch file has been pre-processed if necessary - see Section 28.1, “Pre-process patchfile”.
  • the patch is to be applied within the sub-directory $ECOS_REPOSITORY
  • the patch will be applied with a patch level of 0

Open a command prompt window or shell (for example, opened with the "Shell Environment" shortcut in the eCosPro group) and follow these commands:

Figure 28.4. Application of a patch on Linux

test@ubuntu:~$ cd $ECOS_REPOSITORY
test@ubuntu:/opt/ecospro/ecos-3.1.19/packages$ patch -p0 < /tmp/download/issue-1001234-new.pat
patching file net/common/current/include/bootp.h
patching file net/common/current/src/bootp_support.c
test@ubuntu:/opt/ecospro/ecos-3.1.19/packages$

28.2.3. Example: Applying a patch on Windows

This example makes the following assumptions:

  • the patch provided has been stored in the file C:\TEMP\issue-1001234-new.pat (replace C:\TEMP\issue-1001234-new.pat with the path and filename to the downloaded or pre-processed patchfile).
  • The patch file has been pre-processed if necessary - see Section 28.1, “Pre-process patchfile”.
  • the patch is to be applied within the sub-directory %ECOS_REPOSITORY%
  • the patch will be applied with a patch level of 0

Open a command prompt window or shell (for example, opened with the "Shell Environment" shortcut in the eCosPro group) and follow these commands:

Figure 28.5. Application of a patch on Windows

C:\> cd %ECOS_REPOSITORY%
C:\eCosPro\ecos-3.1.19\packages> patch -p0 < C:\TEMP\issue-1001234-new.pat
patching file net/common/current/include/bootp.h
patching file net/common/current/src/bootp_support.c
C:\eCosPro\ecos-3.1.19\packages>

[Note]Note

On Windows XP in earlier releases of the eCosPro 3.1 host tools the environment variable %ECOS_REPOSITORY% will not be recognised as it used forward instead of backward slashes as directory name seperators. To work around this issue, alter the %ECOS_REPOSITORY% variable by changing forward to backward slashes.

Figure 28.6. Application of a patch on Windows XP

C:\> echo %ECOS_REPOSITORY%
C:/eCosPro/ecos-3.1.19/packages
C:\> set ECOS_REPOSITORY=C:\eCosPro\ecos-3.1.19\packages
C:\> cd %ECOS_REPOSITORY%
C:\eCosPro\ecos-3.1.19\packages> patch -p0 < C:\TEMP\issue-1001234-new.pat
patching file net/common/current/include/bootp.h
patching file net/common/current/src/bootp_support.c
C:\eCosPro\ecos-3.1.19\packages>