45

I am building linux kernel, if my kernel under git, then kernel version every time is:

Image Name:   Linux-2.6.39+

If I am not using git, then everything is OK without any plus at the end.

I know that this done by scripts/setlocalversion script:

if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
    # full scm version string
    res="$res$(scm_version)"
else
    # append a plus sign if the repository is not in a clean
    # annotated or signed tagged state (as git describe only
    # looks at signed or annotated tags - git tag -a/-s) and
    # LOCALVERSION= is not specified
    if test "${LOCALVERSION+set}" != "set"; then
        scm=$(scm_version --short)
            res="$res${scm:++}"
        fi
fi

So, it is possible without code changes say to build system that no need to add "+" at the end of version line?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Yuri
  • 1,179
  • 4
  • 13
  • 27
  • Set `LOCALVERSION`. Are you working off the `HEAD`, or have an unclean branch? – cyphar Oct 12 '13 at 12:02
  • LOCALVERSION - Append an extra string to the end of your kernel version. But I dont need append anything. I need just 2.6.39. – Yuri Oct 12 '13 at 12:19
  • 1
    Did you consider building a more recent kernel. 2.6.39 is really old. Current one is 3.11.4 and has a lot of improvements (but stay compatible with 2.6.x) – Basile Starynkevitch Oct 12 '13 at 12:31
  • 2
    Have found one ugly solution - add LOCALVERSION= to make command – Yuri Oct 12 '13 at 13:03
  • 1
    What difficulty does having the appended `+` cause you? It has a specific meaning, what you're doing will cause anything that cares to make bad decisions. – jthill Oct 12 '13 at 15:59
  • 2
    The "+" confusing some applications, for example "modprobe -l" in my case looking at the 2.6.39 folder without plus at the end. – Yuri Oct 13 '13 at 10:04

5 Answers5

39

The plus sign at the end of your version string is there as an indicator that the kernel was built from modified sources (that is, there were non-committed changes). This is also indicated by the comments in scripts/setlocalversion.

To avoid the '+' being appended despite having a dirty working directory, simply set LOCALVERSION explicityly when running make:

make LOCALVERSION=

You may also have to change the configuration option CONFIG_LOCALVERSION_AUTO to n in your kernel config (.config) before building:

sed -i "s|CONFIG_LOCALVERSION_AUTO=.*|CONFIG_LOCALVERSION_AUTO=n|" .config
Jon Gjengset
  • 4,078
  • 3
  • 30
  • 43
  • I do get a + at the end of my `vmlinuz` and `initrd.img`, yet `git status` says "nothing to commit, working directory clean". It is my own commit though, does the + appear because I am not on the official master branch? Or maybe since I built locally the working directory is not clean although the dirt is gitignored? – Gauthier Jan 23 '15 at 11:35
  • I'm not entirely sure.. You should have a look at `scripts/setlocalversion` and see exactly what it is testing for when setting `+`. – Jon Gjengset Jan 24 '15 at 00:53
  • Apparently, it also adds a plus if your working directory is clean, but your current git HEAD has no tag. – Gauthier Jan 25 '15 at 13:24
  • 1
    Ah, but that's not all of it. I have my own branch, tagged commit, clean working dir, but I still get the +. – Gauthier Jan 26 '15 at 10:15
  • @Gauthier Same as you >_ – Peterlits Zo May 16 '22 at 07:15
35

To prevent the script scripts/setlocalversion to append the + to the end of the kernel local version, create an empty .scmversion file in the root of the kernel sources.

touch .scmversion

this way, you'll be able to leave LOCALVERSION as is in the kernel configuration file, in case you want to append a local signature to the kernel name.

HappyCactus
  • 1,935
  • 16
  • 24
0

Manipulating scripts/setlocalversion seems to be the only way for me. Force return in scm_version():

scm_version()
{
        local short
        short=false
        **return**
BlackBeard
  • 10,246
  • 7
  • 52
  • 62
Sabin
  • 61
  • 3
0

Add this line to your local.conf if you're using yocto and imx soc

SCMVERSION_pn-linux-imx = ""

Tested on imx-4.9.88-2.0.0_ga release

Keelung
  • 349
  • 5
  • 9
0

Just comment the line as a workaround/quickfix in scripts/setlocalversion. Then the kernel version should be same as "make kernelversion".

       # Check for git and a git repo.
        if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
           head=$(git rev-parse --verify HEAD 2>/dev/null); then

                # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
                # it, because this version is defined in the top level Makefile.
                if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then

                        # If only the short version is requested, don't bother
                        # running further git commands
                        if $short; then
                                #echo "+" #comment this line
                                return
                        fi