U-BOOT介绍以及disk模块源码分析(下)

Part_dos.c文件:

……

static void print_one_part (dos_partition_t *p, int ext_part_sector, int part_num)

{   //打印一个分区信息

    ……

    printf ("%5d/t/t%10d/t%10d/t%2x%s/n",

        part_num, lba_start, lba_size, p->sys_ind,

        (is_extended (p->sys_ind) ? " Extd" : ""));

}

 

static int test_block_type(unsigned char *buffer)

{   //测试块类型

    if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||

        (buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) {

        return (-1);

    }   //不是dos

    if(strncmp(&buffer[DOS_PBR_FSTYPE_OFFSET],"FAT",3)==0)

        return DOS_PBR; /* is PBR */

    return DOS_MBR;     /* Is MBR */

}

 

int test_part_dos (block_dev_desc_t *dev_desc)

{   //测试是否为dos

    unsigned char buffer[DEFAULT_SECTOR_SIZE];

    if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) buffer) != 1) ||

        (buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||

        (buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) {

        return (-1);

    }

    return (0);

}

 

static void print_partition_extended (block_dev_desc_t *dev_desc, int ext_part_sector, int relative, int part_num)

{   //输出与其扩展分区表有关的分区信息

    ……

    //输出所有主要/逻辑分区

    pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);

    for (i = 0; i < 4; i++, pt++) {//文件系统不显示MBR以外的分区

        if ((pt->sys_ind != 0) &&

            (ext_part_sector == 0 || !is_extended (pt->sys_ind)) ) {

            print_one_part (pt, ext_part_sector, part_num);

        }

        /* Reverse engr the fdisk part# assignment rule! */

        if ((ext_part_sector == 0) ||

            (pt->sys_ind != 0 && !is_extended (pt->sys_ind)) ) {

            part_num++;

        }

    }

    //处理扩展分区

    pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);

    for (i = 0; i < 4; i++, pt++) {

        if (is_extended (pt->sys_ind)) {

            int lba_start = le32_to_int (pt->start4) + relative;

 

            print_partition_extended (dev_desc, lba_start,

                          ext_part_sector == 0  ? lba_start

                                    : relative,

                          part_num);

        }

    }

    return;

}

 

static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part_sector,    int relative, int part_num, int which_part, disk_partition_t *info)

{   //获取与其扩展分区表有关的分区信息

    ……

}

……

 

Part_iso.c文件:

int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info, int verb)

{   //获得iso设备块的分区信息

    ……

    //第一部分必须是主要卷

    blkaddr=PVD_OFFSET;

    if (dev_desc->block_read (dev_desc->dev, PVD_OFFSET, 1, (ulong *) tmpbuf) != 1)

   return (-1);

    if(ppr->desctype!=0x01) {

        if(verb)

            printf ("** First descriptor is NOT a primary desc on %d:%d **/n",

                dev_desc->dev, part_num);

        return (-1);

    }

    if(strncmp(ppr->stand_ident,"CD001",5)!=0) {

        if(verb)

            printf ("** Wrong ISO Ident: %s on %d:%d **/n",

                ppr->stand_ident,dev_desc->dev, part_num);

        return (-1);

    }

    ……

    //寻找入口

    if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) {

        if(verb)

            printf ("** Wrong El Torito ident: %s on %d:%d **/n",

                pbr->ident_str,dev_desc->dev, part_num);

        return (-1);

    }

    bootaddr=le32_to_int(pbr->pointer);

    PRINTF(" Boot Entry at: %08lX/n",bootaddr);

    if (dev_desc->block_read (dev_desc->dev, bootaddr, 1, (ulong *) tmpbuf) != 1) {

        if(verb)

            printf ("** Can't read Boot Entry at %lX on %d:%d **/n",

                bootaddr,dev_desc->dev, part_num);

        return (-1);

    }

……

    //找到有效入口,现在寻找分区

    entry_num=0;

    offset=0x20;

    sprintf (info->type, "U-Boot");

    switch(dev_desc->if_type) {

        case IF_TYPE_IDE:

        case IF_TYPE_ATAPI:

            sprintf (info->name, "hd%c%d/n", 'a' + dev_desc->dev, part_num);

            break;

        ……

        default:

            sprintf (info->name, "xx%c%d/n", 'a' + dev_desc->dev, part_num);

            break;

    }

    //bootcatalog (including validation Entry) 必须小于 2048Bytes

    while(offset<2048) {

        pide=(iso_init_def_entry_t *)&tmpbuf[offset];

        if ((pide->boot_ind==0x88) ||

            (pide->boot_ind==0x00)) {    //默认入口的id

            if(entry_num==part_num) { //找到分区

                goto found;

            }

            entry_num++; //记录分区入口数

            offset+=0x20;

            continue;

        }

        if ((pide->boot_ind==0x90) ||   /* Section Header Entry */

            (pide->boot_ind==0x91) ||    /* Section Header Entry (last) */

            (pide->boot_ind==0x44)) {    /* Extension Indicator */

            offset+=0x20; //跳过不使用的入口

        }

        else {

            if(verb)

                printf ("** Partition %d not found on device %d **/n",

                    part_num,dev_desc->dev);

            return(-1);

        }

    }

    ……

    newblkaddr=le32_to_int(pide->rel_block_addr);

    info->start=newblkaddr;

    PRINTF(" part %d found @ %lx size %lx/n",part_num,newblkaddr,info->size);

    return 0;

}

 

int get_partition_info_iso(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info)

{

    return(get_partition_info_iso_verb(dev_desc, part_num, info, 1));

}

 

void print_part_iso(block_dev_desc_t * dev_desc)

{   //打印分区信息

    disk_partition_t info;

    int i;

    if(get_partition_info_iso_verb(dev_desc,0,&info,0)==-1) {

        printf("** No boot partition found on device %d **/n",dev_desc->dev);

        return;

    }

    printf("Part   Start     Sect x Size Type/n");

    i=0;

    do {

        printf (" %2d %8ld %8ld %6ld %.32s/n",

            i, info.start, info.size, info.blksz, info.type);

        i++;

    } while (get_partition_info_iso_verb(dev_desc,i,&info,0)!=-1);

}

int test_part_iso (block_dev_desc_t *dev_desc)

{   测试是否为iso分区

    disk_partition_t info;

    return(get_partition_info_iso_verb(dev_desc,0,&info,0));

}

 

Part_mac.c文件:

int test_part_mac (block_dev_desc_t *dev_desc)

{   //检查是否为有效的mac分区

    ……

    if (part_mac_read_ddb (dev_desc, &ddesc)) {//读块错误,或无有效信息

        return (-1);    }

    n = 1;  //假设最少有一个分区

    for (i=1; i<=n; ++i) {

        if ((dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)&mpart) != 1) ||

            (mpart.signature != MAC_PARTITION_MAGIC) ) {

            return (-1);

        }

        n = mpart.map_count;    更新分区数

    }

    return (0);

}

 

void print_part_mac (block_dev_desc_t *dev_desc)

{   //输出mac分区信息

    ……

    if (part_mac_read_ddb (dev_desc, &ddesc)) {

        /* error reading Driver Desriptor Block, or no valid Signature */

        return;

    }

    n  = ddesc.blk_count;

……

    printf ("Block Size=%d, Number of Blocks=%d, "

        "Total Capacity: %ld.%ld MB = %ld.%ld GB/n"

        "DeviceType=0x%x, DeviceId=0x%x/n/n"

        "   #:                 type name"

        "                   length   base       (size)/n",

        ddesc.blk_size,

        ddesc.blk_count,

        mb.quot, mb.rem, gb.quot, gb.rem,

        ddesc.dev_type, ddesc.dev_id

        );

    n = 1;  //假设最少有一个分区

    for (i=1; i<=n; ++i) {

        ……

        printf ("%20.32s %-18.32s %10u @ %-10u (%3ld%c)/n",

            mpart.type,

            mpart.name,

            mpart.block_count,

            mpart.start_block,

            bytes, c

            );

    }

 

    return;

}

 

static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p)

{   //读取设备描述块信息

    ……

    if (ddb_p->signature != MAC_DRIVER_MAGIC) {

#if 0

        printf ("** Bad Signature: expected 0x%04x, got 0x%04x/n",

            MAC_DRIVER_MAGIC, ddb_p->signature);

#endif

        return (-1);

    }

    return (0);

}

 

static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p)

{   //读取分区描述块信息

    int n = 1;

 

    for (;;) {  //必须从第一个分区开始读描述块,只有这样才能知道一共有多少个分区

        if (dev_desc->block_read (dev_desc->dev, n, 1, (ulong *)pdb_p) != 1) {

            printf ("** Can't read Partition Map on %d:%d **/n",

                dev_desc->dev, n);

            return (-1);

        }

 

        if (pdb_p->signature != MAC_PARTITION_MAGIC) {

            printf ("** Bad Signature on %d:%d: "

                "expected 0x%04x, got 0x%04x/n",

                dev_desc->dev, n, MAC_PARTITION_MAGIC, pdb_p->signature);

            return (-1);

        }

        if (n == part)

            return (0);

        if ((part < 1) || (part > pdb_p->map_count)) {

            printf ("** Invalid partition %d:%d [%d:1...%d:%d only]/n",

                dev_desc->dev, part,

                dev_desc->dev,

                dev_desc->dev, pdb_p->map_count);

            return (-1);

        }

        n = part;   //更新分区数

    }

}

 

int get_partition_info_mac (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)

{   //获取mac分区的信息

    mac_driver_desc_t   ddesc;

    mac_partition_t     mpart;

 

    if (part_mac_read_ddb (dev_desc, &ddesc)) {

        return (-1);

    }

 

    info->blksz = ddesc.blk_size;

 

    if (part_mac_read_pdb (dev_desc, part, &mpart)) {

        return (-1);

    }

 

    info->start = mpart.start_block;

    info->size  = mpart.block_count;

    memcpy (info->type, mpart.type, sizeof(info->type));

    memcpy (info->name, mpart.name, sizeof(info->name));

 

    return (0);

}

 

四.常用U-BOOT命令介绍

1.list 得到所有命令列表
2.help: help usb,
列出USB功能的使用说明
3.ping
:注:只能开发板PING别的机器
4.setenv:
设置互环境变量:
5.setenv serverip 192.168.0.1
6.setenv ipaddr 192.168.0.56
7.setenv bootcmd
tftp 32000000 vmlinux; kgo 32000000
8.saveenv:
保存环境变量

9.
在设置好环境变量以后, 保存变量值
10.tftp: tftp 32000000 vmlinux,
serverIP=环境变量中设置的serverip)中/tftpdroot/ 下的vmlinux通过TFTP读入到物理内存32000000处。
11.kgo:
起动没有压缩的linux内核,kgo 32000000
12.bootm:
起动UBOOT  TOOLS制作的压缩LINUX内核
, bootm 3200000
13.protect:
FLASH进行写保护或取消写保护, protect on 1:0-3(就是对第一块FLASH0-3扇区进行保护)protect off 1:0-3取消写保护

14.erase:
删除FLASH的扇区, erase 1:0-2(就是对每一块FLASH0-2扇区进行删除)
15.cp:
在内存中复制内容, cp 32000000 0 40000(把内存中0x32000000开始的0x40000字节复制到0x0
)
16.mw:
RAM中的内容写操作, mw 32000000 ff 10000(把内存0x32000000开始的0x10000字节设为
0xFF)
17.md:
修改RAM中的内容, md 32000000(内存的起始地址)

18.usb:
lusb start:
起动usb 功能
lusb info:
列出设备
lusb scan:
扫描usb storage(u )设备
19.fatls
:列出DOS FAT文件系统, 如:fatls usb 0列出第一块U盘中的文件
20.fatload:
读入FAT中的一个文件,如:fatload usb 0:0 32000000 aa.txt
21.
USB中的aa.txt 读到物理内存0x32000000处!

22.flinfo:
列出flash的信息
23.loadb:
准备用KERMIT协议接收来自kermit或超级终端传送的文件。
24.nfs
nfs 32000000 192.168.0.2:aa.txt , 把192.168.0.2(LINUX NFS文件系统)中的NFS文件系统中的aa.txt 读入内存0x32000000处。

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

gshaojie

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值