]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
sunxi: Create helper function veryfing valid boot signature on MMC
authorDaniel Kochmański <dkochmanski@turtle-solutions.eu>
Fri, 29 May 2015 14:55:41 +0000 (16:55 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Wed, 9 Sep 2015 11:49:04 +0000 (13:49 +0200)
This patch extracts checking for valid SD card "eGON.BT0" signature from
`board_mmc_init` into function `sunxi_mmc_has_egon_boot_signature`.

Buffer for mmc sector is allocated and freed at runtime. `panic` is
triggered on malloc failure.

Signed-off-by: Daniel Kochmański <dkochmanski@turtle-solutions.eu>
CC: Roy Spliet <r.spliet@ultimaker.com>
Cc: Ian Campbell <ijc@hellion.org.uk>
[hdegoede@redhat.com: Small bugfix to make it work for devs other then mmc0]
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
arch/arm/include/asm/arch-sunxi/mmc.h
board/sunxi/board.c
drivers/mmc/sunxi_mmc.c

index cb52e648731ce9687b7c9cb472463fd54d8da38d..3da360b177d9b2a0369745f253a759652aac32ca 100644 (file)
@@ -127,4 +127,5 @@ struct sunxi_mmc {
 #define SUNXI_MMC_COMMON_RESET                 (1 << 18)
 
 struct mmc *sunxi_mmc_init(int sdc_no);
+int sunxi_mmc_has_egon_boot_signature(struct mmc *mmc);
 #endif /* _SUNXI_MMC_H */
index ed60e74808ffd4c8b6187d5cb5f1c0d231a40e8c..76e4b9bcc1e176548956daec8472ce6763827046 100644 (file)
@@ -299,12 +299,8 @@ int board_mmc_init(bd_t *bis)
         * Both mmc0 and mmc2 are bootable, figure out where we're booting
         * from. Try mmc0 first, just like the brom does.
         */
-       if (mmc_getcd(mmc0) && mmc_init(mmc0) == 0 &&
-           mmc0->block_dev.block_read(0, 16, 1, buf) == 1) {
-               buf[12] = 0;
-               if (strcmp(&buf[4], "eGON.BT0") == 0)
-                       return 0;
-       }
+       if (sunxi_mmc_has_egon_boot_signature(mmc0))
+               return 0;
 
        /* no bootable card in mmc0, so we must be booting from mmc2, swap */
        mmc0->block_dev.dev = 1;
index e7ab828a8f1e1f5df54088e8d9d52e0d1c1b1889..f9b9493c892152dcdc958cb5da65feb46191dace 100644 (file)
@@ -433,6 +433,23 @@ static int sunxi_mmc_getcd(struct mmc *mmc)
        return !gpio_get_value(cd_pin);
 }
 
+int sunxi_mmc_has_egon_boot_signature(struct mmc *mmc)
+{
+       char *buf = malloc(512);
+       int valid_signature = 0;
+
+       if (buf == NULL)
+               panic("Failed to allocate memory\n");
+
+       if (mmc_getcd(mmc) && mmc_init(mmc) == 0 &&
+           mmc->block_dev.block_read(mmc->block_dev.dev, 16, 1, buf) == 1 &&
+           strncmp(&buf[4], "eGON.BT0", 8) == 0)
+               valid_signature = 1;
+
+       free(buf);
+       return valid_signature;
+}
+
 static const struct mmc_ops sunxi_mmc_ops = {
        .send_cmd       = sunxi_mmc_send_cmd,
        .set_ios        = sunxi_mmc_set_ios,