Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing Kernel Arguments #21

Open
rellermeyer opened this issue Mar 9, 2014 · 10 comments
Open

Parsing Kernel Arguments #21

rellermeyer opened this issue Mar 9, 2014 · 10 comments
Assignees
Labels

Comments

@rellermeyer
Copy link
Owner

Once we have more of the kernel up and running we might want to pass arguments to it, e.g., to selectively load user processes. Therefore, we need an argument parser.

@SheldonSandbekkhaug
Copy link
Collaborator

I'm willing to work on this.

@SheldonSandbekkhaug SheldonSandbekkhaug self-assigned this Mar 10, 2014
@SheldonSandbekkhaug
Copy link
Collaborator

Do you mean something like a command line prompt for the OS, or arguments given at "VersatilePB" prompt?

@rellermeyer
Copy link
Owner Author

Sorry, I missed this one. The former would be a shell to me, I am thinking something else, the arguments passed to qemu and/or the bootloader. E.g., in Linux that would be the "root=..." etc.

@SheldonSandbekkhaug
Copy link
Collaborator

I added basic argument parsing functionality (it will be later expanded) with commit d617f8f. I'm still trying to find a way to correctly pass arguments to the kernel via QEMU (perhaps -append ARGS is what I'm looking for). Do arguments from -append ARGS get passed to start()?

@rellermeyer
Copy link
Owner Author

I don't think so. Maybe you find documentation where Linux gets them from. It should happen in Linux' init/main.c file.

@SheldonSandbekkhaug
Copy link
Collaborator

I've looked through the Linux source code and I've been trying to understand how kernel parameters are read. This is my understanding:

From main.c, start_kernel() calls setup_arch() in arch/arm/kernel/setup.c, which calls which calls setup_machine_tags() in arch/arm/kernel/atags_parse.c. setup_machine_tags() copies a variable called "from" to boot_command_line. I think "from" is set by a function that mdesc has a function pointer to.

Here's where I'm stumped: setup_machine_tags() has struct machine desc called "mdesc" that is set to a variable named "p". Unfortunately, I can't find a struct machine desc called "p".

Here's the part in question:

http://lxr.free-electrons.com/source/arch/arm/kernel/atags_parse.c#L196

Am I going in the right direction, or is there a better way?

@SheldonSandbekkhaug
Copy link
Collaborator

I seemed to be blocked by this. Now that the test is over, am I moving in the right direction? I still can't figure out how to obtain the kernel arguments.

@rellermeyer
Copy link
Owner Author

The bootloader should pass you a parameter list in R2: https://www.kernel.org/doc/Documentation/arm/Booting

I pushed some minor changes so that you now get the start address of the parameter list as the first argument in start.c

The current implementation simply prints them to the screen. I guess that should give you what you need.

@rellermeyer
Copy link
Owner Author

Here is some more information about the tagged list format. I guess all we need at the moment is the content of the ATAG_CMDLINE tag, all others can be skipped over.

http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html#ATAG_CORE

@SheldonSandbekkhaug
Copy link
Collaborator

I added a function to read ATAG_CMDLINE in b6ab304. However, I tried adding -append "option=value" to the qemu command, but "option=value" doesn't appear in ATAG_CMDLINE. Is this the right way to pass arguments through qemu?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants