[U-Boot-Users] Add a new command to U-Boot

Hi all!
I have one doubt. How can I add a new command to U-Boot?
Do I have to use only the macro U_BOOT_CMD() like files .../common/cmd_* or do I have to do more things, like defines, etc.?
And after this is compliled with no error, if I type help in U-Boot's shell, do I see this command like the others?
Best regards, Carlos Silva

On 11/15/05, Carlos Filipe Silva CarlosF.Silva@siemens.com wrote:
Hi all!
I have one doubt. How can I add a new command to U-Boot? Do I have to use only the macro U_BOOT_CMD() like files .../common/cmd_* or do I have to do more things, like defines, etc.?
You do not need the gating defines -- U_BOOT_CMD() will automatically do everything. The defines are only required for including/excluding the command which saves memory if not included. If the command is defined in your board directory, it will probably always be active and not require any gating macros.
And after this is compliled with no error, if I type help in U-Boot's shell, do I see this command like the others?
Yes.
Cliff
-- ======================= Cliff Brake http://bec-systems.com

HI I am working with Freescale MPC8313E-RDB and with it comes their BSP. This provides a u-boot. I want to understand how the u-boot commands work as in where are they defined and in which files. My utlimate goal is to add new u-boot commands and to modify the exsisting commands (if needed) Im a total newbie to uboot. and am looking for a hint as to where to look for.
thanks a lot...
Deepak

Deepak Gopalakrishnan wrote:
HI I am working with Freescale MPC8313E-RDB and with it comes their BSP. This provides a u-boot. I want to understand how the u-boot commands work as in where are they defined and in which files. My utlimate goal is to add new u-boot commands and to modify the exsisting commands (if needed) Im a total newbie to uboot. and am looking for a hint as to where to look for.
thanks a lot...
Deepak
ls common/cmd*.c
Best regards, gvb

yes indeed...thanks a lot... i can guess that adding a command wont be just a walk in the park.....could you tell me wat all this i will have to take care of if i were supposed to write....say another date function...which would display the date in another format.... other than adding it into the makefile and placing it in the common folder...wat shud i do..? thanks alot...
Regards, Deepak
Jerry Van Baren gerald.vanbaren@ge.com 05/07/2009 07:10 PM
To Deepak Gopalakrishnan Deepak.Gopalakrishnan@Lntemsys.com cc u-boot@lists.denx.de Subject Re: [U-Boot] Add a new command to U-Boot
Deepak Gopalakrishnan wrote:
HI I am working with Freescale MPC8313E-RDB and with it comes their BSP.
This
provides a u-boot. I want to understand how the u-boot commands work as
in
where are they defined and in which files. My utlimate goal is to add new u-boot commands and to modify the
exsisting
commands (if needed) Im a total newbie to uboot. and am looking for a hint as to where to
look
for.
thanks a lot...
Deepak
ls common/cmd*.c
Best regards, gvb

Have you looked at code in common/cmd_date.c?
If you see at the end of the file there is macro U_BOOT_CMD() that adds the command date, there is function do_date that is invoked, so if you wanted to implement your own version of date command you will have to implement your own do_date function.
/Subodh
-----Original Message----- From: u-boot-bounces@lists.denx.de [mailto:u-boot-bounces@lists.denx.de] On Behalf Of Deepak Gopalakrishnan Sent: Thursday, May 07, 2009 7:00 AM To: Jerry Van Baren Cc: u-boot@lists.denx.de Subject: Re: [U-Boot] Add a new command to U-Boot
yes indeed...thanks a lot... i can guess that adding a command wont be just a walk in the park.....could you tell me wat all this i will have to take care of if i were supposed to write....say another date function...which would display the date in another format.... other than adding it into the makefile and placing it in the common folder...wat shud i do..? thanks alot...
Regards, Deepak
Jerry Van Baren gerald.vanbaren@ge.com 05/07/2009 07:10 PM
To Deepak Gopalakrishnan Deepak.Gopalakrishnan@Lntemsys.com cc u-boot@lists.denx.de Subject Re: [U-Boot] Add a new command to U-Boot
Deepak Gopalakrishnan wrote:
HI I am working with Freescale MPC8313E-RDB and with it comes
their BSP. This
provides a u-boot. I want to understand how the u-boot
commands work
as
in
where are they defined and in which files. My utlimate goal is to add new u-boot commands and to modify the
exsisting
commands (if needed) Im a total newbie to uboot. and am looking for a hint as to where to
look
for.
thanks a lot...
Deepak
ls common/cmd*.c
Best regards, gvb

thanks to everyone first. im able to write a new command for the u-boot and load it on to the board and it works like a charm. Im explaining the steps here so that it would be helpful in the future: im using a MPC8313e RDB and u-boot-1.3.0. 1) First of all the commands are defined in files present in u-boot/common folder and are the files that start with cmd_*.c 2) now to add a new command create a file in the same format 3) include the necessary header file (depends on what the command would do) 4) "do_<command>" function. This is the function where you have to do what your command intends to do. 5) U_BOOT_CMD( ) function will include your command to the list of commands of u-boot 6) compile it and get the u-boot.bin file 7) load this on to the board. 8) TADAAAAA....ur function is up and running....
this is the content of firrst u-boot command i wrote:
cmd_dgprint.c <code> /* * (C) Copyright 2005 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ #include <common.h> #include <command.h>
int do_dgprint(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { printf("Hi this is a test\n"); return 0; }
U_BOOT_CMD( dgprint, 1, 1, do_dgprint, "dgprint takes no arguments", "this is just to test a function" );
</code> hope this is useful to atleast one person
Regards, Deepak Gopalakrishnan

Excellent, but...
Deepak Gopalakrishnan wrote:
[snip]
this is the content of firrst u-boot command i wrote:
cmd_dgprint.c
<code> /* * (C) Copyright 2005 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version.
...you should put your own copyright with the correct year in it.
Note also that u-boot is licensed using the GPLv2 so, if you distribute u-boot with your modifications linked into it, you must use a GPLv2 compatible license for your code. http://www.gnu.org/philosophy/license-list.html http://en.wikipedia.org/wiki/License_compatibility
Welcome and enjoy your stay in u-boot-land, :-) gvb

I was wondering if there was any documentation or link which explains the uboot relocation scheme. Isnt it better to understand the concept and then try to understand the code.
Regards, Deepak Gopalakrishnan

Hmmm... what about these additional steps: 1) Add .o file to COBJS in ./common/Makefile 2) Add CFG_CMD_<MY_COMMAND> to CONFIG_COMMANDS macro in ./include/configs/<board_name>.h 3) Add CFG_CMD_<MY_COMMAND> definition to ./include/cmd_confdefs.h
are they necesarry? I think that I had to do these also.
BR, Drasko
On Fri, May 8, 2009 at 3:20 PM, Jerry Van Baren gerald.vanbaren@ge.comwrote:
Excellent, but...
Deepak Gopalakrishnan wrote:
[snip]
this is the content of firrst u-boot command i wrote:
cmd_dgprint.c
<code> /* * (C) Copyright 2005 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version.
...you should put your own copyright with the correct year in it.
Note also that u-boot is licensed using the GPLv2 so, if you distribute u-boot with your modifications linked into it, you must use a GPLv2 compatible license for your code. http://www.gnu.org/philosophy/license-list.html http://en.wikipedia.org/wiki/License_compatibility
Welcome and enjoy your stay in u-boot-land, :-) gvb _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hi I was going thruogh the code of u-boot-1.3.0 and was particlarly going through the code in board/freescale/mpc8313erdb cause thats my board. And i found that relocate_code() function is being declared in common.h and called at few instances but could not find the definition of the code. Can anyone help me with this.
thanks and regards, Deepak Gopalakrishnan

I was going thruogh the code of u-boot-1.3.0 and was particlarly going through the code in board/freescale/mpc8313erdb cause thats my board. And i found that relocate_code() function is being declared in common.h and called at few instances but could not find the definition of the code. Can anyone help me with this.
Have a look cpu/mpc83xx/start.S. You may grep it in the u-boot.

On Mon, May 11, 2009 at 9:12 AM, Deepak Gopalakrishnan Deepak.Gopalakrishnan@lntemsys.com wrote:
And i found that relocate_code() function is being declared in common.h and called at few instances but could not find the definition of the code. Can anyone help me with this.
grep -rw relocate_code *

On Mon, May 11, 2009 at 07:42:02PM +0530, Deepak Gopalakrishnan wrote:
Hi I was going thruogh the code of u-boot-1.3.0 and was particlarly going through the code in board/freescale/mpc8313erdb cause thats my board. And i found that relocate_code() function is being declared in common.h and called at few instances but could not find the definition of the code. Can anyone help me with this.
It's in cpu/mpc83xx/start.S.
-Scott

Hi everyone... In the quest of finding the code for relocation i have reached the start.s file present in u-boot-1.1.6\cpu\mpc83xx\ folder. Even its in assembly language (i dont know assembly language beyond movlw) i tried to understand that using the descriptions of the commands given in this site: http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.ai... but im not able to proceed much. Is there any better way to understand this.
thanks & regards, Deepak Gopalakrishnan

Hi Deepak,
In the quest of finding the code for relocation i have reached the start.s file present in u-boot-1.1.6\cpu\mpc83xx\ folder.
This is old code you're looking at. Best would be to look at current code although this doesn't help here.
Even its in assembly language (i dont know assembly language beyond movlw) i tried to understand that using the descriptions of the commands given in this site: http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.ai... but im not able to proceed much. Is there any better way to understand this.
The algorithm is implemented in assembler (at the relocate_code label), so understanding assembler a little bit will be a preliminary to understanding unless you have access to a device which we in german call a "Nürnberger Trichter" [its a mythical mechanical learning device] ;)
Cheers Detlev

Hi all.... this time i want to know is there anywat i can get a application in linux to fetch the bootstrap and u-boot version and display it.... i have no idea how this can be done.... could someone give a start.....im using AT91Bootstrap and u-boot-1.1.5_atmel_1.2 thanks alot
note:sorry if i havent provided enough information for u to help me...im still pretty much new to this...
Regards, Deepak Gopalakrishnan

Dear Deepak Gopalakrishnan,
In message OFCF73D3BF.BBC1DA5F-ON652575BA.00485257-652575BA.00482D67@lntemsys.com you wrote:
this time i want to know is there anywat i can get a application in linux to fetch the bootstrap and u-boot version and display it.... i have no idea how this can be done.... could someone give a start.....im using AT91Bootstrap and u-boot-1.1.5_atmel_1.2
You can use the "fw_printenv" tool in Linux to print U-Boot environment variables, including the "vers" variable (assuming you used "saveenv" at least once).
I have no idea if there is any version information in what you call "the bootstrap" nor how to access it.
Best regards,
Wolfgang Denk

Hi first of all thanks for the reply... Actually we are planning to include a new parameter as version of parameter. I have a tentative idea of writing into the nand flash as a env variable so that i will be able to read it from the u-boot and then from kernel. But im not sure of how to do this. do u have any idea if this is possible. Also how do i add a new env variable in u-boot... thanks and regards, Deepak Gopalakrishnan

Hi Deepak,
Actually we are planning to include a new parameter as version of parameter.
This sounds like mata-programming, although I'm pretty sure that you wnat to do something simple - so obviously I did not understand what you want to do, sorry.
I have a tentative idea of writing into the nand flash as a env variable so that i will be able to read it from the u-boot and then from kernel. But im not sure of how to do this. do u have any idea if this is possible.
Much is possible, but I do not understand what exactly you are trying to do. Maybe you tell us what "high level" goal you try to achieve and then we can decide for ourselves if an environment variable is the way to go here or if other more natural solutions come to mind.
Also how do i add a new env variable in u-boot...
setenv newvariable newvalue
Cheers Detlev

Sorry for not being clear the first time around. My objective is to write a program with which i will be able to access the u-boot version. Also i would like to add a new parameter to the bootstrap which would specify the bootstrap version.(which i want to according to changes i make to bootstrap) i assume that for this i will have to write a version string to the nand flash and then try to access it for the linux kernel....but thats just an idea...have no clue how to....
Regards, Deepak Gopalakrishnan

Hi Deepak,
Sorry for not being clear the first time around. My objective is to write a program with which i will be able to access the u-boot version.
Form Linux that is I guess. If you have CONFIG_VERSION_VARIABLE defined in your U-Boot configuration, then according to README (see, documentation can help sometimes):
- U-Boot Version: CONFIG_VERSION_VARIABLE If this variable is defined, an environment variable named "ver" is created by U-Boot showing the U-Boot version as printed by the "version" command. This variable is readonly.
This variable will also end up in the saved environment, (after at least one saveenv), so you could use the "standard" fw_printenv tools in tools/env/.
Also i would like to add a new parameter to the bootstrap which would specify the bootstrap version.(which i want to according to changes i make to bootstrap)
You;d have to define what "a bootstrap" is for you.
i assume that for this i will have to write a version string to the nand flash and then try to access it for the linux kernel....but thats just an idea...have no clue how to....
Well if "bootstrap" is e.g. a combination of a U-Boot version + a way to boot Linux, you could simply pass an linux commandline option which is not evaluated by the kernel itself, say "bootstrap=..". In Linux you can use /proc/cmdline to read the command line and find your switch, voila.
Cheers Detlev

Hi In my case, these are the things i do in my bootstrap : *Hardware initialization (DDR) and initialise the clock freq *Load u-boot image from Nand flash in RAM *jump to image address
i want to add a version information for this part of the code. Im not in a postion to write a extra nand_write funtion for this bootstrap cause the limit of 4K has almost been covered. What method would u suggest to get around this?
thanks & regards, Deepak Gopalakrishnan

Hi im using u-boot-1.1.5_atmel_1.2 and want to add a new environment variable for uboot version...my doubt --is it enough that i add this in the env_t environment __PPCENV__ . Also for each entry in this structure there is a macro defined, so if i add version as a new env variable..so this is wat i have made change in common/environment.c line 179 where env_t environment __PPCENV__ is defined
#ifdef U_BOOT_VERSION "u-boot_version=" U_BOOT_VERSION #endif
is this enough...? thanks & regards, Deepak Gopalakrishnan

Hi Deepak,
im using u-boot-1.1.5_atmel_1.2 and want to add a new environment variable
I doubt that you will get much support with this U-Boot version here on the list. Use latest code if you want to get help.
for uboot version...my doubt --is it enough that i add this in the env_t environment __PPCENV__ .
This all sounds very fishy - you're working on an ARM platform and you change something with a tag __PPCENV__? Well, let's see, oh it looks like you're looking at what is common/env_embedded.c in latest code.
Note that this is only for board configuration which embed the environment *inside* the text segment, because of unusal requirements of the flash layout. This is definitely not the norm - does your configuration use CONFIG_ENV_IS_EMBEDDED?
Also for each entry in this structure there is a macro defined, so if i add version as a new env variable..so this is wat i have made change in common/environment.c line 179 where env_t environment __PPCENV__ is defined
#ifdef U_BOOT_VERSION "u-boot_version=" U_BOOT_VERSION #endif
is this enough...?
The environment is a dynamic data section which usually lives outside of U-Boot code in its own data location. Of course we can change the environment in a running system, so the compiled in default environment - or even the embedded environment is only relevant if the "normal" environment is not accessible, e.g. when flashing a module for the first time or after a complete erase operation.
Otherwise the "normal" envirnment will be used and even if you change the compiled in set, you will not see much difference if you don't erase the environment on an update.
Do you see the conceptual differences here?
Cheers Detlev
participants (11)
-
Carlos Filipe Silva
-
Cliff Brake
-
Deepak Gopalakrishnan
-
Detlev Zundel
-
Drasko DRASKOVIC
-
Jerry Van Baren
-
Liu Dave-R63238
-
Scott Wood
-
Subodh Nijsure
-
Timur Tabi
-
Wolfgang Denk