Hi Stefan,
On 04/10/2017 10:28,
Stefan.Herb...@weidmueller.com wrote:
>> As I said, you should *accurately* check the use case, because it is
>> different for each SOC. Take into account that the SPL code (seconary
>> program loader ? We are talking of U-Boot, right ?) just check the
>> header of the u-boot image. You have to ensure that the header is
>> written at the end and not at the beginning of U-Boot image.
>
> Normally the SPL and even most boot roms only check the header, but if I enable secure boot they should check the full image.
That's true - ok, then I guess you have a i.MX6. Without signing SPL,
the Bootrom does not check the header, but just the magic number in the
Header. But with secure boot, the SPL is checked by HAB, right.
> However the saved solution is to build a valid header at the end.
Right.
>
>>>> SWUpdate alone cannot do anything.
>>>
>>> SWUpdate for example could memorize the last successful updated
>>> redundant image in the boot loader environment
>>
>>
>> ...well, you have said that this is checked by U-Boot. As said,
>> SWUpdate cannot guarantee all. The whole concept must be proofed, and
>> includes which U-Boot scripts are running and which variables are set.
>>
>>> and update this image after the other redundant image was successful
>> updated. Therefore you need to reorder the image updates.
>>
>> Environment is *always* set as last part of the update.
>>
>>>
>>>>> The device always tries to load the primary image and falls back to
>>>> the secondary image on failure. A simple two image update could
>> break
>>>> the device when a power loss happens during an update of the first
>>>> image and the second image isn't completed updated because of an
>>>> early power loss.
>>>>
>>>> No you, are wrong. There is no update of "first" or "second", there
>>>> is a "running" and "stand-by" image.
>>>
>>> This is only true if you could influence the boot process and this
>> isn't always possible.
>>
>> Can you tell me the use case ? Why is it not possible ?
>
> I need a reliable update process of the SPL and boot loader.
You do not explain why you cannot influence the boot process.
>
>>>> SWUpdate works as a transaction and inform the bootloader that an
>>>> update is running by setting the variable "recovery". If "recovery"
>>>> is set, the bootloader is not allowed to start the "standby".
>>>
>>> This only works for one image instance of a dual copy but fails if
>> you have more than one image with a dual copy. I suppose you reference
>> the software collections but they are designed for a single dual copy
>> instance.
>>
>> Wrong. collections are designed to make the setup as more generic as
>> possible. I can have three copies, four copies, a setup just for the
>> factory,...
>
> I mean a system with a dual boot loader and a dual SWUpdate image. I have two independent "running" images. At the moment I have to describe any combination as a separate collection.
I do not understand. SPL + U-Boot is like to have kernel outside rootfs.
If you have two independent running images, you have two copies of the
whole software including SPL+U-Boot. You have just to invalidate the old
SPL copy when update is finished, but you lose fallback.
>
>>> The boot loader and secondary program loader are really redundant and
>> I need to update the "primary" and "fallback" image. Normally the
>> system use the "primary" image and only use the "fallback" image if the
>> update of the "primary" image got interrupted. Therefore I need to
>> control the images order at runtime and update the boot loader
>> environment between the separate image updates or better verify the
>> images and always starts with a corrupted image.
>>
>> The SPL is not under your full control - which SPL is taken, it depends
>> (generally) on hardware configuration (boot pins, fuses) or how it is
>> set. Anyway, redundant bootloader can be reached together with
>> SWUpdate, design (including U-Boot scripts, sw-description, U-Boot
>> environment) must take care of it.
>
> How would you handle a reliable update of a redundant boot loader?
>
> Based on your comments and a review of the boot process I see two possible designs:
>
> In both designs the SPL and boot loader form a unity and will be updated together.
They *must* be together. Even if someone splits them, they belong
together. U-Boot does not ensure that a new u-boot.img can work with an
older SPL.
> This simplify the update process and minimize the test cases.
ok
>
> Instead of a redundant SPL and boot loader I use the boot rom functionality to implement a dual image design.
Maybe I am wrong, new speculation, you have Zync / Ultrascale...
I guess I cannot be more precise without knowing the SOC. In fact, what
you want to reach is not something related to SWUpdate, but it is
strictly connected to the features that the SOC has. Different SOC,
maybe different solution.
> In place of a boot loader environment variable the "running" SPL image is marked by a valid image header.
I am losing you. A boot loader variable is a U-Boot variable. This is
evaluated in SPL (if environment is enabled in SPL) or more probably in
U-Boot. But not by the bootrom, that decides on some other conditions
(bootpins, fuses, etc.)
So I do not understand the reason of the U-Boot variable. Yes, you can
switch in SWUpdate if you write a wrong header into the old (and now
updated) SPL.
> The switch between this images is done inside the boot loader and controlled by a boot loader environment variable.
That means that after an update you are running the old SPL+U-Boot, that
should make the copy and the switch - bad.
If you have updated, you should run the updated software, and not the
old one, right ?
> The simplest solution is to erase some well known four bytes from the SPL header in the update image and overwrite this bytes inside the nor flash from the boot loader if the "running" SPL image from the boot loader environment variable and the actual "running" SPL image are different. Additionally the "stand-by" SPL image will be erased or the well known bytes will be overwritten by zero and the boot loader will reset the device.
Something in this way depending on your SOC, right.
>
> Alternative the redundant SPL and boot loader are only used during their update process. SWUpdate always updates the secondary SPL as well as boot loader and sets a boot loader environment variable. If this variable is set the boot loader erases the SPL and copies the secondary boot loader over the primary boot loader.
You are still running the old copy....
> Then the boot loader reads the SPL into memory, erases the well known bytes, overwrites the primary SPL, writes the well known bytes, clears the environment variable and reset the device.
>
> In both cases any power loss will restart the update process inside the boot loader and the redundancy is only used for a reliable update process.
>
> The advantage of the second design is the uniform boot process after each update. The disadvantage is that SWUpdate sets the boot loader environment on every update even if an image is skipped because of the "install-if-different" property.
Best regards,