-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fiptool: Pad zeros for file alignment #1166
Conversation
ARM trusted firmware can specify alignment, the alignment has been applied on every image start address when combine fip.bin; but it misses to apply alignment to the file tail, so fip.bin file size cannot be specified alignment. This commit checks the tail of fip.bin file and pad zeros on the tail for alignment. Signed-off-by: Leo Yan <[email protected]>
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
Hi @hzhuang1, @danh-arm, @raw-bin, This patch is to fix the issue brought up by Robin: ARM-software/tf-issues#528 |
@Leo-Yan |
@davidcunado-arm, yes, have added into commit log. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change actually needed?
I would like to point out that the entry_offset of the null uuid entry is no longer equal to the size of the FIP file after this patch. Hence, if we go with this patch, I would prefer to maintain this constraint as current implementations depend on this. I understand this is not guaranteed by the TBBR spec but I don't want to break this implementation defined behaviour without good reason.
@Leo-Yan I just saw your earlier comment explaining why this patch is needed. Are we sure this is not just working around the problem? I don't understand why the io block layer cannot handle this. |
Hi Dimitris,
On Thu, Nov 23, 2017 at 10:28:28AM +0000, Dimitris Papastamos wrote:
@Leo-Yan I just saw your earlier comment explaining why this patch is needed.
Are we sure this is not just working around the problem? I don't understand why the io block layer cannot handle this.
I might not clearly described this issue, this issue is _NOT_ for
BL1 loading fip.bin image. I don't see the problem is introduced by
block layer in ARM-TF, the problem happens when we want to *flash*
fip.bin image into EMMC.
E.g. at the tail of fip.bin file, it needs to combine BL33 (u-boot.bin
or UEFI image); so you could see the code line [1] ensures the
image offset address is aligned, this also ensures the previous image
has been padded properly for alignment. But it misses to pad the last
one image, e.g. alignment size is 512B, uboot.bin has size 512010
bytes (512010 mod 512 = 10); so finally the fip.bin image size is not
512B alignment.
So we need flash fip.bin in board recovery mode, this needs to
download fip.bin into SRAM and flash into EMMC; for this case sometimes
we have requirement for transferring length alignment.
So I would like to check with you guys if the fip.bin length is not
aligned with the size specified by FIP_ALIGN, do you think this is an
issue or not? Originally I think if we can pad fip.bin file with
FIP_ALIGN alignment, this will be safe for any size of BL33. So this
is the purpse of this patch.
[1] https://github.com/ARM-software/arm-trusted-firmware/blob/master/tools/fiptool/fiptool.c#L552
… --
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#1166 (comment)
|
What code do you use to flash fip.bin into EMMC? Do you use the io block layer in TF or some other code? Why can't you accommodate for this case in your flashing code? |
Oh, it's not related to io block layer in TF. In TF, we could force to align. But this issue is related to usb transmission. USB is actually much like storage deivce. We need to specify the transmission size and be heavily relied on DMA. If the fip.bin isn't aligned with 512B, it causes USB driver always waiting for the last transmission that never comes. We always hope user to do the alignment. But it seems not everyone knows this limitation. So Leo prepared this patch as a workaround. |
I still don't understand why you can't fix this in your code. This is the whole purpose of having an IO block layer to hide the block size requirements of underlying devices. For example, in your flashing code you can do a write of N bytes where N is > 0 and <= 512, the block layer knows that the buffer needs to be a multiple of 512B so it will copy the data into a new buffer and issue a DMA transaction accordingly. |
The key is not in block layer. The key is in the USB driver. Image is downloaded from host to RAM by USB. And it hangs in the USB driver since it's not aligned on 512B. Block layer is only used on flushing data from RAM to storage device. |
We understood that the problem is in the USB driver. What we don't understand is why the USB driver doesn't add the padding bytes to the buffer to be able to transmit and then why you don't use the block io layer to filter these added bytes. Maybe there is some additional problem that we don't understand, but we think that this should be the correct behaviour. |
Since DMA is used in USB driver. Only when data is accumulated to the threshold of FIFO, DMA interrupt is triggered. Otherwise, USB driver is always waiting for the interrupt that never comes. So USB driver doesn't have any chance to add the padding bytes to the buffer. The key is that we're reading data from USB. If we're writing data to USB, we could add padding bytes. |
Can you give me more information about the USB device that you are using?. What device is it?, is it a mass storage device or a serial device? Can you give me a link to the code of the driver? |
It's used to download data from host to target's RAM. It looks much like storage device. Code is in this link. ( |
Do you know if the board is the host or the device in the USB communication? What sotfware do you use in the host machine? |
The board is in device mode. Fastboot is running on the host machine. |
We are going to try to reproduce the problem here. Can you give us a guide how to reproduce the problem? |
Hi @robertovargas-arm, except Haojian said the USB driver in UEFI, actually we also have one USB driver in atf-fastboot: https://github.com/96boards-hikey/atf-fastboot; this code is built for Hikey620 recovery mode for downloading image. Let me take some time to prepare the script for downloading and building code and share back with you. |
Hi @robertovargas-arm, you could use below method to reproduce the issue:
|
The board that we have here is the hikey960, can we reproduce the problem with it or do we need a hikey620? |
Yes, you need hikey620. |
Can one of the admins verify this patch? |
Hi @Leo-Yan, your patch does not fix my issue of loading fip.bin using fastboot. Former ATF version from 96Boards had a rough implementation of TBB for HiKey (620), but this official repo only has a (more generic) version of TBB for some official development platforms from ARM. I tried to port the generic one to be used on HiKey and therefore added some flags to the Makefile. Adding There's no difference between downloading fip.bin in recovery or uefi-fastboot mode. Here you can see the output using
1471849 mod 512 = 361 I applied your 94dc0de.patch but it does not solve the problem. Builds without additional flags work fine, no matter of using your patch or not, even if they are not aligned!? Example: make recovery with additional certificates in fip.bin
To use the workaround from @raw-bin I added a Makefile target.
1475945 mod 64 = 41 Therefore, my assumption is fastboot requires alignment of 64B (bytes) and not 512B. If you thought of 512 bit, please use a small 'b' to prevent size confusion. Fastboot accepted the padded file, thanks to @raw-bin.
Patching fastboot seems not to be a good option. Aren't there devices without the possibility to update fastboot? A device specific workaround could be, to add padding in Makefiles, but my read is it should be the case on other fastboot devices, too. See also: |
Hi @gitfineon, just remind except this fip patch, there have two extra modifications so can let Hikey and Hikey960 really apply alignment for ARM-TF building. You could apply patch 591ff98 and 26bb69c for Hikey and Hikey960 respectively. Following up question: I saw you have pointed out the linkage for the patch "Set alignment size to 512B for Hikey/Hikey960", could you confirm after you apply this patch still cannot see the fip.bin size is not alignment for 512B? |
Hey @Leo-Yan , sry, I tried to pass it like this Please add a hint to the commit message, requiring 512 Byte are a lot and it is used for each image, although we only need it at the end.
Using smaller FIP size of 64B (512b) for HiKey as recommended by @raw-bin, in my case saves more than 1.3KB (of zeroes !!!!) and is accepted by fastboot. Why should we use more?
I would prefer an additional parameter to align the overall size of fip.bin if it makes the images smaller and may save internal storage. E.g. using Edit: But the documentation says image address and block size are independent from source (https://github.com/ARM-software/arm-trusted-firmware/blame/master/docs/firmware-update.rst#L234). In this case overall BS of 512 byte will speed up USB Transmission but in the end images of fip.bin get realigned to the device by FWU StateMachine? |
@Leo-Yan @gitfineon Anyways, we'll re-review this thread and propose next steps. Thanks! |
@gitfineon, thanks for the testing. I think you are right, on Hikey I can see 64B is okay; but I remembered @hzhuang1 has some optimization on Hikey960, so consider to use 512B alignment is for performance optimization. @hzhuang1 is best known for USB and EMMC drivers. @davidcunado-arm, It's okay for us to hold on this patch, seems to me this patch is same with @masahir0y suggestion for --post-pad. If your team has any conclusion, we can follow up that for this. Thanks for reviewing! |
@hzhuang1 We only have a hikey960 here, and it means that I cannot test it. I am a bit confused, because I still don't understand why it cannot be fixed in the usb drivers that you have. You have the control over the drivers of the two devices in the communication. Is there some reason why you cannot fix it in the drivers? Maybe you can add the padding in the host driver and get rid of it in the device driver. We would prefer a solution of that type, because this PR can generate problems to other people. |
What about a patch along these lines? This will maintain the constraint that the null entry should point to the end of the file, so the offset of the null entry image is the size of the file.
|
I'm going to close this PR in its current form. We've created #1204 as an alternative solution to the problem that this PR was looking to address. |
ARM trusted firmware can specify alignment, the alignment has been
applied on every image start address when combine fip.bin; but it misses
to apply alignment to the file tail, so fip.bin file size cannot be
specified alignment.
This commit checks the tail of fip.bin file and pad zeros on the tail
for alignment.
Fixes ARM-software/tf-issues#528
Signed-off-by: Leo Yan [email protected]