Anatomy The storage structure of the SD card when the SD card is started during embedded device development (taking Samsung exynos4412 as an example)

Source: Internet
Author: User

Anatomy The storage structure of the SD card when the SD card is started during embedded device development (taking Samsung exynos4412 as an example)
Currently, in the embedded development of high-performance products, it is very popular to Use SD cards to replace previous jlinks. Moreover, MCU manufacturers are increasingly supportive of SD card startup, instead, they do not pay much attention to JLINK (but they are retained ). Some companies that develop development boards provide their own bootloader (only some of which are their own code, and I will talk about it below). The original code is not open to the public, however, the u-boot source code that everyone like is open-source, but like the friendly arm, they have to use their superboot to load the u-boot binary code into land flash, EMMC and other external rom devices, which also means that we have to use superboot to complete the u-boot burning and writing, they are not open-source code, but have binary executable files for us to use. For those who are used to open-source code, there is no doubt that they are always uncomfortable. So we will introduce how to complete our development without superboot. Follow up the modified uboot Code provided by the Samsung manufacturer. In the main directory, we can see a subdirectory named sd-fuse, which has a makefile, view the makefile. We can know that it is used to compile and generate a tool named mkbl2, which is part of the makefile (this can be used to generate the tool named mkbl2 ): 25 SOURCES = $ (OBJECTS :. o =. c) 26 27 all: 28 $ (CC) $ (CFLAGS) mkbl2 V310-EVT1-mkbl2.c 29 $ (CC) $ (CFLAGS) sd_fdisk sd_fdisk.c so what is the role of this mkbl2 tool, or it can do it, through the above can see its trusted source file V310-EVT1-mkbl2.c, then we certainly look at this source file Hello: 66 for (I = 0; I <(14*1024) -4; I ++) 67 {68 checks Um + = (unsigned char) (Buf [I]); 69} 70 * (unsigned int *) (Buf + I) = checksum; 71 72 fp = fopen (argv [2], "wb"); 73 if (fp = NULL) 74 {75 printf ("destination file open error \ n "); 76 free (Buf); 77 return-1; 78} 79 80 a = Buf; 81 nbytes = fwrite (a, 1, BufLen, fp); 82 83 if (nbytes! = BufLen) 84 {85 printf ("destination file write error \ n"); 86 free (Buf); 87 fclose (fp); 88 return-1; 89} 90 91 free (Buf); 92 fclose (fp); 93 94 return 0; 95} The above is part of the code, it can be seen that it is from a specified file (This specified file will be said below, is actually a binary file) to reproduce the first 14 K content, put the first (14*1024-4) = 14332 bytes checksum (checksum) to get a 4-byte checkcode, Put it after 14332 bytes, and output a new 14 K binary file. After learning about its function, we can continue to trace it. There is a level-2 subdirectory of tiny4412 under the sd-fuse directory. the following files are displayed: E4412_N.bl1.bin E4412_tzsw.bin fast_fuse.sh sd_fusing.sh, there are two script files: fast_fuse.sh sd_fusing.sh, and two binary files provided by Samsung: E4412_N.bl1.bin E4412_tzsw.bin, The sd-fusing.sh is for the SD card, then let's take a look at what this script is used: 44 E4412_UBOOT = .. /.. /u-boot.bin 45 MKBL2 = .. /mkbl2 46 47 if [! -F $ {E4412_UBOOT}]; then 48 echo "Error: u-boot.bin NOT found, please build it & try again." 49 exit-1 50 fi 51 52 if [! -F $ {MKBL2}]; then 53 echo "Error: can not find host tool-mkbl2, stop. "54 exit-1 55 fi 56 57 # <make bl2> 58 ${MKBL2 }$ {E4412_UBOOT} bl2.bin 14336 59 60 ############# ###################### 61 # fusing images 62 63 signed_bl1_position = 1 64 bl2_position = 17 65 uboot_position = 49 66 tzsw_position = 705 67 68 #<BL1 fusing> 69 echo "---------------------------------------" 70 echo "BL1 fusing" 71 dd I Flag = dsync oflag = dsync if =. /E4412_N.bl1.bin of = $1 seek = $ signed_bl1_position 72 73 #<BL2 fusing> 74 echo "75 echo" BL2 fusing "76 dd iflag = dsync oflag = dsync if =. /bl2.bin of = $1 seek = $ bl2_position 77 78 # <u-boot fusing> 79 echo "fill" 80 echo "u-boot fusing" 81 dd iflag = dsync oflag = dsync if =$ {E4412_UBOOT} of = $1 seek = $ uboot_po Sition 82 83 # <TrustZone S/W fusing> 84 echo "-------------------------------------" 85 echo "TrustZone S/W fusing" 86 dd iflag = dsync oflag = dsync if =. /E4412_tzsw.bin of = $1 seek = $ tzsw_position 87 88 # <flush to disk> 89 sync 90 91 ################## ################# 92 # <Message Display> 93 echo "-----------------------------------------" 94 echo "U-boot image is fused successfully. "95 echo" Eject SD card and insert it again. "Analysis: 44 E4412_UBOOT = .. /.. /u-boot.bin 45 MKBL2 = .. /mkbl2 58 $ {MKBL2} $ {E4412_UBOOT} bl2.bin 14336 previously mentioned mkbl2 is to generate a u-boot.bin and verify, generate the file bl2.bin, then look at the following: 63 signed_bl1_position = 1 64 bl2_position = 17 65 uboot_position = 49 66 tzsw_position = 705 71 dd iflag = dsync oflag = dsync if =. /E4412_N.bl1.bin of = $1 seek = $ signed_bl1_position 76 dd iflag = dsync oflag = dsync if =. /bl2.bin of = $1 see K = $ bl2_position 81 dd iflag = dsync oflag = dsync if =$ {E4412_UBOOT} of = $1 seek = $ uboot_position 86 dd iflag = dsync oflag = dsync if =. /E4412_tzsw.bin of = $1 seek = $ tzsw_position 89 sync. We can see that we use the dd command (you can use man for its usage) place E4412_N.bl1.bin in the 1block of the SD card and start to 17block. There are 16 blocks in total, 8 kb in total, (-rw-r -- 1 chenpan 8192 Mar 22 2013 E4412_N.bl1.bin-rw-r -- 1 chenpan 94208 Mar 22 2013 E4412_tzsw.bin from here we also see the E4412-N.bl1.bi N the file size is 8192 bytes, Which is exactly 8 K). Here someone will ask why the first 512 bytes of the SD card are filled with 0 instead of starting from the 0th block of the SD card, it is said on the Internet that some partition information is originally used here. In addition, the. binfile is similar to the specified block (17-49,49-705,705-) written into the SD card, and sync is automatically filled with NUL (0 ). So our SD card storage structure is on top. You can also draw images to deepen your image. Next let's take a look at superboot. bin, We typed the first 560 Bytes: $ 2017-n 560 running 0000000 running 0ac1 3351 33ec 3e84 3b80 2c81 running 0007 ea00 fffe eaff fffe running fffe eaff 00e8 e59f 0000 e590 1102 running 0001 e110 0024 0a00 00d8 e59f 0000 e5900000050 0001 e310 0020 0a00 00cc e59f 0000 e5900000060 0003 e200 0003 e330 0004 0a00 00bc e59f0 000070 0000 e590 0001 e310 0000 0a00 0016 000000ac e59f 0000 e590 0003 e200 0003 00000004 0a00 009c e59f 0000 00000001 00000000 0a00 000c ea00 0000e59f 4000 e59f 2088 e592 5000 e59f 6084 e15400000c0 f005 01a0 007c e59f 0000 e590 0007 e2000108d0 0007 e330 0000 1a00 0010 ea00 0068 e59f00000e0 1068 e59f 3068 e59f 0001 e150 0003 0a0000000f0 0003 e151 2004 34 90 2004 3481 fffb 3aff0000100 1050 e59f 2000 e3a0 0001 e153 2004 34830000110 fffc 3aff 0010 ea00 fffe eaff 0eb7 ea000000120 07b6 ea00 0600 1002 12c0 1002 1188 10020000130 1184 1002 1198 1002 1194 0d10 fcba 1398 1002 2a44 02020000150 2a44 0202 2a44 0202 2a44 0202 4070 e92d0000160 0031 eb00 4070 e6ff 0034 eb00 50ff e2000000170 01a2 eb00 6000 e1a0 0004 e1a0 00df eb0000 00180 0000 e355 000c 1a00 0036 eb00 0000 00000004 1a00 0078 00001078 e59f 0980 0000f000 e320 fffe eaff 006c 00001064 00000984 e581 ffd9 ebff 0013 ea00 0000 00000004 0a00 0054 e59f 1048 e59f 0984 e582131d0 ffd2 ebff 000c ea00 015f eb00 0001 e35000001e0 0004 1a00 0038 e59f 1028 e5800001f0 ffca ebff 0984 ea00 0004 e59f 0028 e59f0000200 1014 e581 f000 e32 0 fffe eaff 0000 e3a00000210 8070 e8bd 0060 dead 0000 1002 50b1 50b0000220 50b2 50b1 50b3 50b1 0061 dead 00a8 e59f0000230 then the first 560 bytes of E4412_N.bl1.bin are given: $ 2017-n 560 running 0000000 69a3 18d3 running 66b9 6bd1 6ed5 79d4 running 0007 ea00 fffe eaff fffe running fffe eaff 00dc e59f 0000 e590 1102 running 0001 e110 0024 0a00 00cc 00000000 00000001 e310 0020 0a00 00c0 e59f 0000 00000003 e200 0003 e330 0004 0a00 00b0 00000000 e590 0001 e310 0000 0a00 0016 000000a0 e59f 0000 e590 0003 e200 0003 00000004 0a00 0090 million 0000 e590 0001 e31000000a0 0000 0a00 000c ea00 2080 e59f 4000 e59200000b0 207c e59f 5000 e592 6078 e59f 0006 e15400000c0 f005 01a0 0070 e59f 0000 e590 0007 e2000000 0d0 0007 e330 0000 1a00 07c8 ea00 005c 0000105c e59f 305c e59f 0001 e150 0003 5E 0003 e151 2004 3490 2004 fffb 00003481 e59f 1044 e3a0 2000 e153 0001 fffc 3aff 002b ea00 2004 12c0 34830000110 10020000120 1188 1002 1184 1002 1198 1002 1194 10020000130 0020 0202 0024 0d10 fcba 0202 1398 10020000140 2aa4 0202 2aa4 0202 2aa4 0202 2aa4 02020000150 1201 e3a0 000c e591 0000 running 0002 running 1000 e3a0 2104 e59f 1008 e582 ff1e running 00fc e59f 0700 e590 0702 e380 0b02 running 10ec e59f 0700 e581 0001 e1a0 0704 running 0402 e380 0040 e380 0704 e581 0001 running 0900 running 0402 0080 e380 0900 e582131b0 0907 e301 1719 e281 0008 e581 1842 e282131c0 0008 e581 ff1e e12f 4070 e92d ffdf ebff00001d0 ffe6 ebff 002b eb00 4070 e6ff 002e eb0000001 E0 50ff e200 019d eb00 6000 e1a0 0004 running 00da eb00 0000 running 000a 1a00 0030 running 0000 e350 0004 1a00 0068 running 1068 running 0980 running f000 e320 fffe eaff 005c running ff30 e12f 000f ea00 0000 e356 0a000000230 have you found anything? Yes, the operation code from 16th bytes to 512 bytes is the same, that is, the starting position of superboot is also the startup Code provided by Samsung, superboot integrates BL1 and superboot. If any arm-gnu assembler wants to know the specific work of superboot, you can perform disassembly (arm-linux-objdump-D-B binary-m arm Superboot4412.bin> superboot. asm & vim superboot. ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.