[U-Boot] help: how get last command result using scripting
Michael Nazzareno Trimarchi
michael at amarulasolutions.com
Fri Jun 22 08:42:57 UTC 2018
Hi
On Fri, Jun 22, 2018 at 10:32 AM, Lukasz Majewski <lukma at denx.de> wrote:
> Hi Michael,
>
>> Hi
>>
>> On Fri, Jun 22, 2018 at 9:10 AM, Lukasz Majewski <lukma at denx.de>
>> wrote:
>> > Hi Michael,
>> >
>> >> Hi all
>> >>
>> >> Trying to understand how to get the last result. For example:
>> >> sspi 1:0.3 24 700002; sspi 1:1.3 24 730000
>> >
>> > The $? shall do the job.
>> >
>> > => true
>> > => echo $?
>> > 0
>> > => false
>> > => echo $?
>> > 1
>>
>> commit d7fc57cf5637416d23adb2e5fd1e6ec8fbed6a63
>> Author: Michael Trimarchi <michael at amarulasolutions.com>
>> Date: Wed Jun 20 13:46:50 2018 +0200
>>
>> cmd: spi: Export sspi command result in an enviroment variable
>>
>> We would like to export sspi result in enviroment variable to use
>> it later in any scripts
>
> Now I do see about what you were asking for. I've misunderstood you.
>
My general idea is to provide an our variable to stdout to all the
command that give some result or exptend command interface
to something like
do_xxxx()
{
redirect-stdout -> enviroment
do somenthing
return
}
Michael
>>
>> Change-Id: Iad92455630e3ef8042b2a9fe02f8995c0d8974c9
>> Signed-off-by: Michael Trimarchi <michael at amarulasolutions.com>
>>
>> diff --git a/cmd/spi.c b/cmd/spi.c
>> index 9a2edcf..00a9c15 100644
>> --- a/cmd/spi.c
>> +++ b/cmd/spi.c
>> @@ -37,13 +37,18 @@ static unsigned int cs;
>> static unsigned int mode;
>> static int bitlen;
>> static uchar dout[MAX_SPI_BYTES];
>> -static uchar din[MAX_SPI_BYTES];
>> +static uchar din[MAX_SPI_BYTES + 1];
>> +
>> +/* enviroment variable used to export the result */
>> +static char env_din[2 * MAX_SPI_BYTES];
>>
>> static int do_spi_xfer(int bus, int cs)
>> {
>> struct spi_slave *slave;
>> int ret = 0;
>>
>> + env_set("spiout", "");
>> +
>> #ifdef CONFIG_DM_SPI
>> char name[30], *str;
>> struct udevice *dev;
>> @@ -79,9 +84,13 @@ static int do_spi_xfer(int bus, int cs)
>> } else {
>> int j;
>>
>> - for (j = 0; j < ((bitlen + 7) / 8); j++)
>> + for (j = 0; j < ((bitlen + 7) / 8); j++) {
>> printf("%02X", din[j]);
>> + sprintf(&env_din[2 * j], "%02x", din[j]);
>> + }
>> printf("\n");
>> + env_din[2 * j] = 0;
>> + env_set("spiout", env_din);
>> :
>>
>> Michael
>> >
>> > Or have I misunderstood something?
>> >
>> >>
>> >> Now I need to have the last output of the last command to compare
>> >> in one script. Any idea?
>> >>
>> >> Michael
>> >> _______________________________________________
>> >> U-Boot mailing list
>> >> U-Boot at lists.denx.de
>> >> https://lists.denx.de/listinfo/u-boot
>> >
>> >
>> >
>> >
>> > Best regards,
>> >
>> > Lukasz Majewski
>> >
>> > --
>> >
>> > DENX Software Engineering GmbH, Managing Director: Wolfgang
>> > Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell,
>> > Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email:
>> > wd at denx.de
>>
>>
>>
>
>
>
>
> Best regards,
>
> Lukasz Majewski
>
> --
>
> DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
--
| Michael Nazzareno Trimarchi Amarula Solutions BV |
| COO - Founder Cruquiuskade 47 |
| +31(0)851119172 Amsterdam 1018 AM NL |
| [`as] http://www.amarulasolutions.com |
More information about the U-Boot
mailing list