Six, transplant uboot-set default environment variables, perfect u-boot

Source: Internet
Author: User

Document Time: 2018-08-14

Cross compiler: arm-linux-gcc-4.3.2

Ubuntu version: 16.04

Uboot version: 2013.10

1, modify uboot default environment variable

The Uboot serial print information obtained in the previous section is as follows:

As you can see, read the bad CRC, use the default environment variable, search for "Using default environment", locate the Set_default_env function located in the Common/env_common.c file, locate here:

As you can guess from the above code, the default environment variables are saved in Default_environment and entered into default_environment:

This content is more, we take one of the Bootargs as an example, search Bootargs words, you can see the following statement in the other veneer:

BOOTARGS=NOINITRD Root=/dev/mtdblock3 INIT=/LINUXRC console=ttysac0

root specifies the file system location

INIT specifies the first application that executes after the kernel is started

console specifies which terminal to use, here the ttySAC0 refers to the serial port 0

The same is true for other macros, such as those we are familiar with:

"bootcmd=", the command used to start the kernel

"bootdelay=", Uboot start Countdown, the default value is 5s, only set the Bootcmd, it is useful

"baudrate=", baud rate, default is 115200

"ipaddr=", IP address

"serverip=", Server IP address

"netmask=", Subnet mask

"gatewayip=", Gateway

"mtdparts=", MTD partition table

Follow the other veneer add the corresponding macro in Include/configs/jz2440.h to set the default environment variable, the code is as follows (red for adding code):

#define Config_bootargs "NOINITRD root=/dev/mtdblock3 init=/linuxrc console=ttysac0"//bootargs
#define CONFIG_BOOTCOMMAND "NAND read 0x30000000 0x60000 0x200000; Bootm 0x30000000 "//bootcmd
#define CONFIG_ETHADDR 00:0c:29:3b:22:2a//mac Address

/* Autoboot */
#define Config_bootdelay5
#define Config_boot_retry_time-1
#define Config_reset_to_retry
#define Config_zero_bootdelay_check

#define Config_netmask255.255.255.0
#define Config_ipaddr192.168.2.90
#define Config_serverip192.168.2.101

2, set mtdparts partition

1), set environment variable save location

Although the previous print message appears, "Bad crc,using default environment", we can do what we want by manually setting the environment variables, but we have not used the Save command to save it to Flash,

This is because in flash, we do not partition the UBOOT,PARAMS,KERNEL,ROOTFS, save command cannot be saved to the location we want to save, so in order not to destroy the original content of Flash, the Save command was not used before

So, first we find the location of save in the code, and on Uboot, enter the Save-help command, printed as follows:

Search keyword saveenv :

It is found that many files have a definition of the saveenv function, because we only need to save the environment variables to flash, so we just have to focus on the flash related files, as shown in:

common/env_nand.c file, and common/env_flash.c file, the former is to save the environment variable to NAND, the latter is saved to nor, open common directory under the Makefile file, View the macros on which the two files are compiled:

As you can see, compiling a env_flash.c file requires Config_env_is_in_flash macros, compiling ENV_NAND.C files requires Config_env_is_in_nand macros, and finding the two macros in the jz2440.h file has no definition:

found that only the definition of the and nor related macros, there is no definition of the NAND-related macros, and in this case, NAND boot does not support nor flash operations, so we save the environment variable in NAND Flash,

Refer to the other veneer definition of the NAND macro, modify the code:

// #define CONFIG_ENV_ADDR            (Config_sys_flash_base + 0x070000) // #define Config_env_is_in_flash // #define Config_env_size            0x10000#define config_env_is_in_nand/        * u-boot ENV in NAND Flash  */#define config_env_size            0x20000        //128kb#define Config_env_offset        0x80000 //to uboot reserved 512kb

There is also a Config_env_range macro, this macro can not be defined, if not defined, in the ENV_NAND.C, it will be set to Config_env_size

Recompile, burn write uboot, you can use the Save command to save the environment variable.

2), set partition, support Mtdparts command

If you want to view partitions such as Uboot,kernel, enter Mtdparts in Uboot to print as follows:

found that the command is not supported, modify the code so that uboot support mtdparts command, search mtdparts, frequent in commong/cmd_mtdparts.c, guess related to this file,

Open the Makefile in the common directory and find that you want to compile the cmd_mtdparts.c file, define the Config_cmd_mtdparts macro as shown in:

Search Config_cmd_mtdparts, refer to the other veneer on this macro settings, in Jz2440.h set the relevant macro to support Mtdparts, modify the code as follows (red part to add code):

/* mtdparts command line support */#define CONFIG_MTD_DEVICE/        * needed for mtdparts commands */#define CONFIG_FLASH_CF I_mtd#define mtdids_default        "nand0=jz2440-0"/* DEFAULT MTD partition Table */#define MTDPARTS_DEFAULT    " mtdparts=jz2440-0:512k (u-boot), "\                            " 128k (params), "\                            " 4m (kernel), "\                            "-(ROOTFS); "\

Then modify the previously set bootcmd (in jz2440.h) and the red part to modify the code:

#define CONFIG_BOOTCOMMAND "NAND read 0x30000000 kernel; BOOTM 0x30000000 "//

After the modification, we also modify the Board_init_r function (in the ARCH/ARM/LIB/BOARD.C file), and the code is modified as follows (the red part adds code):

    run_command ("mtdparts default", 0);       Added by Zhyy    /**      /for (;;) {        main_loop ();    }

This way, Uboot executes the mtdparts default command once each time it is started, so that it is automatically partitioned according to the default parameters, so that the mtdparts is set.

Compile, burn write, test, enter Mtd/mtdparts in Uboot, print as follows:

As can be seen, Uboot has supported the Mtdparts command, print information and our settings match, then use the file name to burn the files, enter the command:

Burn Write Uboot command:

30000000 U-boot.binnand erase.part u-30000000 uboot
Reset //restart Uboot

Burn Write kernel command:

300000003000000030000000        // boot kernel

Burn Write JFFS2 file system (not currently supported for Yaffs file system):

30000000 xxx.jffs2        //XXX indicates file system name  30000000  4a0000 $ Filesizereset

3, Crop Uboot

After the above steps compiled Uboot about 378kb, this is really too big (because the function of Uboot is to start the kernel, to pass parameters to the kernel), so next we need to crop uboot, uboot many files are based on the macros in Makefile to compile , and these macros are basically defined in include/configs/jz2440.h, so we need to modify the Jz2440.h file to remove the unwanted macros:

1), remove USB-related macros

/* *********************************************************** * USB Support (currently only works with D-cache off) * *  *//#define CONFIG_USB_OHCI  //#define CONFIG_USB_OHCI_S3C24XX//#define Config_usb_keyboard//  #define Config_usb_storage//#define Config_dos_partition

2), remove RTC support

/* *********************************************************** * RTC ********************************************  *//#define CONFIG_RTC_S3C24X0

3), remove the BOOTP option

/**//#define CONFIG_BOOTP_BOOTFILESIZE//#define CONFIG _bootp_bootpath//#define Config_bootp_gateway//#define CONFIG_BOOTP_ HOSTNAME

4), remove support for some file systems

/**//#define CONFIG_CMD_FAT//#define CONFIG_CMD_EXT2 // #define Config_cmd_ubi // #define CONFIG_CMD_UBIFS #define Config_cmd_mtdparts#define config_mtd_device#define config_mtd_partitions// #define CONFIG_YAFFS2 // #define Config_rbtree

Compile and print the following error:

Open Include/usb.h, navigate to line 169, and block the following code:

// #error USB lowlevel not defined

Compile and print the following error:

Open the common directory under Makefile, navigate to the Cmd_date keyword, as follows:

You can see that the compilation cmd_date.c needs config_cmd_date support, find the macro in Jz2440.h, and block it:

// #define Config_cmd_date

Compile and print the following error:

Open the common directory under Makefile, navigate to the USB keyword, as follows:

You can see that the compilation USB.C needs the support of the macro CONFIG_CMD_USB, find the macro in Jz2440.h, block it:

// #define CONFIG_CMD_USB

Compile, success, look at the size of the uboot, only 221kb, cut almost

4, support yaffs file system

In our uboot, enter NAND write.yaffs 30000000 0 0 to print as follows:

As can be seen, our uboot currently does not support yaffs file system burning, Next, modify the code to enable it to support yaffs file system burning write.

When we use the NAND command, we go into the Do_nand function (in the COMMON/CMD_NAND.C file), open the Cmd_nand.c file, navigate to the Do_nand function, and the code is as follows:

As you can see, to support yaffs, you need to add a macro config_cmd_nand_yaffs to add the macro in Jz2440.h:

#define Config_cmd_nand_yaffs

Then enter the Nand_write_skip_bad function (located in the drivers/mtd/nand/nand_util.c file):

intNand_write_skip_bad (nand_info_t *nand, loff_t offset, size_t *length, size_t*actual, loff_t Lim, U_char *buffer,intFlags) {

.......

if(!need_skip &&!) (Flags &with_drop_ffs)) { //need to modify rval=nand_write (NAND, offset, length, buffer); //Normal copy, regardless of OOB issues if(Rval = =0) return 0; //Copy finished, return *length =0; printf ("NAND write to offset%llx failed%d\n", offset, rval); returnRval; } while(Left_to_write >0) {size_t Block_offset= offset & (Nand->erasesize-1); size_t write_size, Truncated_write_size; Watchdog_reset (); if(Nand_block_isbad (NAND, offset & ~ (Nand->erasesize-1)) {printf ("Skip bad block 0x%08llx\n", offset& ~ (Nand->erasesize-1)); Offset+ = Nand->erasesize-Block_offset; Continue; } if(Left_to_write < (BlockSize-Block_offset)) Write_size=Left_to_write; Elsewrite_size= BlockSize-Block_offset, #ifdef config_cmd_nand_yaffsif(Flags &With_yaffs_oob) { intpage, pages; size_t pagesize= nand->writesize; size_t Pagesize_oob= pagesize + nand->oobsize; structMtd_oob_ops ops; Ops.len=pagesize; Ops.ooblen= nand->oobsize; Ops.mode=Mtd_ops_auto_oob; //need to modify ops.ooboffs=0; Pages= Write_size/Pagesize_oob; for(page =0; Page < pages; page++) { //cycle burn write each page watchdog_reset (); Ops.datbuf=P_buffer; Ops.oobbuf= Ops.datbuf +pagesize; Rval= Mtd_write_oob (NAND, offset, &OPS); //Burn write OOB if(Rval! =0) Break; //Burn Write failed, exit For loop .......}

Put the above if (!need_skip &&!) ( Flags & with_drop_ffs)) change to if (!need_skip &&!) ( Flags & with_drop_ffs) &&! (Flags&with_yaffs_oob))

Because avoiding input NAND write.yaffs directly into that judgment, then do not execute the following while (Left_to_write > 0) statement

put the above Mtd_ops_auto_oob modified to Mtd_oob_raw(I don't know why, refer to someone else's)

(PS: This paragraph refers to others )

Compile, burn, test, and enter the following commands:

30000000 xxx.yaffs2        //XXX stands for file system name  30000000  4a0000 $filesize

Print the following information:

Indicates that the download was successful, indicating that Uboot has supported the Yaffs file system.

So far, Uboot's transplant has basically been completed.

5, patching

Use the following command to clear the make compiled file before patching

Make distcleanrm u-boot.dis

Then enter the following command to Patch:

CD.. MV u-boot-2013.10 u-boot--xjf u-boot-2013.10. tar.bz2            // Unzip create source file Diff-urn u-boot-2013.10 u-boot-. 10_zhyy > u-boot- Zhyy.patch            //Note that the source file is in front of the new file after

Using the Package command, go to u-boot-2013.10 and enter the command:

Patch-p1 < u-boot-10_zhyy.patch

Uboot transplant to this end ...

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.