【问题标题】:How do I build and deploy LTTng to an embedded Linux system?如何构建 LTTng 并将其部署到嵌入式 Linux 系统?
【发布时间】:2012-11-26 07:15:28
【问题描述】:

http://lttng.org/download 上可用的源 tarball 中的 README 文件似乎假设构建在同一个 Linux 系统上,该系统将成为跟踪的目标。我找到了其他资源来解释如何做到这一点(LTTng Project YouTube channel 有非常好的截屏视频),但我找不到任何关于如何交叉编译 LTTng 的说明(具体来说,我猜是 liburcu、LTTng-UST、 LTTng-tools 和 LTTng-modules),并将其全部安装在嵌入式 Linux 系统上(我可以在其中构建或重建内核,使用设备树 blob 和 - 目前 - 基于 ramdisk 的文件系统)。

我在哪里可以找到有关如何执行此操作的详细信息?

更新:正如Marko 在下面的第一条评论中指出的那样,LTTng 工具是使用autoconf 构建的。我从理论上理解,我可以为configure 找到一个“--host”选项,类似于this answer。也许我需要一个像“ARCH=arm”这样的参数到make,就像我在构建内核时使用的那样。但是,在将要使用它们的同一台机器上构建 LTTng 组件时使用的 make install 的交叉编译等效项是什么?

【问题讨论】:

  • 上次我构建 LTT 用户空间工具时,这并不是一个特别容易的练习——但它们是为autoconf 设置的——所以这个过程非常类似于构建任何其他软件一个交叉编译器。如果您正在使用一个设置良好的交叉环境,其中您的gcc 已经设置了目标库和头文件路径,那么这只是在调用autoconf 时指定 sysroot 和可能的编译器名称的一种情况。如果没有,您还需要设置负载。你有一个 LTT'd 内核吗?这可能是一个更大的挑战。
  • 谢谢@Marko。我将通过更新我的问题来回复您的autoconf cmets...
  • ...我认为 LTTng 2.0 的一个特点是它不再需要补丁。来自lwn.net/Articles/491510:“与它的前身 LTTng 0.x 不同,它可以安装在 vanilla 或分发内核上,无需任何补丁。”如果内核需要专门为LTTng 2.0配置,我找不到任何细节。

标签: cross-compiling embedded-linux trace lttng


【解决方案1】:

LTTng 2.x 不再需要修补内核。您需要加载内核模块 (lttng-modules) 才能进行内核跟踪。支持的最低 Linux 内核版本是 2.6.38。 您可以低至 2.6.32,但您需要根据 LTTng 2.1 release notelttng-modules README 为您的内核应用 3 个补丁。

为了回答您的交叉编译问题,这是我用来交叉编译 LTTng 工具链(用于用户空间跟踪)的常用过程:

export HOST=<your host triplet (e.g. arm-linux-gnueabi)>

# Make sure your cross-compiler can be found in your $PATH
export SYSROOT=<path to the target sysroot>

export CFLAGS="--sysroot=$SYSROOT"
export CPPFLAGS="-I$SYSROOT/include"
export CXXFLAGS=$CFLAGS
export LDFLAGS="--sysroot=$SYSROOT -L$SYSROOT/usr/lib -L$SYSROOT/lib"

# Fix RPL_MALLOC issue. See [Autoconf and RPL_MALLOC][3] for more details.
export ac_cv_func_malloc_0_nonnull=yes

# Cross compile userspace-rcu. You can also use a source tarball.
git clone git://git.lttng.org/userspace-rcu.git
cd userspace-rcu
./bootstrap
./configure --prefix=$SYSROOT --host=$HOST --with-sysroot=$SYSROOT
make
make install

# Cross compile lttng-ust. You can also use a source tarball.
git clone git://git.lttng.org/lttng-ust.git
cd lttng-ust
./bootstrap
./configure --prefix=$SYSROOT --host=$HOST --with-sysroot=$SYSROOT
make
make install

# Cross compile lttng-tools. You can also use a source tarball.
git clone git://git.lttng.org/lttng-tools.git
cd lttng-tools
./bootstrap
./configure --prefix=$SYSROOT --host=$HOST --with-sysroot=$SYSROOT
make
make install

您应该能够使其适应您的平台。如果要进行内核跟踪,还需要以类似的方式交叉编译 lttng-modules。

【讨论】:

    【解决方案2】:

    更新:ARM 的 LTTng 交叉编译现在更简单了。

    首先,安装所需的依赖项。例如,使用 Emdebian 工具链:

    xapt -a armel -m libc6-dev libpopt-dev uuid-dev liburcu-dev
    

    然后:

    export HOST=arm-linux-gnueabi
    export SYSROOT=<path to the target sysroot>
    
    git clone git://git.lttng.org/lttng-ust.git
    cd lttng-ust
    ./bootstrap
    ./configure --host=$HOST --prefix=$SYSROOT/usr/local
    make -j8
    make install
    
    git clone git://git.lttng.org/lttng-tools.git
    cd lttng-tools
    ./bootstrap
    ./configure --host=$HOST --prefix=$SYSROOT/usr/local
    make -j8
    make install
    

    备注:有时由于 'tests' 子目录二进制文件而导致失败。在这种情况下,只需从 Makefile 中删除“测试”(在执行 ./configure 之后)。

    【讨论】:

    • 它给出了以下错误 Requested 'liburcu >= 0.12' but Userspace RCU version is 0.9.1
    【解决方案3】:

    我只想分享我使用的构建脚本。它还编译了一些其他缺失的依赖项。高温

    它编译如下:

    libuuid-libxml2-popt-libiconv-zlib-userspace-rcu-lttng-ust-lttng-tools-lttng-modules

    #!/bin/bash
    
    # install this stuff before
    # apt-get install  lib32z1 lib32ncurses5 lib32bz2-1.0 bison flex build-essential
    # change your flags here
    
    export PATH=/home/build/sam9/compiler/arm-2014.05/bin:$PATH
    export ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes
    export HOST=arm-none-linux-gnueabi
    export SYSROOT=/home/build/sam9/sysroot
    
    G_CC=arm-none-linux-gnueabi-gcc 
    G_PREFIX=/usr/local
    
    G_ARCH=arm
    G_CROSS_COMPILE=arm-none-linux-gnueabi-
    G_KERNELDIR=/home/build/sam9/linux-3.4.106
    
    
    G_CFG_FILE="$PWD/${0%\.*}.conf" # tracking download/compile steps
    
    G_TARBALL_DIR=$PWD/tarballs
    G_SOURCES_DIR=$PWD/sources
    G_BUILD_DIR=$PWD/builds
    
    # steps for tracking progress in $G_CFG_FILE
    step_start=0
    step_download=1
    step_compile=2
    
    echo
    echo "This script will compile and install lttng and some deps"
    echo "Building for HOST=$HOST"
    echo
    echo "Builds are located in $G_BUILD_DIR"
    echo "Sources are located in $G_SOURCES_DIR"
    echo "Tarballs are located in $G_TARBALL_DIR"
    echo "sysroot is located at $SYSROOT"
    echo "prefix is set to $G_PREFIX"
    echo
    echo "press Enter to continue or CRTL-C to abort"
    read
    
    [ -e "$G_CFG_FILE" ] && . "$G_CFG_FILE" &> /dev/null
    
    function get_src_dir()
    {
        local filename="$1"
        tar -tf "$G_TARBALL_DIR/$filename"| sed -e 's@/.*@@' | uniq
    }
    
    function build()
    {
        local filename="$1"
        local what="$2"
        local dir_name="$3"
        local state="$4"
        local do_bootstrap=$5
    
        if [ $state -eq $step_download ] ; then
    
            if $do_bootstrap ; then
                pushd $G_SOURCES_DIR/$dir_name
                ./bootstrap
                popd
            fi
    
            mkdir -p "$G_BUILD_DIR/$dir_name"       
            pushd "$G_BUILD_DIR/$dir_name"      
            if [ -n "$patch" ] ; then
                pushd "$G_SOURCES_DIR/$dir_name"        
                wget $patch -O- | patch -p1
                popd
            fi
            "$G_SOURCES_DIR/$dir_name"/configure --host=$HOST --prefix=$SYSROOT/${G_PREFIX} $EXTRA_CONF
            make -j3
            make install && echo "$what=$step_compile" >> $G_CFG_FILE
            popd
        fi
        if [ $state -eq $step_compile ] ; then
            echo ">> $what is already compiled"
        fi
    }
    
    function download()
    {
        local url="$1"
        local what="$2"
        local filename="$3"
        local state="$4"
    
        if [ $state -lt $step_download ] ; then
            wget "$url" -O "$G_TARBALL_DIR/$filename"
            echo "$what=$step_download" >> $G_CFG_FILE
            tar -C $G_SOURCES_DIR -xf "$G_TARBALL_DIR/$filename"
            . "$G_CFG_FILE" &> /dev/null
        fi
    }
    
    function download_git()
    {
        local url="$1"
        local what="$2"
        local filename="$3"
        local state="$4"
    
        if [ $state -lt $step_download ] ; then
    
            pushd $G_SOURCES_DIR
            git clone $url
            popd
            echo "$what=$step_download" >> $G_CFG_FILE
            . "$G_CFG_FILE" &> /dev/null
        fi
    }
    
    function init()
    {
        local what="$1"
        eval state=\$$what
    
        if [ ! -n "$state" ] ; then
            echo "$what=$step_start" >> $G_CFG_FILE
            . "$G_CFG_FILE" &> /dev/null
        fi
    
        eval state=\$$what
    }
    
    function get_em()
    {
        local url="$1"
        local what="$2"
        local filename=$(basename $url) 
    
        init "$what"
        download "$url" "$what" $filename $state
        eval state=\$$what
        local dir_name=$(get_src_dir $filename)
        build $filename "$what" $dir_name $state false
    }
    
    function get_em_git()
    {
        local url="$1"
        local what="$2"
        local do_bootstrap="$3"
        local filename=$(basename $url) 
        filename=${filename/.git}
    
        init "$what"
        download_git "$url" "$what" $filename $state
        eval state=\$$what
    
        build $filename "$what" $filename $state $do_bootstrap
    }
    
    echo "create directories"
    mkdir -p "$G_TARBALL_DIR" "$G_SOURCES_DIR" "$G_BUILD_DIR" &>/dev/null
    
    
    ########################
    # define the packages we want to compile
    ########################
    
    # this are the dependencies that are missing for our sysroot
    # we will compile them and install the to the $SYSROOT
    #
    # --- BEGIN --- dependencies
    what=libuuid
    url=http://downloads.sourceforge.net/project/libuuid/libuuid-1.0.3.tar.gz
    get_em $url "$what"
    
    what=libxml2
    url=ftp://gd.tuwien.ac.at/pub/libxml/libxml2-sources-2.9.2.tar.gz
    EXTRA_CONF=--without-python
    get_em $url "$what"
    unset EXTRA_CONF
    
    what=popt
    url=ftp://anduin.linuxfromscratch.org/BLFS/svn/p/popt-1.16.tar.gz
    get_em $url "$what"
    
    what=libiconv
    url=http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
    patch=http://data.gpo.zugaina.org/gentoo/dev-libs/libiconv/files/libiconv-1.14-no-gets.patch
    get_em $url "$what"
    unset patch
    
    what=zlib
    url=http://zlib.net/zlib-1.2.8.tar.gz
    init "$what"
    filename=$(basename $url)   
    download "$url" "$what" $filename $state
    if [ $state -eq $step_compile ] ; then
        echo ">> $what is already compiled"
    else
        dir_name=$(get_src_dir $filename)
        pushd $G_SOURCES_DIR/$dir_name
        CC=$G_CC \
        LDSHARED="$G_CC -shared -Wl,-soname,libz.so.1" \
        ./configure --shared --prefix=$SYSROOT/${G_PREFIX}
        make
        make install prefix=$SYSROOT/${G_PREFIX} && echo "$what=$step_compile" >> $G_CFG_FILE
        popd
    fi
    
    # --- END --- dependencies
    
    
    #######################
    # compile lttng related packages and install into $SYSROOT
    what=userspace_rcu
    url=git://git.lttng.org/userspace-rcu.git
    get_em_git $url "$what" true
    
    what=lttng_ust
    url=git://git.lttng.org/lttng-ust.git
    export CPPFLAGS="-I$SYSROOT/${G_PREFIX}/include"
    export LDFLAGS="-L$SYSROOT/${G_PREFIX}/lib -Wl,-rpath-link=$SYSROOT/${G_PREFIX}/lib"
    get_em_git $url "$what" true
    unset CPPFLAGS
    unset LDFLAGS
    
    what=lttng_tools
    url=git://git.lttng.org/lttng-tools.git
    export CPPFLAGS="-I$SYSROOT/${G_PREFIX}/include"
    export LDFLAGS="-L$SYSROOT/${G_PREFIX}/lib -Wl,-rpath-link=$SYSROOT/${G_PREFIX}/lib"
    get_em_git $url "$what" true
    unset CPPFLAGS
    unset LDFLAGS
    
    what=lttng_modules
    url=git://git.lttng.org/lttng-modules.git
    init "$what"
    filename=$(basename $url)   
    filename=${filename/.git}
    download_git "$url" "$what" $filename $state
    if [ $state -eq $step_compile ] ; then
        echo ">> $what is already compiled"
    else
        #dir_name=$(get_src_dir $filename)
        pushd $G_SOURCES_DIR/$filename
        make ARCH=$G_ARCH CROSS_COMPILE=$G_CROSS_COMPILE KERNELDIR=$G_KERNELDIR -j4
        make ARCH=$G_ARCH CROSS_COMPILE=$G_CROSS_COMPILE KERNELDIR=$G_KERNELDIR INSTALL_MOD_PATH=$SYSROOT modules_install \
            && echo "$what=$step_compile" >> $G_CFG_FILE
        popd
    fi
    
    echo
    echo "INFO: the build progress for all packages is tracked in $G_CFG_FILE"
    

    【讨论】:

    • 我收到以下错误:Bison &gt;= 2.4 is required when building from the Git repository. You can set the YACC variable to override automatic detection.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    • 2011-04-18
    • 2020-11-05
    • 2014-10-20
    • 2021-07-20
    相关资源
    最近更新 更多