0%

折腾6410核心板--配置环境

最近又折腾回嵌入式,上次折腾嵌入式已经是几年前玩弄2440核心板,这次换了6410核心板,想必大同小异,但是没想到并不是这样,这次的板是一个师姐买的,是友善出品的开发板。

  1. 一开始,先装上一个ubuntu 12.04的desktop版,首先配置终端,根据我之前的步骤ubuntu使用kermit代替超级终端,由于已经出了ubuntu 12.10,所以说编译kermit的openssl版本与我本机的openssl版本不相符,叫我重新编译,编译你妹呀,这不是想逼我升级么,我果断不鸟它,换了几行命令
    1
    2
    3
    sudo apt-get install minicom
    #配置minicom,配置比特率,把流控制等yes的都选no,并save as dfl
    sudo minicom -s
    大不了换一个终端。
  2. 配置dnw,根据我之前的文章linux下利用dnw烧写文件,又死活都配置不了,说我传输的文件太大,你妹,bootloader才一百k左右,这样都算大?换一个dnw2的神器。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    /* dnw2 linux main file. This depends on libusb.
    *
    * You should use lsusb to find out the actual vender ID & product ID of board.
    *
    * Author: Fox
    * Ace Strong
    * License: GPL
    *
    */

    #include
    #include
    #include
    #include
    #include
    #include

    #define QQ2440_VENDOR_ID 0x5345
    #define QQ2440_PRODUCT_ID 0x1234
    #define FS2410_VENDOR_ID 0x5345
    #define FS2410_PRODUCT_ID 0x1234
    #define EZ6410_VENDOR_ID 0x04e8
    #define EZ6410_PRODUCT_ID 0x1234

    #define EZ6410_RAM_BASE 0x50200000
    #define FS2410_RAM_BASE 0x30200000

    /*
    // FS2410
    #define RAM_BASE FS2410_RAM_BASE
    #define VENDOR_ID FS2410_VENDOR_ID
    #define PRODUCT_ID FS2410_PRODUCT_ID
    */
    // EZ6410
    #define RAM_BASE EZ6410_RAM_BASE
    #define VENDOR_ID EZ6410_VENDOR_ID
    #define PRODUCT_ID EZ6410_PRODUCT_ID

    struct usb_dev_handle * open_port()
    {
    struct usb_bus *busses, *bus;

    usb_init();
    usb_find_busses();
    usb_find_devices();

    busses = usb_get_busses();
    for(bus=busses;bus;bus=bus->next)
    {
    struct usb_device *dev;
    for(dev=bus->devices;dev;dev=dev->next)
    {
    if( VENDOR_ID==dev->descriptor.idVendor
    && PRODUCT_ID==dev->descriptor.idProduct)
    {
    printf("Target usb device found!\n");
    struct usb_dev_handle *hdev = usb_open(dev);
    if(!hdev)
    {
    perror("Cannot open device");
    }
    else
    {
    if(0!=usb_claim_interface(hdev, 0))
    {
    perror("Cannot claim interface");
    usb_close(hdev);
    hdev = NULL;
    }
    }
    return hdev;
    }
    }
    }

    printf("Target usb device not found!\n");

    return NULL;
    }

    void usage()
    {
    printf("Usage: dnw2 \n\n");
    }

    unsigned char* prepare_write_buf(char *filename, unsigned int *len)
    {
    unsigned char *write_buf = NULL;
    struct stat fs;

    int fd = open(filename, O_RDONLY);
    if(-1==fd)
    {
    perror("Cannot open file");
    return NULL;
    }
    if(-1==fstat(fd, &fs))
    {
    perror("Cannot get file size");
    goto error;
    }
    write_buf = (unsigned char*)malloc(fs.st_size+10);
    if(NULL==write_buf)
    {
    perror("malloc failed");
    goto error;
    }

    if(fs.st_size != read(fd, write_buf+8, fs.st_size))
    {
    perror("Reading file failed");
    goto error;
    }

    printf("Filename : %s\n", filename);
    printf("Filesize : %d bytes\n", fs.st_size);

    *((u_int32_t*)write_buf) = RAM_BASE; //download address
    *((u_int32_t*)write_buf+1) = fs.st_size + 10; //download size;

    *len = fs.st_size + 10;
    return write_buf;

    error:
    if(fd!=-1) close(fd);
    if(NULL!=write_buf) free(write_buf);
    fs.st_size = 0;
    return NULL;

    }

    int main(int argc, char *argv[])
    {
    if(2!=argc)
    {
    usage();
    return 1;
    }

    struct usb_dev_handle *hdev = open_port();
    if(!hdev)
    {
    return 1;
    }

    unsigned int len = 0;
    unsigned char* write_buf = prepare_write_buf(argv[1], &len);
    if(NULL==write_buf) return 1;

    unsigned int remain = len;
    unsigned int towrite;
    printf("Writing data ...\n");
    while(remain)
    {
    towrite = remain>512 ? 512 : remain;
    if(towrite != usb_bulk_write(hdev, 0x02, write_buf+(len-remain), towrite, 3000))
    {
    perror("usb_bulk_write failed");
    break;
    }
    remain-=towrite;
    printf("\r%d%\t %d bytes ", (len-remain)*100/len, len-remain);
    fflush(stdout);
    }
    if(0==remain) printf("Done!\n");
    return 0;
    }
    只需要安装libusb-dev
    1
    2
    sudo apt-get install libusb-dev
    gcc -lm -o dnw2 dnw2.c -lusb
    这样就可以编译通过,要支持更多的开发板,只需要用lsusb查看新的USB设备的venderIDproductID,然后添加相应的宏定义即可。反正我的6410在宏定义中已经有了,我就没有改动。
  3. 配置好这两样东西后,就可以往板里烧程序,成功后,我就想怎么拿它的内核编译一下,还有编译一下busybox,注意,我这里只是拿它光盘中的内核和busybox来编译,没有什么技术含量,坑爹的是,建立交叉编译环境,我修改了/etc/environment的参数,然后arm-linux-gcc -v,提示找不相应的文件或目录,我擦,经过无数次重启和不断修改后,问题依旧,所以我敲了which arm-linux-gcc,发现返回了我配置的路径,证明环境变量修改已经成功了,为什么还找不到呢,原因只有一个,友善提供的交叉编译器是32位的,我忍。
    sudo apt-get install ia32-libs
    敲了上面的命令后,兼容32位的程序,这样就可以找到arm-linux-gcc,然后编译好内核,编译好busybox,把内核也拷进入板子上了,准备打包镜像。
  4. 坑爹的事情还没有完,因为友善那个坑爹的superboot,只要配置一下sd卡,可以从sd卡中烧bootloader、内核、根文件系统到nand flash中,这个也没什么,你的根文件系统100多M用sd卡烧快,那你就用呗,反正我烧几M的根文件系统用dnw就行了,坑爹的是superboot不支持yaffs的根文件系统,支持ubi格式的,这也没什么,那我用mkubimage来打包文件,不用mkyaffsimage而已,坑爹的是提示
    1
    2
    error while loading shared libraries: liblzo2.so.2: 
    cannot open shared object file: No such file or directory
    那也没什么sudo apt-get install liblzo2-dev就行了 我的是64位系统,你apt-get的lib也是64位的,怎么用,那也没什么,直接上网找一个liblzo2的库,32位的。
    感受:以后面对友善这些厂家,还是装32位的系统吧。