From: Miquel Raynal <miquel.raynal@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 10/19] tpm: add TPM2_SelfTest command support
Date: Sat, 28 Apr 2018 15:10:34 +0200 [thread overview]
Message-ID: <20180428151034.5004e2c2@xps13> (raw)
In-Reply-To: <CAPnjgZ2KvxHjxG4o1w3iMfXwVjjhw2S49T3SsCvvELM5Xz=n+w@mail.gmail.com>
Hi Simon,
On Thu, 26 Apr 2018 08:40:24 -0600, Simon Glass <sjg@chromium.org>
wrote:
> Hi Miquel,
>
> On 24 April 2018 at 06:53, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> > Hi Simon,
> >
> > I am back on that topic, let me answer some of your questions before
> > addressing them in a next version.
> >
> > On Fri, 30 Mar 2018 06:42:25 +0800, Simon Glass
> > <sjg@chromium.org> wrote:
> >
> >> Hi Miquel,
> >>
> >> On 29 March 2018 at 15:43, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> >> > Add support for the TPM2_Selftest command.
> >> >
> >> > Change the command file and the help accordingly.
> >> >
> >> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> >> > ---
> >> > include/tpm.h | 9 +++++++--
> >> > lib/tpm.c | 36 ++++++++++++++++++++++++++++--------
> >> > 2 files changed, 35 insertions(+), 10 deletions(-)
> >> >
> >> > diff --git a/include/tpm.h b/include/tpm.h
> >> > index ba71bac885..38d7cb899d 100644
> >> > --- a/include/tpm.h
> >> > +++ b/include/tpm.h
> >> > @@ -31,6 +31,11 @@ enum tpm2_structures {
> >> > TPM2_ST_SESSIONS = 0x8002,
> >> > };
> >> >
> >> > +enum tpm2_yes_no {
> >> > + TPMI_YES = 1,
> >> > + TPMI_NO = 0,
> >> > +};
> >> > +
> >> > enum tpm_startup_type {
> >> > TPM_ST_CLEAR = 0x0001,
> >> > TPM_ST_STATE = 0x0002,
> >> > @@ -476,14 +481,14 @@ int tpm_startup(enum tpm_startup_type mode);
> >> > *
> >> > * @return return code of the operation
> >> > */
> >> > -uint32_t tpm_self_test_full(void);
> >> > +int tpm_self_test_full(void);
> >> >
> >> > /**
> >> > * Issue a TPM_ContinueSelfTest command.
> >> > *
> >> > * @return return code of the operation
> >> > */
> >> > -uint32_t tpm_continue_self_test(void);
> >> > +int tpm_continue_self_test(void);
> >> >
> >> > /**
> >> > * Issue a TPM_NV_DefineSpace command. The implementation is limited
> >> > diff --git a/lib/tpm.c b/lib/tpm.c
> >> > index 0c57ef8dc7..3cc2888267 100644
> >> > --- a/lib/tpm.c
> >> > +++ b/lib/tpm.c
> >> > @@ -341,20 +341,40 @@ int tpm_startup(enum tpm_startup_type mode)
> >> > return 0;
> >> > }
> >> >
> >> > -uint32_t tpm_self_test_full(void)
> >> > +int tpm_self_test_full(void)
> >> > {
> >> > - const uint8_t command[10] = {
> >> > - 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50,
> >> > + const u8 command_v1[10] = {
> >> > + U16_TO_ARRAY(0xc1),
> >>
> >> Here I can see some benefit to your macros because the data is better
> >> structured. But why not use the pack_byte_string() function?
> >
> > TPM buffers (1.0 and 2.0) are, most of the time, filled with data of
> > known length (1, 2 or 4 bytes). You can see that most of the time,
> > TPMv1 simple commands were just filling a buffer of bytes. I don't like
> > very much the fact that the user should split the data in byte array so
> > I introduced these macros that do it for me in a cleaner way. When you
> > get an hexadecimal value (like it was the case before) it is easy to
> > split a "0xabcd" in "0xab, 0xcd", but I prefer to use variables or
> > simply defines sometimes and writing "TPM2_ST_NO_SESSIONS" as
> > "TPM2_ST_NO_SESSIONS >> 8, TPM2_ST_NO_SESSIONS & 0xFF" is not readable
> > at all.
> >
> > Now why did I not use the existing pack_byte_string() function. Well,
> > at first I did and realized it was a pain to have a decent
> > incrementation of the offsets, mostly when commands tend to be longer
> > and longer. Having such lists of offset/variable/length while you could
> > define them statically on the stack -which also saves some computing
> > time- is quickly annoying and hard to review. From my point of view this
> > function is a real asset when it comes to 'unknown'/'big' variable
> > length (like a password, an hmac, an user input, etc) but should be
> > avoided when not necessary: typically to fill a buffer with defined
> > values.
> >
> > I am of course very open on the topic, this is my feeling but I don't
> > have that much experience and would carefully listen to yours.
>
> I don't think this is an unreasonable point of view. Either works.
>
> But if you are changing the approach to use static data, should you
> convert the existing code to the new scheme?
I don't think this is relevant anymore as files have been split. You'll
tell me what you think with the next version (need to do some testing
and I'll be done with it).
Regards,
Miquèl
>
> Regards,
> Simon
--
Miquel Raynal, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2018-04-28 13:10 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-29 7:43 [U-Boot] [PATCH v2 00/19] Introduce SPI TPM v2.0 support Miquel Raynal
2018-03-29 7:43 ` [U-Boot] [PATCH v2 01/19] tpm: add Revision ID field in the chip structure Miquel Raynal
2018-03-29 22:41 ` Simon Glass
2018-03-29 7:43 ` [U-Boot] [PATCH v2 02/19] tpm: rename tpm_tis_infineon in tpm_tis_infineon_i2c Miquel Raynal
2018-03-29 22:41 ` Simon Glass
2018-03-29 7:43 ` [U-Boot] [PATCH v2 03/19] tpm: add support for TPMv2 SPI modules Miquel Raynal
2018-03-29 22:41 ` Simon Glass
2018-04-24 13:02 ` Miquel Raynal
2018-03-29 7:43 ` [U-Boot] [PATCH v2 04/19] tpm: fix indentation in command list before adding more Miquel Raynal
2018-03-29 22:41 ` Simon Glass
2018-03-29 7:43 ` [U-Boot] [PATCH v2 05/19] tpm: prepare support for TPMv2 commands Miquel Raynal
2018-03-29 22:42 ` Simon Glass
2018-03-29 7:43 ` [U-Boot] [PATCH v2 06/19] tpm: add macros " Miquel Raynal
2018-03-29 22:42 ` Simon Glass
2018-03-29 7:43 ` [U-Boot] [PATCH v2 07/19] tpm: add possible traces to analyze buffers returned by the TPM Miquel Raynal
2018-03-29 22:42 ` Simon Glass
2018-04-28 12:27 ` Miquel Raynal
2018-03-29 7:43 ` [U-Boot] [PATCH v2 08/19] tpm: handle different buffer sizes Miquel Raynal
2018-03-29 22:42 ` Simon Glass
2018-03-29 7:43 ` [U-Boot] [PATCH v2 09/19] tpm: add TPM2_Startup command support Miquel Raynal
2018-03-29 22:42 ` Simon Glass
2018-04-27 13:45 ` Miquel Raynal
2018-03-29 7:43 ` [U-Boot] [PATCH v2 10/19] tpm: add TPM2_SelfTest " Miquel Raynal
2018-03-29 22:42 ` Simon Glass
2018-04-24 12:53 ` Miquel Raynal
2018-04-26 14:40 ` Simon Glass
2018-04-28 13:10 ` Miquel Raynal [this message]
2018-03-29 7:43 ` [U-Boot] [PATCH v2 11/19] tpm: add TPM2_Clear " Miquel Raynal
2018-03-29 22:42 ` Simon Glass
2018-04-24 13:17 ` Miquel Raynal
2018-04-26 14:40 ` Simon Glass
2018-04-27 13:39 ` Miquel Raynal
2018-05-03 19:01 ` Simon Glass
2018-03-29 7:43 ` [U-Boot] [PATCH v2 12/19] tpm: rename the _extend() function to be _pcr_event() Miquel Raynal
2018-03-29 9:44 ` Reinhard Pfau
2018-03-29 9:46 ` Miquel Raynal
2018-03-29 7:43 ` [U-Boot] [PATCH v2 13/19] tpm: add TPM2_PCR_Extend command support Miquel Raynal
2018-03-29 7:43 ` [U-Boot] [PATCH v2 14/19] tpm: add TPM2_PCR_Read " Miquel Raynal
2018-03-29 7:43 ` [U-Boot] [PATCH v2 15/19] tpm: add TPM2_GetCapability " Miquel Raynal
2018-03-29 7:43 ` [U-Boot] [PATCH v2 16/19] tpm: add dictionary attack mitigation commands support Miquel Raynal
2018-03-29 7:43 ` [U-Boot] [PATCH v2 17/19] tpm: add TPM2_HierarchyChangeAuth command support Miquel Raynal
2018-03-29 7:44 ` [U-Boot] [PATCH v2 18/19] tpm: add PCR authentication commands support Miquel Raynal
2018-03-29 22:42 ` Simon Glass
2018-03-29 7:44 ` [U-Boot] [PATCH v2 19/19] test/py: add TPMv2.0 test suite Miquel Raynal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180428151034.5004e2c2@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox