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

Script to generate dts.fixup file for Zephyr RTOS #13

Merged
merged 2 commits into from
Aug 6, 2018

Conversation

nategraff-sifive
Copy link
Contributor

While Zephyr RTOS defines their DTS-based code generation interface for
drivers, they currently require a dts.fixup file to redefine the
generated macros to the symbols consumed by the drivers themselves. This
script generates that dts.fixup file based on the board's DTS.

The current roadmap for Zephyr puts the new DTS code generation as a
milestone for Zephyr 1.14, so until that support is released, the
Freedom SDK will need to generate these fixup files for creating a port
of Zephyr to a new board.

While Zephyr RTOS defines their DTS-based code generation interface for
drivers, they currently require a dts.fixup file to redefine the
generated macros to the symbols consumed by the drivers themselves. This
script generates that dts.fixup file based on the board's DTS.

The current roadmap for Zephyr puts the new DTS code generation as a
milestone for Zephyr 1.14, so until that support is released, the
Freedom SDK will need to generate these fixup files for creating a port
of Zephyr to a new board.

Signed-off-by: Nathaniel Graff <nathaniel.graff@sifive.com>
static void write_config_file(const fdt &dtb, fstream &os)
{
os << "/* Copyright (c) 2018 SiFive Inc." << endl;
os << " * SPDX-License-Identifier: Apache-2.0 */" << endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

The Linux guys told be that SPDX headers must be structured as //-style comments, but I don't know if that applies to Zephyr as well. I also like adding a "autogenerated by X" header to anything that comes out of a tool and is then checked in, just so people know it's not a human source 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.

Zephyr has the SPDX headers within the /.../ style comments all over the source tree, so this should be fine for them.

I'll add the autogenerated header.

Copy link
Contributor

@palmer-dabbelt palmer-dabbelt left a comment

Choose a reason for hiding this comment

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

Looks good!

auto emit_fixup = [&](string out_prefix, string in_prefix, int dev_num, target_addr base, string suffix) {
os << "#define ";
os << out_prefix << "_" << dev_num << "_" << suffix << "\t";
os << in_prefix << "_" << std::hex << base << std::dec << "_" << suffix << endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an aside, but is there any way to emit an integer as hex to a stream and then reset it to it's original state? I always use this idiom, but it assumes the stream was in std::dec mode. I feel like @brucehoult might know...

Choose a reason for hiding this comment

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

No standard way using manipulators inline in a series of << no.

There are a bunch of suggestions here, but still none that are very pretty: https://stackoverflow.com/questions/2273330/restore-the-state-of-stdcout-after-manipulating-it

@michaeljclark
Copy link

michaeljclark commented Aug 4, 2018 via email

@nategraff-sifive
Copy link
Contributor Author

I do like the look of {fmt}, on first glance it looks really similar to Python's formatting syntax.

Signed-off-by: Nathaniel Graff <nathaniel.graff@sifive.com>
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.

None yet

4 participants