scripts/build/kernel/linux.sh
author David Holsgrove <david.holsgrove@xilinx.com>
Thu Oct 11 14:39:40 2012 +1000 (2012-10-11)
changeset 3076 63d108a39453
parent 3065 603ccf80c48b
child 3079 37831a33e07e
permissions -rw-r--r--
kernel/linux: use generic custom infrastructure

Config options remain the same as before, just generalised to be used by other
components also.

Signed-off-by: "David Holsgrove" <david.holsgrove@xilinx.com>
[yann.morin.1998@free.fr: fix indentation, fix comment]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Message-Id: <50674fe47431174aab80.1349931193@localhost.localdomain>
PatchWork-Id: 190786
     1 # This file declares functions to install the kernel headers for linux
     2 # Copyright 2007 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package
     4 
     5 CT_DoKernelTupleValues() {
     6     if [ "${CT_ARCH_USE_MMU}" = "y" ]; then
     7         CT_TARGET_KERNEL="linux"
     8     else
     9         # Some no-mmu linux targets requires a -uclinux tuple (like m68k/cf),
    10         # while others must have a -linux tuple (like bfin).  Other targets
    11         # should be added here when someone starts to care about them.
    12         case "${CT_ARCH}" in
    13             blackfin)   CT_TARGET_KERNEL="linux" ;;
    14             m68k)       CT_TARGET_KERNEL="uclinux" ;;
    15             *)          CT_Abort "Unsupported no-mmu arch '${CT_ARCH}'"
    16         esac
    17     fi
    18 }
    19 
    20 # Download the kernel
    21 do_kernel_get() {
    22     local k_ver
    23     local custom_name
    24     local rel_dir
    25     local korg_base mirror_base
    26 
    27     if [ "${CT_KERNEL_LINUX_USE_CUSTOM_HEADERS}" = "y"  ]; then
    28         return 0
    29     fi
    30 
    31     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
    32         CT_GetCustom "linux" "${CT_KERNEL_VERSION}"     \
    33                      "${CT_KERNEL_LINUX_CUSTOM_LOCATION}"
    34     else # Not a custom tarball
    35         case "${CT_KERNEL_VERSION}" in
    36             2.6.*.*|3.*.*)
    37                 # 4-part versions (for 2.6 stables and long-terms), and
    38                 # 3-part versions (for 3.x.y stables and long-terms),
    39                 # we need to trash the last digit
    40                 k_ver="${CT_KERNEL_VERSION%.*}"
    41                 ;;
    42             2.6.*|3.*)
    43                 # 3-part version (for 2.6.x initial releases), and 2-part
    44                 # versions (for 3.x initial releases), use all of it
    45                 k_ver="${CT_KERNEL_VERSION}"
    46                 ;;
    47         esac
    48         case "${CT_KERNEL_VERSION}" in
    49             2.6.*)  rel_dir=v2.6;;
    50             3.*)    rel_dir=v3.x;;
    51         esac
    52         korg_base="http://ftp.kernel.org/pub/linux/kernel/${rel_dir}"
    53         CT_GetFile "linux-${CT_KERNEL_VERSION}"         \
    54                    "${korg_base}"                       \
    55                    "${korg_base}/longterm/v${k_ver}"    \
    56                    "${korg_base}/longterm"
    57     fi
    58 }
    59 
    60 # Extract kernel
    61 do_kernel_extract() {
    62     # If using custom headers, or custom directory location, nothing to do
    63     if [ "${CT_KERNEL_LINUX_USE_CUSTOM_HEADERS}" = "y"    \
    64          -o -d "${CT_SRC_DIR}/linux-${CT_KERNEL_VERSION}" ]; then
    65         return 0
    66     fi
    67    
    68     CT_Extract "linux-${CT_KERNEL_VERSION}"
    69     CT_Patch "linux" "${CT_KERNEL_VERSION}"
    70 }
    71 
    72 # Wrapper to the actual headers install method
    73 do_kernel_headers() {
    74     CT_DoStep INFO "Installing kernel headers"
    75 
    76     if [ "${CT_KERNEL_LINUX_USE_CUSTOM_HEADERS}" = "y" ]; then
    77         do_kernel_custom
    78     else
    79         do_kernel_install
    80     fi
    81 
    82     CT_EndStep
    83 }
    84 
    85 # Install kernel headers using headers_install from kernel sources.
    86 do_kernel_install() {
    87     local kernel_path
    88 
    89     CT_DoLog DEBUG "Using kernel's headers_install"
    90 
    91     mkdir -p "${CT_BUILD_DIR}/build-kernel-headers"
    92 
    93     kernel_path="${CT_SRC_DIR}/linux-${CT_KERNEL_VERSION}"
    94     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
    95         kernel_path="${CT_SRC_DIR}/linux-custom"
    96     fi
    97     V_OPT="V=${CT_KERNEL_LINUX_VERBOSE_LEVEL}"
    98 
    99     CT_DoLog EXTRA "Installing kernel headers"
   100     CT_DoExecLog ALL                                    \
   101     make -C "${kernel_path}"                            \
   102          O="${CT_BUILD_DIR}/build-kernel-headers"       \
   103          ARCH=${CT_ARCH}                                \
   104          INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
   105          ${V_OPT}                                       \
   106          headers_install
   107 
   108     if [ "${CT_KERNEL_LINUX_INSTALL_CHECK}" = "y" ]; then
   109         CT_DoLog EXTRA "Checking installed headers"
   110         CT_DoExecLog ALL                                    \
   111         make -C "${kernel_path}"                            \
   112              O="${CT_BUILD_DIR}/build-kernel-headers"       \
   113              ARCH=${CT_ARCH}                                \
   114              INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
   115              ${V_OPT}                                       \
   116              headers_check
   117     fi
   118 
   119     # Cleanup
   120     find "${CT_SYSROOT_DIR}" -type f                        \
   121                              \(    -name '.install'         \
   122                                 -o -name '..install.cmd'    \
   123                                 -o -name '.check'           \
   124                                 -o -name '..check.cmd'      \
   125                              \)                             \
   126                              -exec rm {} \;
   127 }
   128 
   129 # Use custom headers (most probably by using make headers_install in a
   130 # modified (read: customised) kernel tree, or using pre-2.6.18 headers, such
   131 # as 2.4). In this case, simply copy the headers in place
   132 do_kernel_custom() {
   133     local tar_opt
   134 
   135     CT_DoLog EXTRA "Installing custom kernel headers"
   136 
   137     mkdir -p "${CT_SYSROOT_DIR}/usr"
   138     cd "${CT_SYSROOT_DIR}/usr"
   139     if [ "${CT_KERNEL_LINUX_CUSTOM_IS_TARBALL}" = "y" ]; then
   140         case "${CT_KERNEL_LINUX_CUSTOM_PATH}" in
   141             *.tar)      ;;
   142             *.tgz)      tar_opt=--gzip;;
   143             *.tar.gz)   tar_opt=--gzip;;
   144             *.tar.bz2)  tar_opt=--bzip2;;
   145         esac
   146         CT_DoExecLog ALL tar x ${tar_opt} -vf ${CT_KERNEL_LINUX_CUSTOM_PATH}
   147     else
   148         CT_DoExecLog ALL cp -rv "${CT_KERNEL_LINUX_CUSTOM_PATH}/include" .
   149     fi
   150 }