Editing Kernel command-line arguments inside Kernel - linux-kernel

U-boot passes kernel command-line parameters. In my requirement I want to edit these parameters in the kernel source tree and don't want to change U-boot code. I am using 2.6.35 kernel.
So please guide me which part of the kernel source I have to check for this.

Follow this procedure:
Enter the kernel config by typing make menuconfig
Enter the menu Processor type and features
Enable Built-in kernel command line
Specify your command line by clicking on Built-in kernel command string
Select Built-in command line overrides boot loader arguments if you want bootargs to be ignored

You can change if from kernel config:-
+CONFIG_CMDLINE="foo=1"
+CONFIG_CMDLINE_EXTEND=y
Check runtime:-
$cat /proc/cmdline

Related

How to set the environment of a SDK in a script file?

Some operations related to embedded Linux (e.g. Kernel build etc) requires the use of toolchain, thus the first command is:
$ source /opt/fslc-x11/2.2.1/environment-setup-armv7at2hf-neon-fslc-linux-gnueabi
I'd like to place this command inside a .sh script for Ubuntu: what's the right way?

Is there any way to harcode Linux kernel boot options? [duplicate]

This question already has answers here:
Editing Kernel command-line arguments inside Kernel
(2 answers)
Closed 2 years ago.
I am working on SoC and I need to pass the kernel root partition name:
root=/dev/mmcblk0p1
I can not pass it via uEnv.txt. Is there any way to pass this boot option using the kernel configuration files or something like this?
You can do this via your bootloader. I am going to assume you are using the most common bootloader for SoC's: U-Boot. U-Boot has a variable called bootargs that normally holds all the command line options for the kernel (like root=). To append bootargs with what you want, you would enter the following in the U-Boot prompt
setenv bootargs $(bootargs) root=/dev/mmcblk0p1
If you want to permanently save the variable then you need to enter the command saveenv to tell U-Boot to save this change to disk. After this you can issue your normal boot commands.

Where is GDB's gdbinit file when using cygwin?

I would like to follow the answer in this question:
Permanently Change Disassembly Flavor in GDB
but it refers to a GDB file named .gdbinit. What is the equivalent file when using GDB through cygwin?
gdb help output tells you where it's looking at startup:
$ gdb --help | tail
Set GDB's data-directory to DIR.
At startup, GDB reads the following init files and executes their commands:
* user-specific init file: /home/davidw/.gdbinit
* local init file (see also 'set auto-load local-gdbinit'): ./.gdbinit
For more information, type "help" from within GDB, or consult the
GDB manual (available as on-line info or a printed manual).
Report bugs to "<http://www.gnu.org/software/gdb/bugs/>".
You can also get a little more information from within gdb with the command
show autoload.
See also the online manual here.
Not really relevant to this question, but the reason I spent time looking into this was that, with cygwin, my .gdbinit seemd to be getting ignored. It turned out to be the command in my .gdbinit that was being ignored.

How to use single step mode in QEMU?

I am new to qemu and I read that it allows for a singlestep mode emulation. This is helpful because I am trying to dump some addresses of the physical ram every cycle. Unfortunately, the qemu documentation is very bad. I know how to enable the singlestep mode from the qemu monitor but I have no idea where to put the code that I want to execute at every step. Does anyone have any information about this?
You can use gdb to attach to the guest with the
--gdb tcp::
option to qemu and then use
$ gdb <binary>
(gdb) symbol-file <sym file>
(gdb) target remote <host>:<port number>
(gdb) b <function>
(gdb) c
'b' sets a breakpoint. 'n' 's' 'i' can be used to step though the code. Entering "info" in gdb mode will show more info
http://www.xenproject.org/help/questions-and-answers/problem-with-vga-passthrough.html
From above link is the command line option for entering singlestep modes for QEMU. Next is to get the source code for QEMU (http://wiki.qemu.org/Download)
The function monitor.c:do_singlestep(Monitor *mon, const QDict *qdict)
just simply set a flag "singlestep". Note this is not the same as the "singlestep_enabled", which is to emulate hardware singlestep emulation.
(global var is declared in vl.c).
Now look into all the functions in targt-i386/translate.c - where "singlestep" flag are tested are:
if (singlestep) {
gen_jmp_im(pc_ptr - dc->cs_base);
gen_eob(dc);
break;
}
This is the place where the binaries are either executed (or "translated" to be more exact), or otherwise hardware exception raised and handler (for example). If there is any behavior you want to modify perhaps u can try here?
From Ubuntu Documentation
-singlestep
Run the emulation in single step mode.

source a script from gdb

Before I debug or execute a program on my system at work, I have to source a file that contains numerous paths and settings that are specific to each project. Is there a way I can do this from gdb? I tried putting it into a .gdbinit file in the working directory, but that doesn't seem to be working. I tried to see if the environmental variable was set by typing
(gdb) shell echo $MY_VAR
and it was blank. Any ideas?
Basically to set the environment variable in the command prompt, you can use the set environment varname [=value]. More information is present here. Since you have noted down there are huge number of paths to be set, you can add them to a file like myGdbSrc and then load them explicitly using source [-s] [-v] filename. You can find details on loading a file here.
I have tried both of them and it works.
HTH.
PS: I have tried it on GNU GDB 6.6 version on SUSE Linux. However, it must work across all version since it seems to be basic command.
How about writing a wrapper script which sources your settings before loading gdb?
E.g. some trivial example:
#!/bin/sh
source my-script-which-sets-up-the-environment
gdb $*
This can of course also add arguments to the gdb invocation to setup paths, load a gdb script, etc.

Resources