Conditional execution within a mkifs [.script]

Can I you use an if statement within a [.script] directive in a mkifs
build file? Is there an alternative?

The Building Embedded Systems manual indicates the script is parsed by
mkifs so procnto doesn’t have to contain a complete shell interpreter
but it doesn’t specify what capabilities are present (nor does the mkifs
docs).

Here’s what I’m trying to do:

Developing a custom image for an embedded device. It has a serial port
that could be used for diagnostic i/o if a hw jumper is installed. If
the jumper is not installed, the port is reserved for other uses. If
the jumper is installed, I want to redirect output to the serial port as
early as possbile.

I created a simple app called testjmpr (returns 0 if jumper installed)
and compiled it into the OS. I attempted to add some logic to the build
file like:

[+script] .script = {
devc-ser8250-jace5 -e -c25000000 -b57600 0xffffc000,9 0xffffd000,10
&
if testjmpr
then
reopen
fi

But when I boot this image, I get error messages

Unable to start “if” (2)
Unable to start “then” (2)
Unable to start “fi” (2)

Any suggestions / alternative approaches?

Thanks
Dan Giorgis
Tridium

Unfortunately, these are not shell scripts - the syntax is limited to that
which is in the mkifs documentation. Perhaps this would be a good feature
to request however… You may be able to simulate this behaviour by
writing simple shell scripts to include in the image that could be executed
by a shell. I think in your case you might be out of luck because you want
to use the reopen command which wouldn’t be available in a shell script.

Kris

“Dan Giorgis” <dang@tridium.com> wrote in message
news:3C9F4D9F.EF21D41E@tridium.com

Can I you use an if statement within a [.script] directive in a mkifs
build file? Is there an alternative?

The Building Embedded Systems manual indicates the script is parsed by
mkifs so procnto doesn’t have to contain a complete shell interpreter
but it doesn’t specify what capabilities are present (nor does the mkifs
docs).

Here’s what I’m trying to do:

Developing a custom image for an embedded device. It has a serial port
that could be used for diagnostic i/o if a hw jumper is installed. If
the jumper is not installed, the port is reserved for other uses. If
the jumper is installed, I want to redirect output to the serial port as
early as possbile.

I created a simple app called testjmpr (returns 0 if jumper installed)
and compiled it into the OS. I attempted to add some logic to the build
file like:

[+script] .script = {
devc-ser8250-jace5 -e -c25000000 -b57600 0xffffc000,9 0xffffd000,10
&
if testjmpr
then
reopen
fi

But when I boot this image, I get error messages

Unable to start “if” (2)
Unable to start “then” (2)
Unable to start “fi” (2)

Any suggestions / alternative approaches?

Thanks
Dan Giorgis
Tridium

Can I you use an if statement within a [.script] directive in a mkifs
build file? Is there an alternative?

Unable to start “if” (2)
Unable to start “then” (2)
Unable to start “fi” (2)

No “if”, as the shell used in *.ifs isn’t even a shell
which lacks lots of fluffs available in standard ksh.
See mkifs helppages.

I guess that’s why there’s oh-so-overloaded “diskboot” is used for
desktop applications (which needs LOTS of predicates)


Developing a custom image for an embedded device. It has a serial port
that could be used for diagnostic i/o if a hw jumper is installed. If
the jumper is not installed, the port is reserved for other uses. If
the jumper is installed, I want to redirect output to the serial port as
early as possbile.

[+script] .script = {
devc-ser8250-jace5 -e -c25000000 -b57600 0xffffc000,9 0xffffd000,10
&
if testjmpr
then
reopen
fi

Now I’m not an embedded guy so just guessing;

You can’t selectively reopen console inside the .script
(and reopen-ing in subprocess/subshell won’t work anyway), so

*) At the end of the .script, exec to the program which switches the console
or
*) Make a program (in C) that tests the jumper, and will procmgr_symlink
/dev/myconsole to appropriate devices (/dev/ser0 or /dev/console?),
and just wait in the .script for “reopen /dev/myconsole”
(dunno if this works)

kabe

Dan Giorgis <dang@tridium.com> wrote in news:3C9F4D9F.EF21D41E@tridium.com:

Can I you use an if statement within a [.script] directive in a mkifs
build file? Is there an alternative?

The Building Embedded Systems manual indicates the script is parsed by
mkifs so procnto doesn’t have to contain a complete shell interpreter
but it doesn’t specify what capabilities are present (nor does the mkifs
docs).

Correct, mkifs parses the build file, and choices (if they could be made)
could only be made at build time. Since proc doesn’t contain a (full)shell
interpreter, you can’t do run-time checking of return values of programs
executed.

You could write a wrapper ksh script that would build a image that outputs
to the serial port or does not. Or you could load two images, and have
your IPL code choose which to load based on the jumper.


Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

Thanks to all who replied. In case anyone’s interested, I came up with
a simple workaround described below.

Developing a custom image for an embedded device. It has a serial port
that could be used for diagnostic i/o if a hw jumper is installed. If
the jumper is not installed, the port is reserved for other uses. If
the jumper is installed, I want to redirect output to the serial port as
early as possbile.

I created an executable that tests for the presence of the jumper. If
jumper is installed, a symbolic link from /dev/serialDebug to /dev/ser1
is created. If not installed, a symbolic link from /dev/serialDebug to
/dev/null is created instead. I can then always use “reopen
/dev/serialDebug” in my mkifs script.

Dan Giorgis
Tridium

I know this is an old post, but I was just trying to do this same thing.
There is a way to do it.

In your build script have a line that reads:
[+session} ksh -c /proc/boot/script2

Then add a script2 file to your boot image as:
[perms=0500] script2 = {

Here you can put anything

you would want in a normal shell script

}

Now the only catch is that:

  1. you either have to include ksh in the boot image, or
  2. already have another file system loaded.
    If using another file system you may need to add a path to ksh.


    Kris Warkentin <kewarken@qnx.com> wrote:
    KW > Unfortunately, these are not shell scripts - the syntax is limited to that
    KW > which is in the mkifs documentation. Perhaps this would be a good feature
    KW > to request however… You may be able to simulate this behaviour by
    KW > writing simple shell scripts to include in the image that could be executed
    KW > by a shell. I think in your case you might be out of luck because you want
    KW > to use the reopen command which wouldn’t be available in a shell script.

KW > Kris

KW > “Dan Giorgis” <dang@tridium.com> wrote in message
KW > news:3C9F4D9F.EF21D41E@tridium.com

Can I you use an if statement within a [.script] directive in a mkifs
build file? Is there an alternative?

The Building Embedded Systems manual indicates the script is parsed by
mkifs so procnto doesn’t have to contain a complete shell interpreter
but it doesn’t specify what capabilities are present (nor does the mkifs
docs).

Here’s what I’m trying to do:

Developing a custom image for an embedded device. It has a serial port
that could be used for diagnostic i/o if a hw jumper is installed. If
the jumper is not installed, the port is reserved for other uses. If
the jumper is installed, I want to redirect output to the serial port as
early as possbile.

I created a simple app called testjmpr (returns 0 if jumper installed)
and compiled it into the OS. I attempted to add some logic to the build
file like:

[+script] .script = {
devc-ser8250-jace5 -e -c25000000 -b57600 0xffffc000,9 0xffffd000,10
&
if testjmpr
then
reopen
fi

But when I boot this image, I get error messages

Unable to start “if” (2)
Unable to start “then” (2)
Unable to start “fi” (2)

Any suggestions / alternative approaches?

Thanks
Dan Giorgis
Tridium