From: Stefan Roese Date: Tue, 24 Mar 2020 08:26:46 +0100 Subject: [PATCH v3 3/5] cmd: mvebu: bubt: verify A38x target device type In-Reply-To: <20200323174307.209645-3-mrjoel@lixil.net> References: <20200323174307.209645-1-mrjoel@lixil.net> <20200323174307.209645-3-mrjoel@lixil.net> Message-ID: <234e468f-7494-496b-71e7-e28f92dcdbe7@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 23.03.20 18:43, Joel Johnson wrote: > Ensure that the device to which an image is being written includes > header information indicating boot support for the destination > device. > > This is derived from the support in the SolidRun master-a38x vendor > fork. > > Signed-off-by: Joel Johnson > > --- > > v2 changes: > - none > v3 changes: > - use ARRAY_SIZE instead of #define size > > --- > cmd/mvebu/bubt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 45 insertions(+), 2 deletions(-) > > diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c > index b80b81c82a..fbcad37c40 100644 > --- a/cmd/mvebu/bubt.c > +++ b/cmd/mvebu/bubt.c > @@ -107,6 +107,24 @@ struct a38x_main_hdr_v1 { > u8 ext; /* 0x1E */ > u8 checksum; /* 0x1F */ > }; > + > +struct a38x_boot_mode { > + unsigned int id; > + const char *name; > +}; > + > +/* The blockid header field values used to indicate boot device of image */ > +struct a38x_boot_mode a38x_boot_modes[] = { > + { 0x4D, "i2c" }, > + { 0x5A, "spi" }, > + { 0x69, "uart" }, > + { 0x78, "sata" }, > + { 0x8B, "nand" }, > + { 0x9C, "pex" }, > + { 0xAE, "mmc" }, > + {}, > +}; > + > #endif > > struct bubt_dev { > @@ -644,6 +662,23 @@ static int check_image_header(void) > return 0; > } > #elif defined(CONFIG_ARMADA_38X) > +static int a38x_check_boot_mode(const struct bubt_dev *dst) > +{ > + int mode; > + const struct a38x_main_hdr_v1 *hdr = > + (struct a38x_main_hdr_v1 *)get_load_addr(); > + > + for (mode = 0; mode < ARRAY_SIZE(a38x_boot_modes); mode++) { > + if (strcmp(a38x_boot_modes[mode].name, dst->name) == 0) > + break; > + } > + > + if (a38x_boot_modes[mode].id == hdr->blockid) > + return 0; > + > + return -ENOEXEC; > +} > + > static size_t a38x_header_size(const struct a38x_main_hdr_v1 *h) > { > if (h->version == 1) > @@ -697,7 +732,7 @@ static int check_image_header(void) > } > #endif > > -static int bubt_verify(size_t image_size) > +static int bubt_verify(const struct bubt_dev *dst) > { > int err; > > @@ -708,6 +743,14 @@ static int bubt_verify(size_t image_size) > return err; > } > > +#if defined(CONFIG_ARMADA_38X) > + err = a38x_check_boot_mode(dst); > + if (err) { > + puts("Error: image not built for destination device!\n"); > + return err; > + } > +#endif Sorry for spotting this so late, but could you please change this to if (IS_ENABLED(CONFIG_ARMADA_38X)) { err = a38x_check_boot_mode(dst); ... instead (less #ifdef's). Other than that, please add my: Reviewed-by: Stefan Roese Thanks, Stefan > + > return 0; > } > > @@ -829,7 +872,7 @@ int do_bubt_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) > if (!image_size) > return -EIO; > > - err = bubt_verify(image_size); > + err = bubt_verify(dst); > if (err) > return err; > > Viele Gr??e, Stefan -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de