All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Agner <stefan@agner.ch>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 0/3] imx: bootaux elf firmware support
Date: Tue, 04 Apr 2017 12:45:43 -0700	[thread overview]
Message-ID: <98fa8e01dbf42824f1ac8239405e78e5@agner.ch> (raw)
In-Reply-To: <1d98ecaf-bcef-07de-fa28-a6adeb3d766d@denx.de>

On 2017-04-04 11:38, Marek Vasut wrote:
> On 04/04/2017 07:57 PM, Stefan Agner wrote:
>> On 2017-04-04 02:22, Marek Vasut wrote:
>>> On 04/04/2017 02:02 AM, Stefan Agner wrote:
>>> [...]
>>>>>>> Admitedly, I didn't look at the patch, but if you want to boot ad-hoc
>>>>>>> cores, you can very well also boot secondary cores on the current CPU
>>>>>>> complex with the same command. Why not ?
>>>>>>
>>>>>> Sure, it could be done. I just feel it is not the right design.
>>>>>>
>>>>>> Auxiliary cores have usually a different view to memory, this is why I
>>>>>> had to add the get_host_mapping callback in the elf loader code to let
>>>>>> architecture dependent code translate to host addresses. SMP systems
>>>>>> don't need that.
>>>>>>
>>>>>> Also flush caches is not necessary on some cache coherent CPU's
>>>>>> (depending on how your cache coherence between I and D cache looks
>>>>>> like).
>>>>>
>>>>> So SMP is just a reduced special-case of this , yes ?
>>>>
>>>> Yeah, I guess you can get away with dummy callback implementation and a
>>>> performance hit due to cash flushes.
>>>
>>> Or you can abstract things out ?
>>>
>>
>> There is one callback to arch for translation and one for cache flush,
>> what more can I abstract out?
> 
> Well then I don't think I understand your concerns about cache flushing
> in SMP .
> 

It makes things unnecessary slower.

>>>>>> Creating a new command like bootaux comes with very few overhead.
>>>>>
>>>>> The overhead is the new command, we already have many ad-hoc commands.
>>>>>
>>>>
>>>> Agreed, and I really wished that this got discussed when that command
>>>> initially got added. I brought it up back then...
>>>> https://lists.denx.de/pipermail/u-boot/2016-January/240323.html
>>>>
>>>> It seemed to be acceptable to just add this ad hoc command, with some
>>>> "random binary format" support back then...
>>>
>>> Based on that discussion, I only see that noone opposed, but I don't see
>>> any agreement.
>>>
>>
>> Maybe I need to word my emails a bit stronger, but with that email I
>> actually tried to oppose:
>> https://lists.denx.de/pipermail/u-boot/2016-January/240989.html
> 
> Well, I do not like adding ad-hoc commands as it's not managable in the
> long run.
> 

I argue that a remote core loading command is _much_ more manageable
than making the bootm command even more complex by support
SMP/remoteproc and whatnot usecases... I would even argue that a bunch
of those commands are more manageable than a single ifdef/if hell....

That said, I still would push for keeping the image processing code
generic, whenever it makes sense.

>>>> Ok, it is not entirely
>>>> random, since it is the format of a binary how it ends up in
>>>> microcontrollers execute in place flash (stack pointer and reset vector
>>>> are the two first words)....
>>>
>>> I thought this command was starting the core by loading data to RAM ,
>>> not flash ?
>>>
>>
>> Ok, maybe I am a bit unclear here:
>>
>> bootaux currently supports a Cortex-M specific binary format only. The
>> binary format starts with a Cortex-M class vector table. The vector
>> tables first vector is the "reset vector".
>>
>> In a regular microcontroller, that binary gets flashed on a NOR flash
>> which is mapped at 0x0 for the CPU. The CPU has no "boot ROM", the CPU
>> starts by calling the reset vector. So when NXP defined how the bootaux
>> command should look like, they just took that binary format which was
>> laying around and implemented a U-Boot command around it.
>>
>> So this is the history of the binary format. And my point here is, that
>> the binary format supported by bootaux is _very_ Cortex-M class
>> specific.
> 
> Aha, so I now totally don't understand why this command cannot be
> fixed/extended to support other/generic cores or SMP systems etc.
> But looking at the initial proposal, I think maybe the intention of this
> patchset was not to add that support, but to fix the command to
> support loading ELF files ? We already have bootelf for that though ...
> 

Yes, that is pretty much it. I would like to teach that command a more
generic format, which would be at least a step towards something more
generic/standardized.

bootelf is really meant for the primary CPU. That would be an entirely
different direction: Make all common boot commands "aux core" capable.

But I would strongly vote against that. First, those commands have
already complex arguments and argument handling (e.g. bootm), and their
implementation supports use cases which we hardly would ever use on aux
cores (initramfs..).

>>>> However, making this ad hoc command now
>>>> generic really feels weird to me, since we would end up supporting that
>>>> format for A class CPUs etc... bootaux is really suited for auxiliary
>>>> M-class cores on ARM, as it is right now. Maybe we should have named it
>>>> bootm ;-)
>>>
>>> We always try to avoid one-off hacks, so it's not weird. I still don't
>>> quite understand how it is a problem to abstract things out . I am not
>>> asking you to support CA, but to avoid CM specific implementation which
>>> cannot be extended to support CA or even MIPS/Nios2/etc .
>>>
>>
>> Again, why would you support a Cortex-M class specific file format for
>> MIPS/Nios2 etc...?
>>
>> bootaux is M4 specific. We can through it away, and start over, but then
>> we should call the command differently.
> 
> Unless you look very carefully, it is not clear that it is cortex M4
> specific at all based on this discussion. I was under the impression
> that the goal here was to support all sorts of secondary cores ...
> 

Yeah it's also only that binary format handling which is M4 specific.
And frankly, that is just 2 lines of code, basically dereferencing the
first two words:

+    if (valid_elf_image(addr)) {
+        stack = 0x0;
+        pc = load_elf_image_phdr(addr);
+        if (!pc)
+            return CMD_RET_FAILURE;
+
+    } else {
+        /*
+         * Assume binary file with vector table at the beginning.
+         * Cortex-M4 vector tables start with the stack pointer (SP)
+         * and reset vector (initial PC).
+         */
+        stack = *(u32 *)addr;
+        pc = *(u32 *)(addr + 4);
+    }

>>>>>> This are the reasons why I feel creating a new command for a SMP boot
>>>>>> case makes more sense. We can still reuse functions which are very
>>>>>> similar by moving them into some common location, where it makes sense.
>>>>>>
>>>>>>>
>>>>>>> Also, I think this might come useful when booting stuff like "Altera
>>>>>>> Sparrow" ...
>>>>>>
>>>>>> I am not familiar with that architecture, what kind of core does it
>>>>>> provide which needs to be booted by U-Boot?
>>>>>
>>>>> The secondary ARM core in the SoCFPGA C-A9 complex or Nios2 core in the
>>>>> FPGA.
>>>>
>>>> In my thinking, the Nios2 core seems like such a remote processor well
>>>> suited for the bootaux command. For the secondary A9, I would create a
>>>> new command.
>>>
>>> Uh, why, that does not make any sense to me. Both the random core in
>>> FPGA and the secondary CA9 core have almost the same bringup sequence.
>>> What is so different about this stuff ?
>>>
>>
>> A cache coherent core and a non-cache coherent core remote core
>> somewhere in the SoC is very much different IMHO.
>>
>> Lets compare how you bring up a A class CPU, or cache coherent SMP style
>> CPU in general:
>>
>> 1. Load code into RAM
>> 2. Some cache flushing might be necessary due to I/D-cache incoherency
>> 3. Write entry point into some architecture specific register
>> 4. kick off the CPU by writing another architecture specific register
>>
>> M class/remote CPU
>>
>> 1. Load code in RAM, depending on image format translate core specific
>> memory map to host memory map
>> 2. Flush D-cache
>> 3. (Potentially set up IOMMU, not in the NXP case though)
>> 4. Write entry point into some architecture specific register
>> 5. kick off the CPU by writing another architecture specific register
>>
>> From what I can see, everything is different other than "Load code in
>> RAM" which is image specific. If the image format is complex, we
>> certainly should factor that out to avoid code duplication.
> 
> Image format is usually binary blob or elf file, we support both.
> The rest is "load file to RAM, do magic setup (can be CPU specific),
> unreset CPU".
> 

Loading files to RAM is already generic since it is handled by separate
commands.

It is really the image handling which has the potential of reusability.

>>>> If we want to support the two with the same command, we already have a
>>>> first problem: How do we address them? Of course, we could add just a
>>>> index or something, but this would already break backward compatibility
>>>> of the bootaux command.
>>>
>>> So we already accepted a command which has shit commandline semantics
>>> and we're stuck with it , hrm. You can always specify a default core
>>
>> Add shitty binary file format to the list.
> 
> Why do we care about this ? The CM just needs a vectoring table, so set
> it up (in the elf file or whatever) and point the core at the reset vector.
> 

Not sure what you want to say here, but I guess we need to keep support
for this file format for backward compatibility?

>>> index for those two iMX boards and it's done. Or just fix the semantics
>>> in their default environment, which is not awesome, but I doubt this is
>>> wildly used yet.
>>
>> I guess my general point is, bootaux is already broken in two ways:
>> Command line interface does not allow for extensibility, the only format
>> supported right now is a binary format which is not generic.
>>
>> My patchset was an attempt to improve the situation to give it at least
>> a decent elf format support.
> 
> Maybe this information was lost ... Lukasz ?!
> 
>> Note that there is also bootelf, where the elf headers have been
>> introduced. Reusing that command seems impractical since it is meant to
>> boot on the primary CPU. My first attempt was reusing at least the load
>> function, but it seemed impractical due to memory map translation and
>> since the load function is rather short. If it helps for the acceptance
>> of this patchset, I still could try to make that happen.
> 
> Extending bootelf might indeed make more sense IMO. But that needs
> discussion.
> 

There are two variants of reuse here:
1. Reuse the elf parsing and loading function (function
load_elf_image_phdr in this case).
2. Reuse the bootelf command. This would need extending the command with
some parameter to tell it to not boot the primary CPU but boot some
other auxiliary processor.


Let's get a bit more concrete here, take bootelf as a case study:

1 would introduce the architecture specific translation callback
load_elf_image_phdr (see my load_elf_image_phdr implementation in this
patchset). For regular/primary boot we can implement a dummy 1:1
translation.



2 would need 1, and changes to do_bootelf. Since the command has already
optional arguments adding core selection as an optional argument is not
possible. But we could add a parameter, e.g. -c (core):

bootelf -c aux

or

bootelf -c 1

The exact enumeration would have to be discussed. I guess this would
also be architecture specific.

Adding the new parameter handling plus callbacks into architecture
dependent code probably makes do_bootelf double in length. Also, half of
the existing code cannot be reused: The call do_bootelf_exec is primary
CPU specific, passing the arguments (this is likely not supported by
remote cores) and the return code handling (since a remote core would
not return), autostart handling, not sure?

2 would also need to either disable the section header functionality for
the remote core, or we add another if in do_bootelf and avoid parsing
section header even if requested...


Again, I strongly disfavor solution 2. That makes boot commands with
image types we want to support even more complex. bootelf already starts
to look ugly when I start implementing that, and bootelf is really one
of the cleanest and simplest boot commands I have seen... I probably
would give it a shot if this is the only way to bring elf format support
for aux cores upstream... Good luck for the guy implementing FIT image
support (bootm) for auxiliary cores :-D

1 we could do, and I would be willing to do it. I personally feel that
the small code duplication is cleaner than reusing that function from
cmd/elf.c and implementing the dummy 1:1 translation, but both works for
me....

IMHO, commands are really lightweight and nice in U-Boot, I think we
should make use of them, even when it means some namespace pollution.

--
Stefan

  reply	other threads:[~2017-04-04 19:45 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-29 19:58 [U-Boot] [PATCH 0/3] imx: bootaux elf firmware support Stefan Agner
2017-03-29 19:58 ` [U-Boot] [PATCH 1/3] imx: imx-common: move aux core image parsing to common code Stefan Agner
2017-03-29 19:58 ` [U-Boot] [PATCH 2/3] imx: imx-common: add elf firmware support Stefan Agner
2017-03-29 19:58 ` [U-Boot] [PATCH 3/3] ARM: vf610: add auxiliary core boot support Stefan Agner
2017-04-03 11:20 ` [U-Boot] [PATCH 0/3] imx: bootaux elf firmware support Lukasz Majewski
2017-04-03 21:36   ` Stefan Agner
2017-04-03 22:07     ` Marek Vasut
2017-04-03 22:42       ` Stefan Agner
2017-04-03 23:34         ` Marek Vasut
2017-04-04  0:02           ` Stefan Agner
2017-04-04  8:46             ` Lukasz Majewski
2017-04-04  9:22             ` Marek Vasut
2017-04-04 17:57               ` Stefan Agner
2017-04-04 18:38                 ` Marek Vasut
2017-04-04 19:45                   ` Stefan Agner [this message]
2017-04-04 20:17                     ` Marek Vasut
2017-04-04 21:39                       ` Stefan Agner
2017-04-04  8:25       ` Lukasz Majewski
2017-04-04  8:23     ` Lukasz Majewski
2017-04-04 18:59       ` Stefan Agner
2017-04-05 15:15         ` Lukasz Majewski
2017-04-05 18:20           ` Stefan Agner
2017-04-05 19:10             ` Tom Rini
2017-04-05 19:54               ` Lukasz Majewski
2017-04-05 19:56               ` Stefan Agner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98fa8e01dbf42824f1ac8239405e78e5@agner.ch \
    --to=stefan@agner.ch \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.