U-boot introduction and DISK module source code analysis (below)

xiaoxiao2021-03-06  62

Part_dos.c file:

......

Static void print_one_part (DOS_PARTITION_T * P, INT EXT_PART_Sector, INT Part_NUM)

{// Print a partition information

......

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)

{// test block type

IF ((Buffer [DOS_PART_MAGIC_OFFSET 0]! = 0x55) ||

(Buffer [DOS_PART_MAGIC_OFFSET 1]! = 0xAA)) {

Return (-1);

} // is not a DOS block

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)

{// Test is DOS block

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_exteded (block_dev_desc_t * dev_desc, int ext_part_sector, int in)

{// Output partition information related to its extension partition table

......

// Output all major / logical partitions

Pt = (DOS_PARTITION_T *) (Buffer DOS_PART_TBL_OFFSET);

For (i = 0; i <4; i , pt ) {// file system does not show partitions other than MBR

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

(EXT_PART_Sector == 0 ||! is_exteded)) {

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_exteded (Pt-> Sys_ind)))) {

Part_num ;

}

}

// Handling extension partition

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)

{// Get partition information related to its extension partition table

......

}

......

Part_iso.c file:

INT GET_PARTITION_INFO_ISO_VERB (Block_DEV_DESC_T * DEV_DESC, INT Part_NUM, DISK_PARTITION_T * INFO, INT VERB)

{/ / Partition information for ISO device blocks

......

// The first part must be the main volume

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 dec 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:% SON% D:% D ** / N",

PPR-> Stand_ident, dev_desc-> dev, part_num);

Return (-1);

}

......

// Looking for entrance

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);

}

......

/ / Find the effective entrance, now look for partition

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 (include Validation Entry) must be less than 2048bytes

While (Offset <2048) {

PIDE = (ISO_INIT_DEF_ENTRY_T *) & TMPBUF [OFFSET];

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

(Pide-> Boot_ind == 0x00)) {// The ID header of the default entry

IF (entry_num == part_num) {// Find partition

Goto Found;

}

Entry_num ; // Record the number of partition portions

OFFSET = 0x20;

CONTINUE;

}

IF ((pide-> boot_ind == 0x90) || / * section header entry * /

(Pide-> Boot_ind == 0x91) || / * Section Header Entry (Last) * /

(pide-> boot_ind == 0x44)) {/ * extension indeicator * /

OFFSET = 0x20; // Skip unused portals

}

Else {

IF (Verb)

Printf ("** part% d not found on device% d ** / n",

Part_num, dev_desc-> dev);

Return (-1);

}

}

......

NEWBLKADDR = Le32_to_int (pide-> rel iblock_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)

{// Print partition information

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 STT 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)

{Test is an ISO partition

Disk_partition_t info;

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

}

Part_mac.c file:

INT TEST_PART_MAC (Block_Dev_desc_t * dev_desc)

{// Check if it is a valid MAC partition

......

IF (part_mac_read_ddb (dev_desc, & ddesc)) {// read block error, or no valid information

Return (-1);

n = 1; // Hypothesis at least one partition

For (i = 1; i <= n; i) {

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

(mpart.signaature! = mac_partition_magic)) {

Return (-1);

}

N = mpart.map_count; Update partition number

}

Return (0);

}

Void Print_Part_mac (Block_Dev_desc_t * dev_desc)

{// output MAC partition information

......

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; // Hypothesis at least one partition

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) {// Read Device Description Block Information

......

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)

{// read partition descriptor information

INT n = 1;

For (;;) {// must start reading the block from the first partition, only this can know how many partitions

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 part% 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; // Update the number of partitions

}

}

INT GET_PARTITION_INFO_MAC (Block_DEV_DESC_T * DEV_DESC, INT Part, Disk_Partition_t * Info)

{// Get information on the MAC partition

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);

four. Commonly use U-boot command introduction

1.List gets all command list 2.Help: Help USB, listing the usb function instructions 3.ping: Note: You can only develop board PING other machine 4.Stenv: Setting mutual environment variable: 5.senv ServerIP 192.168. 0.16.Stenv ipaddr 192.168.0.567.senv bootcmd 'TFTP 32000000 VMLinux; kgo

32000000

'

8.SaveEnv: Save Environment Variable 9. After setting the environment variable, save the variable value 10.TFTP: TFTP 32000000 VMLinux, put the server (IP = environment variable) / tftpdroot / under the VMLinux read in TFTP Go to 3200,000 physical memory. 11.Kgo: KGO 3200000012.BOOTM: Bootm 320000013.Protect: Write the Flash to write to flash, protectOn 1: 0-3 (就 对 对) The first FLASH 0-3 sector is protected), protect off 1: 0-3 Cancel write protection 14.rase: Delete Flash sectors, ERASE 1: 0-2 (is 0-2 for each Flash Sector delete) 15.cp: copy content in memory, CP 32000000 0 40000 (copy 0x40000 bytes starting in memory to 0x40000 bytes to 0x0) 16.MW: Write an operation in RAM, MW 32000000 FF 10000 (Set the 0x10000 bytes starting in memory 0x32000000) 17.md: Modify the content in the RAM, MD 32000000 (Memory start address) 18.USB: LUSB Start: Start USB Function LUSB INFO: List device LUSB SCAN : Scan the USB Storage (U disk) device 19.fatls: Lists the DOS FAT file system, such as FATLS USB 0 lists files in the first U disk 20.fatload: read into a file in FAT, such as: Fatload USB 0: 0 32000000 aa.txt21. Read Aa.txt in USB to 0x32000000! 22.flinfo: Lists Flash information 23.LoadB: Prepare to receive files from kermit or super terminal transfer with Kermit protocol. 24.NFS: NFS 32000000 192.168.0.2:Aa.txt, the AA.TXT in the NFS file system in 192.168.0.2 (LINUX NFS file system) is read into memory 0x32000000.

转载请注明原文地址:https://www.9cbs.com/read-84698.html

New Post(0)