How to stop a U-Boot macro using itest
Asked Answered
B

1

11

I need to create a 3-step macro in U-Boot:

  1. Use dhcp to download an image to memory. This sets filesize
  2. Test if $filesize > $SOMELIMIT, print a message, and stop
  3. Would write the downloaded image to flash.

I know how to do steps 1 and 3, but not 2.

I know that I can use the U-Boot command itest to test integer values, but I don't know how to create a compound statement in the if/else/endif clause. And I don't know how to have an "abort macro" step in one of those clauses.

How can I stop a U-Boot command sequence abruptly?

Bicorn answered 14/3 at 20:38 Comment(9)
For #2, the usual advice is to study the examples in include/config_distro_bootcmd.h. Re #1, that doesn't make sense; you probably mean TFTP instead of "dhcp".Cofferdam
@Cofferdam According to the online help the dhcp command supports loading the file specified by the DHCP server or by the user as parameter via TFTP. It works fine for me. - Offline documentation for if, itest, dhcp is still missing in U-Boot (cf. docs.u-boot.org/en/latest/usage/index.html#shell-commands). Patches are welcome.Belak
"How can I stop a uboot command sequence abruptly?" - You don't need to when you use the structured programming construct of if ... then ... else ... properly and as intended. There's no need to "stop" (???) or "abort" execution. Your "step #3" is merely the alternative action to the if ... then ... action, so "step 3" should be the else ... action.Cofferdam
This post is beeing discussed on meta.Cohin
Even if this post is well about programming, it's opinion-based and not focused?Cohin
So what is the process in a then clause to a) print a message and stop the macro and in the else clause print success and continueBicorn
It would seem the echo. Command should have a error option that it could use to print an message and cancel or exit with a command failureBicorn
@Cohin How is it opinion based and not focused? The majority of questions on SO are "how do I do X", which is exactly what this question is. The question is incredibly clear and concise too.Semipalatinsk
@Semipalatinsk at the time of my comment, he were asking Suggestions?, and (it's already the case here) he's asking for help for 2 actions, so it's not focused on one problem, only on one project which have 2 problemCohin
B
5

For testing if the result of itest is true you can use the if command. To leave a macro use the exitcommand:

setenv macro 'if itest $filesize > 2048; then exit; else echo bingo; fi; echo continuing'
setenv filesize 10000
run macro

Man-pages for 'if' and 'itest' have been added to https://docs.u-boot.org/en/latest/usage/.

Belak answered 15/3 at 12:24 Comment(1)
I want to do two things I want to print an error message and exit keyword and exitBicorn

© 2022 - 2024 — McMap. All rights reserved.