scripts/build/kernel/linux.sh
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Sun May 11 23:43:52 2014 +0200 (2014-05-11)
changeset 3320 78af1c99bc6d
parent 3262 87ad9e82546d
permissions -rw-r--r--
scripts/functions: add target_endian_le and target_endian_be

We currently define target_endian_el and target_endian_eb to be the
tuple extension depending on endianness, defined to be respectively
'el' or 'eb' according to the endianness.

Some architecture do not use 'el' or 'eb', but use 'le' or 'be'.

Provide that as well, as two new variables: target_endian_le and
target_endian_be.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Cody P Schafer <dev@codyps.com>
     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 a custom headers tree, nothing to do
    63     if [ "${CT_KERNEL_LINUX_USE_CUSTOM_HEADERS}" = "y" ]; then
    64         return 0
    65     fi
    66 
    67     # If using a custom directory location, nothing to do
    68     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y"    \
    69          -a -d "${CT_SRC_DIR}/linux-${CT_KERNEL_VERSION}" ]; then
    70         return 0
    71     fi
    72 
    73     # Otherwise, we're using either a mainstream tarball, or a custom
    74     # tarball; in either case, we need to extract
    75     CT_Extract "linux-${CT_KERNEL_VERSION}"
    76 
    77     # If using a custom tarball, no need to patch
    78     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
    79         return 0
    80     fi
    81     CT_Patch "linux" "${CT_KERNEL_VERSION}"
    82 }
    83 
    84 # Wrapper to the actual headers install method
    85 do_kernel_headers() {
    86     CT_DoStep INFO "Installing kernel headers"
    87 
    88     if [ "${CT_KERNEL_LINUX_USE_CUSTOM_HEADERS}" = "y" ]; then
    89         do_kernel_custom
    90     else
    91         do_kernel_install
    92     fi
    93 
    94     CT_EndStep
    95 }
    96 
    97 # Install kernel headers using headers_install from kernel sources.
    98 do_kernel_install() {
    99     local kernel_path
   100     local kernel_arch
   101 
   102     CT_DoLog DEBUG "Using kernel's headers_install"
   103 
   104     mkdir -p "${CT_BUILD_DIR}/build-kernel-headers"
   105 
   106     kernel_path="${CT_SRC_DIR}/linux-${CT_KERNEL_VERSION}"
   107     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
   108         kernel_path="${CT_SRC_DIR}/linux-custom"
   109     fi
   110     V_OPT="V=${CT_KERNEL_LINUX_VERBOSE_LEVEL}"
   111 
   112     kernel_arch="${CT_ARCH}"
   113     case "${CT_ARCH}:${CT_ARCH_BITNESS}" in
   114         # ARM 64 (aka AArch64) is special
   115         arm:64) kernel_arch="arm64";;
   116     esac
   117 
   118     CT_DoLog EXTRA "Installing kernel headers"
   119     CT_DoExecLog ALL                                    \
   120     make -C "${kernel_path}"                            \
   121          O="${CT_BUILD_DIR}/build-kernel-headers"       \
   122          ARCH=${kernel_arch}                            \
   123          INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
   124          ${V_OPT}                                       \
   125          headers_install
   126 
   127     if [ "${CT_KERNEL_LINUX_INSTALL_CHECK}" = "y" ]; then
   128         CT_DoLog EXTRA "Checking installed headers"
   129         CT_DoExecLog ALL                                    \
   130         make -C "${kernel_path}"                            \
   131              O="${CT_BUILD_DIR}/build-kernel-headers"       \
   132              ARCH=${kernel_arch}                            \
   133              INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
   134              ${V_OPT}                                       \
   135              headers_check
   136     fi
   137 
   138     # Cleanup
   139     find "${CT_SYSROOT_DIR}" -type f                        \
   140                              \(    -name '.install'         \
   141                                 -o -name '..install.cmd'    \
   142                                 -o -name '.check'           \
   143                                 -o -name '..check.cmd'      \
   144                              \)                             \
   145                              -exec rm {} \;
   146 }
   147 
   148 # Use custom headers (most probably by using make headers_install in a
   149 # modified (read: customised) kernel tree, or using pre-2.6.18 headers, such
   150 # as 2.4). In this case, simply copy the headers in place
   151 do_kernel_custom() {
   152     local tar_opt
   153 
   154     CT_DoLog EXTRA "Installing custom kernel headers"
   155 
   156     mkdir -p "${CT_SYSROOT_DIR}/usr"
   157     cd "${CT_SYSROOT_DIR}/usr"
   158     if [ "${CT_KERNEL_LINUX_CUSTOM_IS_TARBALL}" = "y" ]; then
   159         case "${CT_KERNEL_LINUX_CUSTOM_PATH}" in
   160             *.tar)      ;;
   161             *.tgz)      tar_opt=--gzip;;
   162             *.tar.gz)   tar_opt=--gzip;;
   163             *.tar.bz2)  tar_opt=--bzip2;;
   164             *.tar.xz)   tar_opt=--xz;;
   165         esac
   166         CT_DoExecLog ALL tar x ${tar_opt} -vf ${CT_KERNEL_LINUX_CUSTOM_PATH}
   167     else
   168         CT_DoExecLog ALL cp -rv "${CT_KERNEL_LINUX_CUSTOM_PATH}/include" .
   169     fi
   170 }