Skip to content

boot_serial: Fix incorrect format specifier for off_t #1413

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

Merged
merged 1 commit into from
Aug 4, 2022

Conversation

stephanosio
Copy link
Contributor

The BOOT_LOG_INF function, which uses the format specifiers defined
by the C standard, was incorrectly printing a variable with the type of
off_t using the %x format specifier, which is intended to be used
with the int type.

The off_t type, specified by the POSIX standard, is not guaranteed to
be int, and it may be defined as long or long long depending on
the toolchain and the target architecture.

This commit updates the print routine such that it casts the arguments
of the off_t type to intmax_t and prints them out using the
corresponding %jx format specifier.

Signed-off-by: Stephanos Ioannidis [email protected]

@stephanosio
Copy link
Contributor Author

FYI @nvlsianpu

@ngboonkhai
Copy link

Hi, may I know how's the progress of this pull request? Is it pending for another reviewer before it can be merged?

@ngboonkhai
Copy link

@nvlsianpu

@ngboonkhai
Copy link

@de-nordic

@ngboonkhai
Copy link

@carlescufi

Copy link
Member

@d3zd3z d3zd3z left a comment

Choose a reason for hiding this comment

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

I'm a little concerned if the 'j' is available in all of the printf variants that might be available to us. It doesn't look like nanolibc supports it, and I wonder if this will work in those configurations.

Intmax might also be fairly inefficient on some of these targets, but I'm not sure of a better way to handle it, at least portably.

@@ -301,7 +301,8 @@ static off_t erase_range(const struct flash_area *fap, off_t start, off_t end)
}

size = flash_sector_get_off(&sect) + flash_sector_get_size(&sect) - start;
BOOT_LOG_INF("Erasing range 0x%x:0x%x", start, start + size - 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not to cast this to ssize and use z?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because ssize_t is not guaranteed to be the largest integer type supported and/or the same size as off_t.

Copy link
Collaborator

@de-nordic de-nordic Jul 15, 2022

Choose a reason for hiding this comment

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

because ssize_t is not guaranteed to be the largest integer type supported and/or the same size as off_t.

We should probably replace the off_t, here, with the uint32_t, including the erase_range definition; I do not think that we need offsets and sizes greater than 32-bit here (for example Zephyr flash_map sizes are uint32_t). Than just use llx and cast expressions to unsigned long long - this should cover both 32 and 64 bit systems for us.
Scratch that, is should be possible to access slot anywhere on the external flash, so it means that it may be beyond 32-bit range, so off_t would be correct here, if we can make off_t 64bit on 32bit machines to make this work.

@stephanosio
Copy link
Contributor Author

I'm a little concerned if the 'j' is available in all of the printf variants that might be available to us.

The j modifier was introduced in the C99 and it should be supported by all toolchains/libc that claim to support the C99 standard and above.

Also, as far as Zephyr is concerned, it is supported by all toolchains/libc; but, as you noted, that might not be the case for the rest of the targets that mcuboot supports.

If there indeed is a toolchain/libc supported by the mcuboot that does not support the j modifier, then I will revise this patch to cast the values to (long) and do %lx, which is far from ideal but should be portable ...

@ngboonkhai
Copy link

Hi @stephanosio, in the previous comment you mention that you will revise the patch may I know how is the progress?

@stephanosio
Copy link
Contributor Author

If there indeed is a toolchain/libc supported by the mcuboot that does not support the j modifier

That is "if there indeed is a toolchain/libc supported by the mcuboot that does not support the j modifier."

Someone will need to approve the CI run here so we can see.

@ngboonkhai
Copy link

@nvlsianpu @de-nordic

@ngboonkhai
Copy link

ngboonkhai commented Jul 20, 2022

@nvlsianpu @de-nordic @ioannisg @utzig @d3zd3z
Please help to approve the CI run and get this resolved asap, this PR is blocking
zephyrproject-rtos/zephyr#47612
zephyrproject-rtos/zephyr#46443

@de-nordic de-nordic requested a review from nvlsianpu July 20, 2022 09:32
@de-nordic
Copy link
Collaborator

@nvlsianpu @de-nordic @ioannisg @utzig @d3zd3z Please help to approve the CI run and get this resolved asap, this PR is blocking zephyrproject-rtos/zephyr#47612 zephyrproject-rtos/zephyr#46443

I do not see how the zephyrproject-rtos/zephyr#46443](zephyrproject-rtos/zephyr#46443 is depending on this.
Anyway, making change here will not immediately fix zephyrproject-rtos/mcuboot, there needs to be sync done.

@ngboonkhai
Copy link

@nvlsianpu @de-nordic @ioannisg @utzig @d3zd3z Please help to approve the CI run and get this resolved asap, this PR is blocking zephyrproject-rtos/zephyr#47612 zephyrproject-rtos/zephyr#46443

I do not see how the zephyrproject-rtos/zephyr#46443](zephyrproject-rtos/zephyr#46443 is depending on this. Anyway, making change here will not immediately fix zephyrproject-rtos/mcuboot, there needs to be sync done.

Because I did a workaround to just pass the workflow check for the flash_shell.c, so the reviewer can continue review on the other part, once this PR 1413 is checked in will remove the work around patch
zephyrproject-rtos/zephyr@62e1f63

@ngboonkhai
Copy link

ngboonkhai commented Jul 20, 2022

Anyway, making change here will not immediately fix zephyrproject-rtos/mcuboot, there needs to be sync done.

That's the reason why I keep rushing to complete this PR

@ngboonkhai
Copy link

Hi @de-nordic,

Is @nvlsianpu the maintainer? He seems like not very responsive.

@carlescufi
Copy link
Collaborator

Hi @de-nordic,

Is @nvlsianpu the maintainer? He seems like not very responsive.

He's on holiday.

@ngboonkhai
Copy link

Hi @de-nordic,
Is @nvlsianpu the maintainer? He seems like not very responsive.

He's on holiday.

I see, thanks for informing. Other than him, is there any other colleague that would be able to help?

@ngboonkhai
Copy link

Hi, @utzig @d3zd3z,

I notice that you are the top contributor of mcuboot, can you guys help to enable the CI workflow to run? Thanks

Copy link
Collaborator

@gustavonihei gustavonihei left a comment

Choose a reason for hiding this comment

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

LGTM

@ngboonkhai
Copy link

Hi @stephanosio, can you help to take a look at the CI result?

@ngboonkhai
Copy link

Hi @stephanosio, any updates?

@stephanosio
Copy link
Contributor Author

stephanosio commented Aug 3, 2022

Hi @stephanosio, any updates?

This is not a problem specific to this PR. The mcuboot maintainers will need to fix their CI.

p.s. the CI is tracking the Zephyr main repo, which is subject to breakages. This is generally a bad practice -- it should either track a specific release or commit.

ZEPHYR_VERSION: 'main'

@ngboonkhai
Copy link

Hi, @utzig @d3zd3z @gustavonihei @nvlsianpu @de-nordic @ioannisg. Can you please take a look at the CI?

@nvlsianpu
Copy link
Collaborator

@ngboonkhai @stephanosio Can you rebase? This looks like the "too big flash footprint" issue we recently fixed on the mian branch.

@ngboonkhai
Copy link

@ngboonkhai @stephanosio Can you rebase? This looks like the "too big flash footprint" issue we recently fixed on the mian branch.

Hi @nvlsianpu, Need stephan help to rebase, I'm here to keep track this issue to unblock my PR in Zephyr zephyrproject-rtos/zephyr#46443

The `BOOT_LOG_INF` function, which uses the format specifiers defined
by the C standard, was incorrectly printing a variable with the type of
`off_t` using the `%x` format specifier, which is intended to be used
with the `int` type.

The `off_t` type, specified by the POSIX standard, is not guaranteed to
be `int`, and it may be defined as `long` or `long long` depending on
the toolchain and the target architecture.

This commit updates the print routine such that it casts the arguments
of the `off_t` type to `intmax_t` and prints them out using the
corresponding `%jx` format specifier.

Signed-off-by: Stephanos Ioannidis <[email protected]>
@stephanosio stephanosio force-pushed the fix_off_t_print_upstream branch from 2ce9f1e to ddd8888 Compare August 3, 2022 15:16
@stephanosio
Copy link
Contributor Author

Rebased

@nvlsianpu nvlsianpu merged commit 09e2bd7 into mcu-tools:main Aug 4, 2022
@ngboonkhai
Copy link

Thanks everyone for he effort.
Hi @nvlsianpu would you create a PR in zephyr repo to handle the mcuboot fork sync and west.yml ?

@nvlsianpu
Copy link
Collaborator

@ngboonkhai Yes I will do this on Monday.

@ngboonkhai
Copy link

@ngboonkhai Yes I will do this on Monday.

@nvlsianpu Okay, Thanks a lot :D

@ngboonkhai
Copy link

nvlsianpu

Hi @nvlsianpu

Quick check with you on the mcuboot fork sync, have you got a chance to look into it? I try my luck to search over the zephyr PR but can't find.

@nvlsianpu
Copy link
Collaborator

zephyrproject-rtos#85

@ngboonkhai
Copy link

zephyrproject-rtos#85

Thanks @nvlsianpu

@ngboonkhai
Copy link

nvlsianpu

Hi @nvlsianpu I believe you need to update the revision number at the zephyr west.yaml as well
https://github.com/zephyrproject-rtos/zephyr/blob/main/west.yml#L175

@carlescufi
Copy link
Collaborator

nvlsianpu

Hi @nvlsianpu I believe you need to update the revision number at the zephyr west.yaml as well https://github.com/zephyrproject-rtos/zephyr/blob/main/west.yml#L175

zephyrproject-rtos/zephyr#48786

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants