Migrate the mtdparts partition of u-boot-1.1.6

Publisher:中华古风Latest update time:2023-10-12 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Unlike higher versions of u-boot, the mtdparts command does not have a separate file like cmd_mtdparts to implement.


However, if you search for uboot, you can see the following code in cmd_jffs2.c:


 1 U_BOOT_CMD(

 2     mtdparts,    6,    0,    do_jffs2_mtdparts,

 3     "mtdparts- define flash/nand partitionsn",

 4     "n"

 5     "    - list partition tablen"

 6     "mtdparts delalln"

 7     "    - delete all partitionsn"

 8     "mtdparts del part-idn"

 9     "    - delete partition (e.g. part-id = nand0,1)n"

10     "mtdparts add

11         

12 

13         ...


It can be seen that the mtdpart command is implemented in the do_jffs2_mtdparts function.


Look at the do_jffs2_mtdparts function again:


int do_jffs2_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])

{

    if (argc == 2) { //Check the number of parameters here first. Note that we usually use the mtdpart command without parameters. We will make modifications here below.

        if (strcmp(argv[1], "default") == 0) {

            setenv("mtdids", (char *)mtdids_default);  //mtdids使用mtdids_default

            setenv("mtdparts", (char *)mtdparts_default); //mtdparts uses mtdparts. The above two default configurations are implemented in the configuration file, such as smdk2410.h

            setenv("partition", NULL);


            mtdparts_init();

            return 0;

        } else if (strcmp(argv[1], "delall") == 0) {

            /* this may be the first run, initialize lists if needed */

            mtdparts_init();


            setenv("mtdparts", NULL);


            /* devices_init() calls current_save() */

            return devices_init();

        }

    }


        ...


In addition, at the beginning of the cmd_jffs2.c file, note that there are several macro definitions:


#include


#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)


#include


#if (CONFIG_COMMANDS & CFG_CMD_NAND)

#ifdef CFG_NAND_LEGACY

#include

#else /* !CFG_NAND_LEGACY */


and


#ifdef CONFIG_JFFS2_CMDLINE

/* default values for mtdids and mtdparts variables */

#if defined(MTDIDS_DEFAULT)

static const char *const mtdids_default = MTDIDS_DEFAULT;

#else

#warning "MTDIDS_DEFAULT not defined!"

static const char *const mtdids_default = NULL;

#endif


besides


static int part_validate_nand(struct mtdids *id, struct part_info *part)

{

#if defined(CONFIG_JFFS2_NAND) && (CONFIG_COMMANDS & CFG_CMD_NAND)

    /* info for NAND chips */

    nand_info_t *nand;

Here you need to define three macros and default configuration:


#define CONFIG_JFFS2_CMDLINE 1

#define CONFIG_JFFS2_NAND    1


#define MTDIDS_DEFAULT "nand0=nandflash0"

#define MTDPARTS_DEFAULT "mtdparts=nandflash0:256k@0(bootloader),"

                            "128k(params),"

                            "2m(kernel),"

                            "-(root)"


1 #define CONFIG_COMMANDS  

2                         CFG_CMD_JFFS2    |


Above, after the compilation is passed, the kernel cannot be started immediately. Pay attention to the startup parameters at this time:


#define CONFIG_BOOTCOMMAND "nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0" //Because the kernel has not been recognized yet


This should be changed to:


#define CONFIG_BOOTCOMMAND "nand read.jffs2 0x30007FC0 0x60000 0x200000; bootm 0x30007FC0"


//Here, the kernel has been programmed into the Nand, and then the nand read command is used to read the 30007fc0 address of the sdram. The address of the kernel in the nand is 0x60000, and the size is 2M.


The mtdpart command still cannot be used here because of the mtdpart parameter problem mentioned above.


Since we don't use parameters, then:


 1 if (argc == 2) {

 2         if (strcmp(argv[1], "default") == 0) {

 3             setenv("mtdids", (char *)mtdids_default);

 4             setenv("mtdparts", (char *)mtdparts_default);

 5             setenv("partition", NULL);

 6 

 7 mtdparts_init();

 8             return 0;

 9         } else if (strcmp(argv[1], "delall") == 0) {

10             /* this may be the first run, initialize lists if needed */

11 mtdparts_init();

12 

13             setenv("mtdparts", NULL);

14 

15             /* devices_init() calls current_save() */

16             return devices_init();

17         }

18     }

19 

20     /* make sure we are in sync with env variables */

21     if (mtdparts_init() != 0)

22         return 1;

23 

24     if (argc == 1) {

25         list_partitions();

26         return 0;

27     }


Then, the following four functions are not executed:


setenv("mtdids", (char *)mtdids_default);

setenv("mtdparts", (char *)mtdparts_default);

setenv("partition", NULL);


mtdparts_init(); //Among them, mainly this is not executed


Treatment measures: There are two types


The first one is to remove the parameter parsing and directly execute the mtdparts_init() function. The code is as follows:


 1 int do_jffs2_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])

 2 {

 3                 //by Flinn

 4         setenv("mtdids", (char *)mtdids_default);

 5         setenv("mtdparts", (char *)mtdparts_default);

 6         setenv("partition", NULL);

 7 

 8 mtdparts_init();

 9     if (argc == 2) {

10         if (strcmp(argv[1], "default") == 0) {

11             //setenv("mtdids", (char *)mtdids_default);

12             //setenv("mtdparts", (char *)mtdparts_default);

13             //setenv("partition", NULL);

14 

15 //mtdparts_init();

16             return 0;

17         } else if (strcmp(argv[1], "delall") == 0) {

18             /* this may be the first run, initialize lists if needed */

19 mtdparts_init();

20 

21             setenv("mtdparts", NULL);

22 

23             /* devices_init() calls current_save() */

24             return devices_init();

25         }

26     }    


The second kind, as Wei Dongshan did, add: in the main_loop function of main.c:


 1 #ifdef CONFIG_JFFS2_CMDLINE

 2 extern int mtdparts_init(void); //Execute the init function first

 3     if (!getenv("mtdparts"))

 4     {

 5 run_command("mtdparts default", 0); //Call the default configuration again

 6     }

 7     else

 8     {

 9 mtdparts_init();

10     }

11 #endif


Both of the above methods are possible.


Reference address:Migrate the mtdparts partition of u-boot-1.1.6

Previous article:Porting u-boot-1.1.6 NOR support
Next article:Develop and implement an application plan for elevator buffer reset time test system in EVC environment

Recommended posts

Raspberry Pi Official Manual 2023
ExplorethetruepotentialoftheRaspberryPiwiththenew,OfficialManual2023.Withover200pagesofamazingprojects,funtutorials,practicalguides,andclearreviews,ithaseverythingyouneedtomastertheRaspberryPi! TheOfficial
dcexpert MicroPython Open Source section
Android 5.0 BLE low-power Bluetooth slave device application
Android'slow-powerBluetoothapplicationsareverycommon.Smartbraceletsandwatchesareeverywhere,andtheybasicallyuseBLEcommunicationtoexchangedata.BLEisbasicallywellsupportedonbothAndroidandIOSterminaldevices,soithasa
fish001 Wireless Connectivity
EEWORLD University----[High Precision Laboratory] Motor Drive: Brushless DC Motor Driver
MotorDrive:BrushlessDCMotorDriver:https://training.eeworld.com.cn/course/5605Motordrive:BrushlessDCmotordriverMotordrive:BrushlessDCmotordriverBrushlessDCmotordriversofferhugesystem-leveladvantagesMotordrive:4brush
hi5 Analog electronics
Design a PCB diagram based on FPGA electronic piano
1.Basicrequirements: (1)Ithasgeneralplayingfunctionsandvariablevolume(atleasttwolevels) (2)Realizetheautomaticplaybackfunctionofasong (3)Functionofdigitallydisplayingmusicalnotationnotes (4)Makearegulatedpowe
ma.hh PCB Design
Circuit parameters of real op amp
Thisisavoltagefollowercircuit.Thecircuitinputis0-10V(10Kohmvariableresistor),thepowersupplyis0-15V(singlepowersupply),andtheopampisLM358.Myfriendsaidthisistheworstopamponearth! ThequestionIwanttoaskt
bigbat Analog electronics
RK3568J "Hongmeng System" is officially released, making your product development faster and easier!
ThisarticlemainlyintroducestheOpenHarmonysystemdemonstrationofRockchipRK3568J.Thedevelopmentenvironmentisasfollows: OpenHarmonySDKcompilationenvironment:Ubuntu18.04.464bit U-Boot:U-Boot-2017.09 Kernel:Linux-5.10.97
别打牛牛 ARM Technology
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号