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

scripts: New tool to dump init hooks #125

Merged
merged 1 commit into from
Oct 7, 2016
Merged

scripts: New tool to dump init hooks #125

merged 1 commit into from
Oct 7, 2016

Conversation

louisom
Copy link
Contributor

@louisom louisom commented Oct 5, 2016

At now this script will print by hook level,
but is not the real seq when kernel perform run_init_hook.

Copy link
Member

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow the consistent copyright notice.

# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Authors:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mention "Authors" since we maintain the list in dedicated top-level files.

Copy link
Contributor Author

@louisom louisom Oct 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take the sample from Linux kernel scripts format. and fixed.

Copy link
Member

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the malformed situation.

self.files, hooks = s.split(':')

# Regex for splitting function and level
regex = r"\((.*?),(.*?)\)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any error handling?

Copy link
Contributor Author

@louisom louisom Oct 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a big problem since initializer element should be constant, according to c99 spec,
this mean we have these choice to init element.

6.4.4 Constants

Syntax

constant:

integer-constant       (e.g. 4, 42L)
floating-constant      (e.g. 0.345, .7)
enumeration-constant   (stuff in enums)
character-constant     (e.g. 'c', '\0')
6.6 Constant expressions

(7) More latitude is permitted for constant expressions in initializers. Such a constant expression shall be, or evaluate to, one of the following:

— an arithmetic constant expression,

— a null pointer constant,

— an address constant, or

— an address constant for an object type plus or minus an integer constant expression.

(8) An arithmetic constant expression shall have arithmetic type and shall only have operands that are integer constants, floating constants, enumeration constants, character constants, and sizeof expressions. Cast operators in an arithmetic constant expression shall only convert arithmetic types to arithmetic types, except as part of an operand to a sizeof operator whose result is an integer constant.

That mean we can have these valid input, but can't valuate in python

enum foobar {
    foo = 5,
    bar = 10,
};

INIT_HOOK(function, (int) &thread_init_subsys);
INIT_HOOK(function, bar);
INIT_HOOK(thread_init_subsys, SSI_NORMAL_THREAD);
INIT_HOOK(thread_init_subsys, 50L);

Copy link
Contributor Author

@louisom louisom Oct 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a workaround method for now. but still need to think some method to count on it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can even generate headers to be included for init hooks as we did for mconf. I did the similar hack for raytracing program as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I found that we can read it from .init_hook section in obj file

Contents of section .init_hook:
 0000 afbeadde 00000000 00000000           ............

will that be a better method to get level when eval failed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retrieving ELF section from given files is a practical way. @arcbbb did that for Kprobe (yes, F9 has the feature.) by means of similar technique.


def __init__(self, infile=None):
# Hack for board build prefix
self.board = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing defconfig such as board/discoveryf4/defconfig is straightforward rather than hardcode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is about self.board or other thing ?

The problem here is we need to specify user's config board for build/prefix, so only read from .config file and program can determine which board is using now.

And pair of board -> build prefix was existed in top dir Makefile if else block

ifeq "$(CONFIG_BOARD_STM32F429DISCOVERY)" "y"
BOARD ?= discoveryf429
else ifeq "$(CONFIG_BOARD_STM32P103)" "y"
BOARD ?= stm32p103
else
BOARD ?= discoveryf4
endif

rather than making a turly parser, I make this attr set when parsing .config, since we will only get one CONFIG_BOARD=y in config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@louisom louisom closed this Oct 6, 2016
@louisom louisom reopened this Oct 6, 2016
@@ -0,0 +1,101 @@
#!/usr/bin/python
#
# Scripts for print all init hooks in f9-kernel.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eliminate Line 3. We already have descriptions.

@jserv
Copy link
Member

jserv commented Oct 6, 2016

The subject of GIT commit messages can be "scripts: New tool to dump init hooks".

@louisom
Copy link
Contributor Author

louisom commented Oct 6, 2016

Rebase all commit to one?

@louisom louisom changed the title scripts: Add scripts for list init hooks scripts: New tool to dump init hooks Oct 6, 2016
@jserv
Copy link
Member

jserv commented Oct 6, 2016

@grapherd , Yes, please do.

Introducing new tool to dump init hook in f9-kernel.

At now this script will dump init hook by hook level,
but if hook is at same level, is may not dump by the
real sequence when kernel perform run_init_hook in runtime.

This tool's mechanism for getting hook level is to parse
source code and use regex to get `INIT_HOOK(hander, hook_level)`,
hook_level will be eval in python and for fallback, it will parse
object file in build directory to get hook level, so you'll need
to bulid a full f9-kernel, and get setup GNU toolchain at first.

Also, this tool will get some information from config file
like `.config`, `Makefile`, `mk/toolchain.mk` for some
general setting variable: BOARD, CROSS_COMPILE...etc

Class MakefileConfig perform will config interface.

Parser in MakefileConfig can only parse makefile `?=` variable when
the attribute is not set. (it only serive for BOARD and CROSS_COMPILE
for now)

for example:
	c = MakefileConfig() 		# Create new object,
					# also load .config into it.

	c.CONFIG_DEBUG       		# Return True
	c.CONFIG_LOADER	     		# Raise KeyError
	c.parse_makefile('Makefile')	# Parsing 'Makefile'
	c.BOARD				# Return config board
	c.out				# build/$(BOARD)

As I say, it only impl very low parsing process for makefile,
so you can see the last example return `build/$(BOARD)`, thought
$(BOARD) has been set in object c, it still won't convert to
`build/stm32p103` style for now.
@jserv jserv merged commit 194e5c1 into f9micro:master Oct 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants