您的位置:首页 > 运维架构 > Linux

arm-6410友善之臂 uboot linux内核.文件系统移植

2014-09-04 20:33 447 查看
小编使用的arm是友善之臂6410 由于小编能力有限,暂时只会移植开发板资料自带的uboot,下面就与大家分享如何移植现有的uboot

1)将u-boot_nand-ram256烧写到nand flash中

小编是用MINItool(sd卡启动,superboot烧写),将u-boot_nand-ram256烧写到开发板的nand flash中。

2)开两个终端。窗口A选择要等待USB串口下载的项目,窗口B则是运行串口程序,将要下载的东西,下载到nand flash中。如下

窗口A:(注意此时ARM是用nand flash进行启动)

##### FriendlyARM U-Boot(2011-10, NAND) for 6410 #####
[f] Format the nand flash
[v] Download u-boot.bin
[k] Download Linux/Android kernel
[y] Download root yaffs2 image
[u] Download root ubifs image
[a] Download Absolute User Application

Download Nboot.nb0 for WinCE
[w] Download WinCE NK.nb0
[s] Set the boot parameter of Linux
 Boot Linux
[q] Quit to shell
NAND(SLC): 256 MiB, RAM: 256 MiB
LCD type, firmware version: 3 1426
Enter your Selection:
[b]我们要进行的是K linux内核的烧写,还有文件系统的烧写(即y/u)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

一内核的烧写

窗口A

按K

Downloading Linux/Android Kernel from USB...
Insert a OTG cable into the connector!
等待USB串口烧写

窗口B

ysy@ysy-System-Product-Name:~$ sudo ./dnw zImage 0
如果显示

Target usb device not found!

则可能是没有装usb,或者是usb没插好

sudo apt-get install libusb-dev (装了之后,如果下次遇到这样的问题,见USB线进行拔插即可)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

二文件系统的烧写

/init: line 103: can't open /r/dev/console: no such file
像这类问题(找不到控制台),就是没有对文件系统进行烧写就启动linux

窗口A(按u/y)

Enter your Selection:u
Downloading ubifs-image from USB...
Insert a OTG cable into the connector!
窗口B

ysy@ysy-System-Product-Name:~$ sudo ./dnw rootfs_rtm_6410-slc.ubi  0
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

窗口A

按b

[<c0172228>] (__irq_svc+0x48/0xa0) from [<c05174f4>] (_raw_spin_unlock_irqresto)
[<c05174f4>] (_raw_spin_unlock_irqrestore+0x10/0x38) from [<c01b5d24>] (__setup)
[<c01b5d24>] (__setup_irq+0x23c/0x308) from [<c01b5ebc>] (request_threaded_irq+)
[<c01b5ebc>] (request_threaded_irq+0xcc/0x11c) from [<c0512aa4>] (s3c_hsotg_pro)
[<c0512aa4>] (s3c_hsotg_probe+0x190/0x5b0) from [<c03143f0>] (platform_drv_prob)
[<c03143f0>] (platform_drv_probe+0x14/0x18) from [<c03135e4>] (driver_probe_dev)
[<c03135e4>] (driver_probe_device+0xa8/0x158) from [<c03136f4>] (__driver_attac)
[<c03136f4>] (__driver_attach+0x60/0x84) from [<c03128cc>] (bus_for_each_dev+0x)
[<c03128cc>] (bus_for_each_dev+0x4c/0x78) from [<c0312f68>] (bus_add_driver+0xa)
[<c0312f68>] (bus_add_driver+0xa8/0x224) from [<c0313940>] (driver_register+0xa)
[<c0313940>] (driver_register+0xa8/0x12c) from [<c01684d8>] (do_one_initcall+0x)
[<c01684d8>] (do_one_initcall+0xbc/0x190) from [<c0008adc>] (kernel_init+0x98/0)
[<c0008adc>] (kernel_init+0x98/0x148) from [<c0173668>] (kernel_thread_exit+0x0)
发现窗口A停在这里

复位即可

uboot移植成功!

下面添加串口烧写代码dnw.c, gcc dnw.c -o dnw ./dnw即可使用

/* dnw2 linux main file. This depends on libusb.
*
* License:        GPL
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <usb.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define                 QQ2440_SECBULK_IDVENDOR        0x5345
#define                QQ2440_SECBULK_IDPRODUCT        0x1234

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)
{
printf("idVendor:0x%x\t,ipProduct:0x%x\n",dev->descriptor.idVendor,dev->descriptor.idProduct);
if( QQ2440_SECBULK_IDVENDOR==dev->descriptor.idVendor
&&  QQ2440_SECBULK_IDPRODUCT==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 <file> <addr>\n\n");
}

unsigned char* prepare_write_buf(char *filename, unsigned int *len, int addr)
{
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) = addr;                //download address
*((u_int32_t*)write_buf+1) = fs.st_size + 10;        //download size;

int i;
unsigned short sum=0;
for(i=8; i<fs.st_size+8; i++)
{
sum += write_buf[i];
}

write_buf [fs.st_size + 8] = sum & 0xff;
write_buf [fs.st_size + 9] = sum >> 8;

*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(3!=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, strtol(argv[2],NULL, 16));
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: