Odi's astoundingly incomplete notes

New entries | Code

Creating a kernel source diff

When you roll your own kernel and frequently update it to the current stable version from git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git, then this script may be helpful. It creates the diff from the currently running kernel version to the latest stable one. You can easily apply it to your build source tree with: patch -p1 <~/patch.diff
cd "${REPO}" || exit 1
[ -d .git ] || {
  echo "${REPO} is not a git repo" >&2
  exit 1

CUR=$(uname -r)
MAJ=$(echo "${CUR}"| sed 's/\.[^.]*$//')
BR=$(git branch --show-current)

echo "Using git repo: ${REPO}"
echo "Current kernel: ${CUR}"
echo "Major version: ${MAJ}"
echo "git branch: ${BR}"
if [ "${BR}" != "linux-${MAJ}.y" ]; then
  echo "linux-stable on branch ${BR} which is not compatible with kernel ${CUR}" >&2
  EX=$(git branch | fgrep linux-${MAJ}.y)
  if [ -z "${EX}" ]; then
    echo "Please do: git checkout -t origin/linux-${MAJ}.y" >&2
    echo "Please do: git checkout linux-${MAJ}.y" >&2
  exit 1

# starts with v
NEXT=$(git tag --sort='-v:refname' | egrep "v${MAJ}" | head -1)

if [ "${NEXT}" = "v${CUR}" ]; then
  # are we uptodate at all?
  echo "Pulling git"
  git pull -q
  NEXT=$(git tag --sort='-v:refname' | egrep "v${MAJ}" | head -1)

echo "Next version: ${NEXT}"
if [ "${NEXT}" = "v${CUR}" ]; then
  echo "Kernel is uptodate, nothing to do" >&2
  exit 1

echo "Creating diff v${CUR}..${NEXT}"
git diff "v${CUR}..${NEXT}" >"${OUT}"
echo "Done: ${OUT}"

posted on 2022-06-09 12:13 UTC in Code | 0 comments | permalink