On Wed, Apr 18, 2012 at 2:14 AM, Wu Zhangjin <[email protected]> wrote:
> Hi, Lucas
>
> Thanks very much for you help, shared my solutions below:
>
> On 4/16/12, Lucas Meneghel Rodrigues <[email protected]> wrote:
>> On Mon, 2012-04-16 at 11:43 +0800, Wu Zhangjin wrote:
>>> ---------- Forwarded message ----------
>>> From: Wu Zhangjin <[email protected]>
>>> Date: Mon, Apr 16, 2012 at 11:40 AM
>>> Subject: Question about cross compiling support
>>> To: Autotest Team <[email protected]>
>>>
>>>
>>> Hi, Autotest Team
>>>
>>> Thanks very much for your work on the autotest support of Linux, I'm
>>> currently playing with this powerful tool but I encountered a problem,
>>> that is:
>>>
>>> How to compile a kernel in a local machine and install it to a target
>>> board, then, reboot the target with the new kernel.
>>>
>>> For example, my local machine is an X86 PC, the target machine is an
>>> ARM board, I want to cross compile the kernel from X86 PC and then
>>> install
>>> it to the ARM board, how can I simply implement this?
>>>
>>> BTW, my target board doesn't support the popular Grub or Lilo
>>> bootloader, but instead, it uses a Uboot bootloader, so, it is not
>>> suitable to use
>>> the old install() and boot() methods of the kernel class, is that
>>> possible to add a new Bootloader support for Uboot? or simply hack the
>>> install() and boot() methods?
>>
>> Hi Wu,
>>
>> I don't have a good answer for your query just yet. I saw a while ago
>> patches from the guys working on ChromeOS that allow cross compilation,
>> but I am not sure how to use it. Maybe Scott Zawalski knows more about
>> cross compilation, I'm copying him in this reply.
>>
>
> For the kernel cross compilation, I did find two 'simple' solutions
> (Will paste the using demo's tomorrow):
>
> 1. Build the kernel on a 'localhost' SSHHost, but we need to
> explicitly set the autodir to another directory, it should differ from
> the default one: '/usr/local/autotest', for example,
> '/usr/local/kbuild', otherwise, there will be conflicts.
>
> Note: The existing LocalHost class doesn't work as the argument of
> kernel.build() for it lacks lots of required functions.

server/site_tests/cross_kbuild_and_test.srv:

# Start
from autotest_lib.client.common_lib import git
from autotest_lib.client.bin import utils

build_file = """

from autotest_lib.client.common_lib import git

# git repo
repo = 'git://path/to/repo_dir'
branch = 'master'
repodir = '/tmp/linux'
cfg = '/path/to/defconfig'

# Annotate the cross compiler path
os.environ["PATH"] = "/path/to/cross-compiler-bin:" + os.getenv("PATH")

r = git.get_repo(uri=repo, branch=branch, destination_dir=repodir)
testkernel = job.kernel(r)
testkernel.config(cfg)
testkernel.build()
"""

# Run some remote tests
control_file = """
job.run_test('sleeptest')
"""

results_dir = "job_results"

# Cross compile the kernel image
def kbuild(machine):
    host = hosts.create_host(machine)
    host.set_autodir("/usr/local/kbuild")
    at = autotest_remote.Autotest(host)
    at.run(build_file, results_dir, host)

def run(machine):
    host = hosts.create_host(machine)
    print "Install the kernel image to target board"
    kinstall(host)                       // see below
    print "Reboot to the new kernel"
    host.reboot()
    at = autotest_remote.Autotest(host)
    while True:
        at.run(control_file, results_dir, host)
        host.reboot()

kbuild("localhost")
job.parallel_simple(run, machines)
# End

Run the test:

$ ./server/autoserv -m target_board_ip_or_hostname -s
server/site_tests/cross_kbuild_and_test.srv

>
> 2. Use the utils tools to run 'cp /path/to/defconfig .config', 'make
> oldconfig', 'make -j8 zImage' commands one by one directly, but this
> will not benefit from the Kernel classes.
>

# Local build
def kbuild():
    repo = 'git://path/to/repo_dir'
    branch = 'master'
    repodir = '/tmp/linux'
    cfg = '/path/to/defconfig'

    os.environ["PATH"] = "/path/to/cross-compiler-bin:" + os.getenv("PATH")
    r = git.get_repo(uri=repo, branch=branch, destination_dir=repodir)
    os.chdir(repodir)
    utils.system("cp %s .config" % cfg)
    utils.make("oldconfig")
    utils.make("-j8 zImage")

Replace the above kbuild() call with this one ...

> Seems both of them require to add the path of the cross compiler to
> the PATH env variable explicitly, not sure if there is a better method
> to use the existing PATH (included the path to cross compiler) in
> /etc/profile or ~/.bashrc.
>
>> Otherwise, I'd have to do a bit of research, as I don't work with ARM
>> boards.
>>
>
> In order to install the cross-compiled kernel image to the board with
> Uboot, I simply give up the the install() and boot() functions of the
> kernel class and add my own function to copy the kernel image from my
> localhost to a directory(e.x /path/to/zimage) of the target board with
> the send_file() method of the host, and then, install it with the dd
> command: dd if=/path/to/zimage of=/dev/zimage_partition. after that,
> issue a host.reboot() will let the board run with the new kernel.
>

kernel_image = "/tmp/linux/arch/<ARCH>/boot/zImage"
zimage_partition = /dev/zimage_partition

# Install the kernel image
def kinstall(host):
    remote_kernel_image = host.get_tmp_dir() + "/zImage"
    host.send_file(kernel_image, remote_kernel_image)
    host.run("dd if=%s of=%s" % (remote_kernel_image, zimage_partition))

Regards,
Wu Zhangjin

>> I'll tell you that I have recently talked with some folks interested in
>> cross compilation support. I'd love to enable you guys to use autotest
>> for your use cases, but we'd need some help with documentation of the
>> feature, and helping with patches.
>>
>
> Cross compilation may speedup the testing of the slow embedded targets
> for it saves the time of sending source files between the server and
> the client and also save the time of compilation, if the clients are
> the same, the time saving may be more explicit since the clients may
> share the same cross-compiled binaries.
>
> Hope I can join in, but I'm a newbie to autotest currently ;-)
>
> Best Regards,
> Wu Zhangjin
>
>> Cheers,
>>
>> Lucas
>>
>>> Thanks in advance.
>>>
>>> Best Regards,
>>> Wu Zhangjin
>>> _______________________________________________
>>> Autotest mailing list
>>> [email protected]
>>> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
>>
>>
>>
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to