This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM3358 Rom code - payload interface question

Other Parts Discussed in Thread: AM3358

Hi, all. My question is that:

I need to make use an am3358 rom code's raw mode of memory booting from both SD cards and eMMC.
My question is whether the CH (Configuration Header) needed in this case?
TI's TRM on Sitara am335x states CH must be located at the first sector,
and says it might be void (only containing a disabled CHSETTINGS item),
but it is very unclear with respect of its size and offsets***. and also it's not clear whether it's needed at all.
Quote [TRM SPRUH73K]:
"The raw mode is detected by reading sectors #0, #256, #512, #768.
The content of these sectors is then verified for presence of a TOC structure as described in Section 26.1.9."

But section 26.1.9 even doesn't mention CH, just a GP header.
And the TRM on Sitara 572x states CH is optional for GP devices.

If I place my binary into LBA #0 (first sector) with the only GP header attached and no CH,
would the Rom code recognize the raw mode and boot my image?

I can't use MBR/FAT mode, because there is GPT and Protective MBR there.

I wanted to learn this, and before bothering you, I checked eMMC content on the Beagle Bone Black board (BBB),
since TI's TRM states for embedded memories, ROM code doesn't use MBR/FAT mode.
So on eMMC, there should be a valid example of CH with TOC in the first sector. But on BBB, somehow,
and it is clearly seen, the FAT/MBR mode is used and there is no any TOC at all (first bytes
of the first sector are filled with zeros up to the Partition records). TRM states if the first
4 bytes are 0x00 or 0xFF this device is considererd as not containig the image to load:
Quote:
"The detection of whether an image is present or not on a selected device depends on the first few bytes.
On a GP Device type a booting image is considered to be present when the first four bytes of the sector is
not equal to 0000 0000h or FFFF FFFFh."

Tell me please, is CH required, in raw mode of memory booting for GP devices and
what its minimal content if it is? Because I cannot let it occupy the entire 512 bytes, only part
of the code block (first 440 bytes) of the Protective MBR may be used.

*** Below is my trying to expalin what I meant saying about unclear offsets and sizes in the TOC and CHSETTINGS description in TRM.

The TRM gives an example of the TOC structure (table 26-20), and CHSETTINGS section (table 26-21).

In the TOC, the Start field indicates value a0h as an offset from the TOC to the (CHSETTINGS) section. Why a0h? it's 160 bytes, whereas TOC from the table is maximum 64 bytes long. Because the last its field is placed at the offset 3ch and has 4 byte. Moreover, the TOC states there should be 8 closing items filled with ffffffffh. Why? Isn't enough one after CHSETTINGS TOC item? Then, TOC size might be as little as 36 bytes!

Next, in the TOC, the Size field (for CHSETTINGS) has a value 50h (80 bytes). But when looking at the next table where CHSETTINGS is described, it requires fields up to the offset e0h (almost all filled with zeroes). it would result in minimum 225 bytes of the CHSETTINGS section! this is definitely not 50h claimed in the TOC. This is a mess. I understand that this all is for smudging CH into the entire sector, but with a Protective MBR it's impossible. The most irritating thing, that this is absolutely not needed, and still it wants to occupy the entire sector!  Please, tell me, this CH thing is not needed for raw mode. Because, honestly, rom code checks first 4 bytes of read sector and if they are not 0 or ffffffff, it thinks it's a GP header of a valid image. or at least tell that I can prepare a minimalistic CH not bloated with meaningless tons of closing items and reserved zeroed fields for disabled CHSETTINGS section.

  • Hi Valerij,

    I've asked the design team for help on this questions. Their feedback will be posted here.

    Best Regards,
    Yordan
  • The raw MMC header (TOC and CHSETTINGS) is required for raw SD/MMC boot mode, this in addition to the GP header. Note that ROM looks at four locations for it, not just sector 0. The beaglebone black uses the second location, sector 256.

    See the readme of this project for examples on the various ways of booting an image on the am335x. It also has a premade raw MMC header in its extras directory.

  • Thank you very much,  Yordan and Matthijs.

    @ Matthijs. The project you gave link on, was very helpful. I only want to note few things:

    1) raw-mmc-header.img has Start and Size values which differ from the table in TRM. The question is - how to know the valid values, that rom code wouldn't reject?

    2) there is no mention in TRM that if a valid CH (a raw boot header) is detected at the sector X, then the image is expected at the next sector. This is the most missing part in TRM.

    3) I've checked all the four locations on BBB's eMMC and sectors #256, #512 and #768 are filled with zeros. Instead there is MLO file in the root of a FAT16 partition. It looks like ROM code actually does MBR/FAT boot even on embedded memories contrary to what TRM says.

    With GPT partitioning, I cannot place the boot image at the sector next to the MBR sector, because there is a fixed GPT header there. So, the only option to combine GPT and raw mode of the rom code is to place the image at Lba 256?

    So, did I understand right, that even though the raw mode header is lesser than a whole sector in size, Rom code still expects the image to be on the next sector and NOT just after CH inside the same sector? Because if the latter would be possible, I might place GP and the image just after those 288 bytes of the raw-mode-header. The MBR's BootCode block gives such a possibilty.

  • valerij zaporogeci said:
    I've checked all the four locations on BBB's eMMC and sectors #256, #512 and #768 are filled with zeros. Instead there is MLO file in the root of a FAT16 partition.

    The old images used a FAT boot partition yes, the new ones use raw MMC boot. Both methods are supported, iirc this is correctly described in the TRM.

    valerij zaporogeci said:
    raw-mmc-header.img has Start and Size values which differ from the table in TRM. The question is - how to know the valid values, that rom code wouldn't reject?

    I use the one produced by u-boot (hence used by the BBB images), didn't even check them against the TRM really. Since there's no variable content in it, once you have one that works that's all you need.

    valerij zaporogeci said:
    With GPT partitioning, I cannot place the boot image at the sector next to the MBR sector, because there is a fixed GPT header there. So, the only option to combine GPT and raw mode of the rom code is to place the image at Lba 256?

    Putting the raw MMC header at sector 256 (hence image with GP header at sector 257) is actually most typical I think. It's generally overlooked that the raw mmc header is compatible with an MBR partition table (due to the raw mmc header being in the bootcode area of the MBR).

    If you use a hybrid MBR then a FAT partition would also be an option.

    valerij zaporogeci said:
    So, did I understand right, that even though the raw mode header is lesser than a whole sector in size, Rom code still expects the image to be on the next sector and NOT just after CH inside the same sector?

    Correct. TRM indeed seems to be unclear about that. Weird, I seem to remember it used to be clearer...

    valerij zaporogeci said:
    Because if the latter would be possible, I might place GP and the image just after those 288 bytes of the raw-mode-header. The MBR's BootCode block gives such a possibilty.

    Ehm, then your image would have to fit in the remainder of the tiny BootCode space, what kind of image are you imagining would fit there? (regardless, it's not important since it does in fact need to start at the next sector).

  • Thank you. Now it's much more clear.

    "The old images used a FAT boot partition yes, the new ones use raw MMC boot. Both methods are supported, iirc this is correctly described in the TRM."

    I won't argue. I just read this:

    "26.1.7.5.3 Booting Procedure
    The high level flowchart of the eMMC / eSD and MMC/SD booting procedure is depicted in Figure 26-17.
    The booting file is searched only in case of booting from a card. eMMC/eSD embedded memories only
    support raw mode."

    So I was thinking accordingly. Here, it's quite clear.

    "Correct. TRM indeed seems to be unclear about that. Weird, I seem to remember it used to be clearer..."

    yes, it states this:

    "The raw mode is detected by reading sectors #0, #256, #512, #768. The content of these sectors is then
    verified for presence of a TOC structure as described in Section 26.1.9. In the case of a GP Device, a
    Configuration Header (CH) must be located in the first sector followed by a GP header. The CH might be
    void (only containing a CHSETTINGS item for which the Valid field is zero)."

    which is nowhere near saying abour the next sector. :)

    "Ehm, then your image would have to fit in the remainder of the tiny BootCode space, what kind of image are you imagining would fit there? (regardless, it's not important since it does in fact need to start at the next sector)."

    I might put there as few as a GP header (8 bytes) and a jump instruction (4 bytes), the latter would jump over GPT header (it would be also loaded as part of an image) at the sector #2 (third) or farther, where my code would lie. That way it would be possible to combine GPT with the rom code requirements the nicest way (because forcing boot from lba 256 looks way worse). But anyway, it does not matter now. It's amazing how much the Rom code requirements are incompatible with the GPT ones. But this is another story. I got the answers on my questions, and very quickly and they were useful, for what I thank you. :)

  • valerij zaporogeci said:
    The booting file is searched only in case of booting from a card. eMMC/eSD embedded memories only
    support raw mode."

    You're reading revision L of the TRM or older. I suggest downloading the latest revision since that phrase is gone since revision M.

    valerij zaporogeci said:
    jump over GPT header (it would be also loaded as part of an image)

    Ew... eh yeah I guess that could have worked if it didn't expect the image to be sector aligned, but it does.

    valerij zaporogeci said:
    But anyway, it does not matter now. It's amazing how much the Rom code requirements are incompatible with the GPT ones.

    I don't really see any incompatibility. Nor much reason to use GPT for that matter though.

  • Matthijs van Duin said:

    You're reading revision L of the TRM or older. I suggest downloading the latest revision since that phrase is gone since revision M.

    This is what I read. I guess It's K, right?

    Literature Number: SPRUH73K
    October 2011–Revised June 2014

    Downloading a new TRM is easy, but there is also an actual rom code inside a SoC.) It might not care much about the release of the new TRM. :)

    valerij zaporogeci
    jump over GPT header (it would be also loaded as part of an image)

    Ew... eh yeah I guess that could have worked if it didn't expect the image to be sector aligned, but it does.

    valerij zaporogeci
    But anyway, it does not matter now. It's amazing how much the Rom code requirements are incompatible with the GPT ones.

    I don't really see any incompatibility. Nor much reason to use GPT for that matter though.

    By incompatibility I meant that what Rom code expects, can not fit well with what GPT wants - Gpt wants sector #1 for the fixed header, rom code wants here the image, due to its (humble) sector alignment requirement, actually if there would be a mechanism to say it where the image lays, this alignment wouldn't conflict with Gpt, i.e. some "MLO" section in the TOC with the exact (sector aligned) position of the image (the same as with CHSETTINGS). Then I might put the image at any sector behind a GPT header. (and before the GPT partition array which is not fixed). Of course I may put the image at the sector #256, but this not only wastes 128KB of space, it also puts a very awkward requirement to have a specially treated, very sensible area inside of a fw storage. It's easier when such a "special" thing lies at the very beginning, not somewhere in between other data. so, roughly mimicking the beginning i might skip this 128KB (except PMBR, GPT header and Gpt partiotion array) and make "the first usable lba" (it's a gpt term) at lba 256 (or after if my code and firmware volume wouldn't be accounted as a gpt partition). better than nothing. :)

    After all, linux puts the first partition on BBB at lba 2048 at all. xD my tryings to be efficient look funny here.

    Gpt scheme is an integral part of the work, becuase it's UEFI related. :)

    And yet, maybe you know, does rom code check for booting the eMMC's boot areas (the eMMC specification calls these "partitions" but obvoulsy it's very confusing)? Because TRM says it doesn't, but as we see this is not necessarily corresponded with what it actually does. (Rom code on Sitara am57xx does this and it's documented if i remember properly).

  • valerij zaporogeci said:
    Downloading a new TRM is easy, but there is also an actual rom code inside a SoC.) It might not care much about the release of the new TRM. :)

    Well you should since it was updated to reflect actual behaviour of the ROM code. The older revisions were incorrect.

    valerij zaporogeci said:
    By incompatibility I meant that what Rom code expects, can not fit well with what GPT wants - Gpt wants sector #1 for the fixed header, rom code wants here the image

    No, it wants it at one of four locations, three of which are compatible with GPT. You can alternatively use a hybrid MBR/GPT partition table and a FAT boot partition.

    valerij zaporogeci said:
    After all, linux puts the first partition on BBB at lba 2048 at all. xD my tryings to be efficient look funny here.

    For efficiency it may actually be advisable to align the partitions on an allocation group boundary, which for the eMMC used in the BBB would be 4 MB (lba 8192). This is just a guess however, I've never tested it.

    valerij zaporogeci said:
    And yet, maybe you know, does rom code check for booting the eMMC's boot areas

    No. This was added only in later SoCs, e.g. the am57xx.


  • No, it wants it at one of four locations, three of which are compatible with GPT.


    Yes, I understood, will be trying to use lba 256.
    And yet, does Rom code load the image without the GP header? So if I direct it to load at the address 0x402f1000, wouldn't be there the GP header at 0x402f0ff8?



    You can alternatively use a hybrid MBR/GPT partition table and a FAT boot partition.

    With Gpt, if the fw really makes use of this scheme, there is Protective MBR, and it must have 1 partition describing the entire disk (non-active, with OSType 0xEE - Gpt Protective ) beginning with sector #1, so it hardly will be usable by Rom code. If I resort to Legacy MBR, there will not be Gpt at the device. :)



    For efficiency it may actually be advisable to align the partitions on an allocation group boundary, which for the eMMC used in the BBB would be 4 MB (lba 8192). This is just a guess however, I've never tested it.

    it just looks too much as for such media like eMMC and SD. Because even for huge HDD (considering possible RAID scenarios or physical/logical sector mismatch), Gpt recommends align partitions at lba 2048.



    No. This was added only in later SoCs, e.g. the am57xx.

    Thank you.

  • valerij zaporogeci said:
    And yet, does Rom code load the image without the GP header? So if I direct it to load at the address 0x402f1000, wouldn't be there the GP header at 0x402f0ff8?

    It first reads the GP header into some temporary space and then reads the image (without GP header) to the location indicated in the GP header.

    valerij zaporogeci said:
    With Gpt, if the fw really makes use of this scheme, there is Protective MBR, and it must have 1 partition describing the entire disk (non-active, with OSType 0xEE - Gpt Protective ) beginning with sector #1, so it hardly will be usable by Rom code. If I resort to Legacy MBR, there will not be Gpt at the device. :)

    Please look up what a "hybrid MBR" is.

    valerij zaporogeci said:
    it just looks too much as for such media like eMMC and SD. Because even for huge HDD (considering possible RAID scenarios or physical/logical sector mismatch), Gpt recommends align partitions at lba 2048.

    HDD don't have to deal with the large erase blocks of NAND flash.

  • Thank you.

    Please look up what a "hybrid MBR" is.

    I did, it's a variant, but it's not compatible with the Gpt/Uefi specification and it's problematic overall. Use of 256th sector looks much better.