RT-Thread 编译

下面是在裁剪并且编译x86平台的RT-Thread的教程:

首先检查linux(我的是32位ubuntu 15.10 默认安装python )上是否安装了Python(必须是2.7?)

然后安装scons

ubuntu@ubuntu:~$ python -V
Python 2.7.10
ubuntu@ubuntu:~$ sudo apt-get install scons

然后编辑 rt-thread-master/bsp/x86/rtconfig.h,对RTT进行裁剪:

/* RT-Thread config file */
#ifndef __RTTHREAD_CFG_H__
#define __RTTHREAD_CFG_H__

/* RT_NAME_MAX*/
#define RT_NAME_MAX        8

/* RT_ALIGN_SIZE*/
#define RT_ALIGN_SIZE    8

/* PRIORITY_MAX */
#define RT_THREAD_PRIORITY_MAX    32

/* Tick per Second */
#define RT_TICK_PER_SECOND        1000

/* SECTION: RT_DEBUG */
/* Thread Debug */
#define RT_DEBUG
#define RT_THREAD_DEBUG

#define RT_USING_OVERFLOW_CHECK

/* Using Hook */
#define RT_USING_HOOK

/* Using Software Timer */
/* #define RT_USING_TIMER_SOFT */
#define RT_TIMER_THREAD_PRIO        4
#define RT_TIMER_THREAD_STACK_SIZE    512
#define RT_TIMER_TICK_PER_SECOND    10

/* SECTION: IPC */
/* Using Semaphore*/
#define RT_USING_SEMAPHORE

/* Using Mutex */
#define RT_USING_MUTEX

/* Using Event */
#define RT_USING_EVENT

/* Using MailBox */
#define RT_USING_MAILBOX

/* Using Message Queue */
#define RT_USING_MESSAGEQUEUE

/* SECTION: Memory Management */
/* Using Memory Pool Management*/
#define RT_USING_MEMPOOL

/* Using Dynamic Heap Management */
#define RT_USING_HEAP

/* Using Small MM */
#define RT_USING_SMALL_MEM

/* SECTION: Device System */
/* Using Device System */
#define RT_USING_DEVICE

/* SECTION: Console options */
#define RT_USING_CONSOLE
/* the buffer size of console*/
#define RT_CONSOLEBUF_SIZE    128

#define IDLE_THREAD_STACK_SIZE        1024  /* idle stack 1K */

/* SECTION: finsh, a C-Express shell */
#define RT_USING_FINSH
/* Using symbol table */
#define FINSH_USING_SYMTAB
#define FINSH_USING_DESCRIPTION


#endif

像文件系统支持之类的宏,我都删除了(强迫症 >_<|||),大家可以对比原来的文件看一下。

然后编辑 rt-thread-master/bsp/x86/rtconfig.py ,3处做了修改,修改后结果如下:

import os

# toolchains options
ARCH='ia32'
CPU=''
CROSS_TOOL='gcc'

if os.getenv('RTT_CC'):
    CROSS_TOOL = os.getenv('RTT_CC')

# cross_tool provides the cross compiler
# EXEC_PATH is the compiler execute path, for example, CodeSourcery,

if  CROSS_TOOL == 'gcc':
    PLATFORM     = 'gcc'
    EXEC_PATH     = ''

elif CROSS_TOOL == 'keil':
    print '================ERROR============================'
    print 'Not support keil yet!'
    print '================================================='
    exit(0)
elif CROSS_TOOL == 'iar':
    print '================ERROR============================'
    print 'Not support iar yet!'
    print '================================================='
    exit(0)

if os.getenv('RTT_EXEC_PATH'):
    EXEC_PATH = os.getenv('RTT_EXEC_PATH')

BUILD = 'debug'

if PLATFORM == 'gcc':
    # toolchains
    PREFIX = ''
    CC = PREFIX + 'gcc'
    AS = PREFIX + 'gcc'
    AR = PREFIX + 'ar'
    LINK = PREFIX + 'gcc'
    TARGET_EXT = 'elf'
    SIZE = PREFIX + 'size'
    OBJDUMP = PREFIX + 'objdump'
    OBJCPY = PREFIX + 'objcopy'

    DEVICE = ' -mtune=generic'
    CFLAGS = DEVICE + ' -Wall -fno-stack-protector'
    AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
    LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-ia32.map,-cref,-u,_start -T x86_ram.lds -nostdlib'

    CPATH = ''
    LPATH = ''

    if BUILD == 'debug':
        CFLAGS += ' -O0 -gdwarf-2'
        AFLAGS += ' -gdwarf-2'
    else:
        CFLAGS += ' -O2'

    POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'

编译结果:

ubuntu@ubuntu:~/rt-thread-master/bsp/x86$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build/bsp
CC build/bsp/applications/application.o
CC build/bsp/applications/startup.o
CC build/bsp/drivers/board.o
CC build/bsp/drivers/console.o
CC build/bsp/drivers/keyboard.o
CC build/bsp/drivers/serial.o
CC build/kernel/components/finsh/cmd.o
CC build/kernel/components/finsh/finsh_compiler.o
CC build/kernel/components/finsh/finsh_error.o
CC build/kernel/components/finsh/finsh_heap.o
CC build/kernel/components/finsh/finsh_init.o
CC build/kernel/components/finsh/finsh_node.o
CC build/kernel/components/finsh/finsh_ops.o
CC build/kernel/components/finsh/finsh_parser.o
CC build/kernel/components/finsh/finsh_token.o
CC build/kernel/components/finsh/finsh_var.o
CC build/kernel/components/finsh/finsh_vm.o
CC build/kernel/components/finsh/shell.o
CC build/kernel/components/finsh/symbol.o
CC build/kernel/components/libc/minilibc/ctype.o
CC build/kernel/components/libc/minilibc/math.o
CC build/kernel/components/libc/minilibc/qsort.o
CC build/kernel/components/libc/minilibc/rand.o
CC build/kernel/components/libc/minilibc/stdlib.o
CC build/kernel/components/libc/minilibc/string.o
CC build/kernel/components/libc/minilibc/time.o
CC build/kernel/libcpu/ia32/__udivsi3.o
CC build/kernel/libcpu/ia32/__umodsi3.o
CC build/kernel/libcpu/ia32/backtrace.o
CC build/kernel/libcpu/ia32/interrupt.o
CC build/kernel/libcpu/ia32/showmem.o
CC build/kernel/libcpu/ia32/stack.o
CC build/kernel/libcpu/ia32/trap.o
In file included from drivers/include/bsp.h:17:0,
                 from /home/ubuntu/rt-thread-master/libcpu/ia32/trap.c:17:
/home/ubuntu/rt-thread-master/libcpu/ia32/trap.c: In function 'rt_hw_idt_init':
/home/ubuntu/rt-thread-master/libcpu/ia32/trap.c:49:29: warning: taking address of expression of type 'void'
   SETGATE(idt[i], 0, GD_KT, &Xdefault, 0);
                             ^
drivers/include/i386.h:69:38: note: in definition of macro 'SETGATE'
  (gate).gd_off_15_0 = (rt_uint32_t) (off) & 0xffff;  \
                                      ^
/home/ubuntu/rt-thread-master/libcpu/ia32/trap.c:49:29: warning: taking address of expression of type 'void'
   SETGATE(idt[i], 0, GD_KT, &Xdefault, 0);
                             ^
drivers/include/i386.h:77:39: note: in definition of macro 'SETGATE'
  (gate).gd_off_31_16 = (rt_uint32_t) (off) >> 16;  \
                                       ^
/home/ubuntu/rt-thread-master/libcpu/ia32/trap.c: In function 'rt_hw_trap_irq':
/home/ubuntu/rt-thread-master/libcpu/ia32/trap.c:95:4: warning: implicit declaration of function 'rt_hw_interrupt_handle' [-Wimplicit-function-declaration]
    rt_hw_interrupt_handle(T_DEFAULT);
    ^
CC build/kernel/src/clock.o
CC build/kernel/src/device.o
CC build/kernel/src/idle.o
CC build/kernel/src/ipc.o
CC build/kernel/src/irq.o
CC build/kernel/src/kservice.o
CC build/kernel/src/mem.o
CC build/kernel/src/mempool.o
CC build/kernel/src/object.o
CC build/kernel/src/scheduler.o
CC build/kernel/src/thread.o
CC build/kernel/src/timer.o
LINK rtthread.elf
objcopy -O binary rtthread.elf rtthread.bin
size rtthread.elf
   text       data        bss        dec        hex    filename
  73773       3484       9864      87121      15451    rtthread.elf
scons: done building targets.
ubuntu@ubuntu:~/rt-thread-master/bsp/x86$ 

 OK!上面编译过程中没用到的文件夹可以删除了。

 

欢迎各位转载,转载文章之后请在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。

你可能感兴趣的:(RT-Thread 编译)