Merge branch '2022-04-11-assorted-updates'
authorTom Rini <trini@konsulko.com>
Mon, 11 Apr 2022 19:59:45 +0000 (15:59 -0400)
committerTom Rini <trini@konsulko.com>
Mon, 11 Apr 2022 19:59:45 +0000 (15:59 -0400)
- Assorted fixes/updates including K3-J721s2 timer dts fix, assorted
  crypto improvements, led-pwm driver, improve handling of mtd
  partitions, align mkimage hash output buffers and backport a UBIFS
  bugfix from Linux.

22 files changed:
MAINTAINERS
arch/arm/dts/k3-j721s2-common-proc-board-u-boot.dtsi
boot/image-fit.c
boot/pxe_utils.c
common/spl/Kconfig
common/spl/spl_mmc.c
doc/device-tree-bindings/leds/leds-pwm.txt [new file with mode: 0644]
drivers/ata/ahci-pci.c
drivers/led/Kconfig
drivers/led/Makefile
drivers/led/led_bcm6858.c
drivers/led/led_pwm.c [new file with mode: 0644]
drivers/mtd/mtdpart.c
drivers/mtd/nand/raw/nand_base.c
fs/ubifs/tnc.c
include/image.h
include/linux/mtd/mtd.h
include/u-boot/rsa.h
lib/crypto/pkcs7_verify.c
lib/crypto/x509_public_key.c
lib/rsa/rsa-verify.c
tools/mkimage.h

index 6142504..7a9e315 100644 (file)
@@ -899,6 +899,12 @@ F: doc/README.kwbimage
 F:     doc/kwboot.1
 F:     tools/kwb*
 
+LED
+M:     Ivan Vozvakhov <i.vozvakhov@vk.team>
+S:     Supported
+F:     doc/device-tree-bindings/leds/leds-pwm.txt
+F:     drivers/led/led_pwm.c
+
 LOGGING
 M:     Simon Glass <sjg@chromium.org>
 S:     Maintained
index 749bc71..a17e61e 100644 (file)
@@ -40,7 +40,7 @@
                compatible = "ti,omap5430-timer";
                reg = <0x0 0x40400000 0x0 0x80>;
                ti,timer-alwon;
-               clock-frequency = <25000000>;
+               clock-frequency = <250000000>;
                u-boot,dm-spl;
        };
 
index f01cafe..6610035 100644 (file)
@@ -24,6 +24,7 @@
 #include <mapmem.h>
 #include <asm/io.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <asm/global_data.h>
 #ifdef CONFIG_DM_HASH
 #include <dm.h>
@@ -1263,7 +1264,8 @@ int calculate_hash(const void *data, int data_len, const char *name,
 static int fit_image_check_hash(const void *fit, int noffset, const void *data,
                                size_t size, char **err_msgp)
 {
-       uint8_t value[FIT_MAX_HASH_LEN];
+       DEFINE_ALIGN_BUFFER(uint8_t, value, FIT_MAX_HASH_LEN,
+                           ARCH_DMA_MINALIGN);
        int value_len;
        const char *algo;
        uint8_t *fit_value;
index 0c24bec..b08aee9 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <dm.h>
 #include <env.h>
 #include <image.h>
 #include <log.h>
@@ -14,6 +15,7 @@
 #include <lcd.h>
 #include <net.h>
 #include <fdt_support.h>
+#include <video.h>
 #include <linux/libfdt.h>
 #include <linux/string.h>
 #include <linux/ctype.h>
@@ -21,7 +23,6 @@
 #include <linux/list.h>
 
 #ifdef CONFIG_DM_RNG
-#include <dm.h>
 #include <rng.h>
 #endif
 
@@ -1516,8 +1517,13 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg)
                /* display BMP if available */
                if (cfg->bmp) {
                        if (get_relfile(ctx, cfg->bmp, image_load_addr, NULL)) {
-                               if (CONFIG_IS_ENABLED(CMD_CLS))
-                                       run_command("cls", 0);
+#if defined(CONFIG_DM_VIDEO)
+                               struct udevice *dev;
+
+                               err = uclass_first_device_err(UCLASS_VIDEO, &dev);
+                               if (!err)
+                                       video_clear(dev);
+#endif
                                bmp_display(image_load_addr,
                                            BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
                        } else {
index a3a6f31..ac61b25 100644 (file)
@@ -668,7 +668,8 @@ config SYS_MMCSD_FS_BOOT_PARTITION
        default 1
        help
          Partition on the MMC to load U-Boot from when the MMC is being
-         used in fs mode
+         used in fs mode.
+         Use -1 as a special value to use the first bootable partition.
 
 config SPL_MMC_TINY
        bool "Tiny MMC framework in SPL"
index 1bb785a..6116a68 100644 (file)
@@ -280,16 +280,40 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image,
 {
        int err = -ENOSYS;
 
+       __maybe_unused int partition = CONFIG_SYS_MMCSD_FS_BOOT_PARTITION;
+
+#if CONFIG_SYS_MMCSD_FS_BOOT_PARTITION == -1
+       {
+               struct disk_partition info;
+               debug("Checking for the first MBR bootable partition\n");
+               for (int type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) {
+                       err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info);
+                       if (err)
+                               continue;
+                       debug("Partition %d is of type %d and bootable=%d\n", type_part, info.sys_ind, info.bootable);
+                       if (info.bootable != 0) {
+                               debug("Partition %d is bootable, using it\n", type_part);
+                               partition = type_part;
+                               break;
+                       }
+               }
+               printf("Using first bootable partition: %d\n", partition);
+               if (partition == CONFIG_SYS_MMCSD_FS_BOOT_PARTITION) {
+                       return -ENOSYS;
+               }
+       }
+#endif
+
 #ifdef CONFIG_SPL_FS_FAT
        if (!spl_start_uboot()) {
                err = spl_load_image_fat_os(spl_image, bootdev, mmc_get_blk_desc(mmc),
-                       CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
+                       partition);
                if (!err)
                        return err;
        }
 #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
        err = spl_load_image_fat(spl_image, bootdev, mmc_get_blk_desc(mmc),
-                                CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
+                                partition,
                                 filename);
        if (!err)
                return err;
@@ -298,13 +322,13 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image,
 #ifdef CONFIG_SPL_FS_EXT4
        if (!spl_start_uboot()) {
                err = spl_load_image_ext_os(spl_image, bootdev, mmc_get_blk_desc(mmc),
-                       CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
+                       partition);
                if (!err)
                        return err;
        }
 #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
        err = spl_load_image_ext(spl_image, bootdev, mmc_get_blk_desc(mmc),
-                                CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
+                                partition,
                                 filename);
        if (!err)
                return err;
diff --git a/doc/device-tree-bindings/leds/leds-pwm.txt b/doc/device-tree-bindings/leds/leds-pwm.txt
new file mode 100644 (file)
index 0000000..186e8a8
--- /dev/null
@@ -0,0 +1,47 @@
+LEDs connected to PWM (Linux compatible)
+
+Required properties:
+- compatible : should be "pwm-leds".
+
+Each LED is represented as a sub-node of the pwm-leds device.  Each
+node's name represents the name of the corresponding LED.
+
+LED sub-node properties:
+- pwms :  (required) LED pwm channel, see "pwms property" in
+  doc/device-tree-bindings/pwm/pwm.txt
+- label :  (optional) LED label, see "label property" in
+  doc/device-tree-bindings/led/common.txt
+- max-brightness :  (optional, unsigned, default 255) Maximum brightness possible
+  for the LED
+- active-low :  (optional, boolean, default false) For PWMs where the LED is
+  wired to supply rather than ground
+- u-boot,default-brightness :  (optional, unsigned, default 0) Initial state
+  of pwm-leds
+
+Example:
+
+leds {
+    compatible = "pwm-leds";
+    status = "okay";
+
+    blue {
+        label = "led-blue";
+        pwms = <&pwm1 0 100000 0>;
+        max-brightness = <255>;
+        u-boot,default-brightness = <127>;
+    };
+
+    green {
+        label = "led-green";
+        pwms = <&pwm2 0 100000 0>;
+        max-brightness = <255>;
+        u-boot,default-brightness = <127>;
+    };
+
+    red {
+        label = "led-red";
+        pwms = <&pwm3 0 100000 0>;
+        max-brightness = <255>;
+        u-boot,default-brightness = <127>;
+    };
+}
index b1d231e..797e0d5 100644 (file)
@@ -38,6 +38,8 @@ U_BOOT_DRIVER(ahci_pci) = {
 static struct pci_device_id ahci_pci_supported[] = {
        { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_SATA_AHCI, ~0) },
        { PCI_DEVICE(0x1b21, 0x0611) },
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6121) },
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6145) },
        {},
 };
 
index 430d076..418ed21 100644 (file)
@@ -49,6 +49,12 @@ config LED_CORTINA
          This option enables support for LEDs connected to the Cortina
          Access CAxxxx SOCs.
 
+config LED_PWM
+       bool "LED PWM"
+       depends on LED && DM_PWM
+       help
+         Enable support for LEDs connected to PWM.
+         Linux compatible ofdata.
 
 config LED_BLINK
        bool "Support LED blinking"
index 2aa2c21..49ae919 100644 (file)
@@ -8,5 +8,6 @@ obj-$(CONFIG_LED_BCM6328) += led_bcm6328.o
 obj-$(CONFIG_LED_BCM6358) += led_bcm6358.o
 obj-$(CONFIG_LED_BCM6753) += led_bcm6753.o
 obj-$(CONFIG_LED_BCM6858) += led_bcm6858.o
+obj-$(CONFIG_LED_PWM) += led_pwm.o
 obj-$(CONFIG_$(SPL_)LED_GPIO) += led_gpio.o
 obj-$(CONFIG_LED_CORTINA) += led_cortina.o
index fbf46a1..3ca6c5b 100644 (file)
@@ -18,6 +18,7 @@
 
 #define LEDS_MAX               32
 #define LEDS_WAIT              100
+#define LEDS_MAX_BRIGHTNESS    7
 
 /* LED Mode register */
 #define LED_MODE_REG           0x0
@@ -38,6 +39,8 @@
 #define LED_HW_LED_EN_REG              0x08
 /* LED Flash control register0 */
 #define LED_FLASH_RATE_CONTROL_REG0    0x10
+/* LED Brightness control register0 */
+#define LED_BRIGHTNESS_CONTROL_REG0    0x20
 /* Soft LED input register */
 #define LED_SW_LED_IP_REG              0xb8
 /* Parallel LED Output Polarity Register */
@@ -96,6 +99,27 @@ static int bcm6858_led_set_period(struct udevice *dev, int period_ms)
 }
 #endif
 
+static int led_set_brightness(struct udevice *dev, unsigned int brightness)
+{
+       struct bcm6858_led_priv *priv = dev_get_priv(dev);
+       u32 offset, shift, mask, value;
+
+       offset = (priv->pin / 8) * 4;
+       shift  = (priv->pin % 8) * 4;
+       mask   = 0xf << shift;
+
+       /* 8 levels of brightness achieved through PWM */
+       value = (brightness > LEDS_MAX_BRIGHTNESS ?
+                       LEDS_MAX_BRIGHTNESS : brightness) << shift;
+
+       debug("%s: %s brightness set to %u\n", __func__, dev->name, value >> shift);
+
+       clrbits_32(priv->regs + LED_BRIGHTNESS_CONTROL_REG0 + offset, mask);
+       setbits_32(priv->regs + LED_BRIGHTNESS_CONTROL_REG0 + offset, value);
+
+       return 0;
+}
+
 static enum led_state_t bcm6858_led_get_state(struct udevice *dev)
 {
        struct bcm6858_led_priv *priv = dev_get_priv(dev);
@@ -113,6 +137,8 @@ static int bcm6858_led_set_state(struct udevice *dev, enum led_state_t state)
 {
        struct bcm6858_led_priv *priv = dev_get_priv(dev);
 
+       debug("%s: Set led %s to %d\n", __func__, dev->name, state);
+
        switch (state) {
        case LEDST_OFF:
                clrbits_32(priv->regs + LED_SW_LED_IP_REG, (1 << priv->pin));
@@ -180,7 +206,7 @@ static int bcm6858_led_probe(struct udevice *dev)
        } else {
                struct bcm6858_led_priv *priv = dev_get_priv(dev);
                void __iomem *regs;
-               unsigned int pin;
+               unsigned int pin, brightness;
 
                regs = dev_remap_addr(dev_get_parent(dev));
                if (!regs)
@@ -201,6 +227,10 @@ static int bcm6858_led_probe(struct udevice *dev)
                        clrbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin);
                else
                        setbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin);
+
+               brightness = dev_read_u32_default(dev, "default-brightness",
+                                                 LEDS_MAX_BRIGHTNESS);
+               led_set_brightness(dev, brightness);
        }
 
        return 0;
diff --git a/drivers/led/led_pwm.c b/drivers/led/led_pwm.c
new file mode 100644 (file)
index 0000000..4e50272
--- /dev/null
@@ -0,0 +1,192 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022 VK
+ * Author: Ivan Vozvakhov <i.vozvakhov@vk.team>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <led.h>
+#include <malloc.h>
+#include <dm/lists.h>
+#include <pwm.h>
+
+#define LEDS_PWM_DRIVER_NAME   "led_pwm"
+
+struct led_pwm_priv {
+       struct udevice *pwm;
+       uint period;    /* period in ns */
+       uint duty;      /* duty cycle in ns */
+       uint channel;   /* pwm channel number */
+       bool active_low;        /* pwm polarity */
+       bool enabled;
+};
+
+static int led_pwm_enable(struct udevice *dev)
+{
+       struct led_pwm_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       ret = pwm_set_invert(priv->pwm, priv->channel, priv->active_low);
+       if (ret)
+               return ret;
+
+       ret = pwm_set_config(priv->pwm, priv->channel, priv->period, priv->duty);
+       if (ret)
+               return ret;
+
+       ret = pwm_set_enable(priv->pwm, priv->channel, true);
+       if (ret)
+               return ret;
+
+       priv->enabled = true;
+
+       return 0;
+}
+
+static int led_pwm_disable(struct udevice *dev)
+{
+       struct led_pwm_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       ret = pwm_set_config(priv->pwm, priv->channel, priv->period, 0);
+       if (ret)
+               return ret;
+
+       ret = pwm_set_enable(priv->pwm, priv->channel, false);
+       if (ret)
+               return ret;
+
+       priv->enabled = false;
+
+       return 0;
+}
+
+static int led_pwm_set_state(struct udevice *dev, enum led_state_t state)
+{
+       struct led_pwm_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       switch (state) {
+       case LEDST_OFF:
+               ret = led_pwm_disable(dev);
+               break;
+       case LEDST_ON:
+               ret = led_pwm_enable(dev);
+               break;
+       case LEDST_TOGGLE:
+               ret = (priv->enabled) ? led_pwm_disable(dev) : led_pwm_enable(dev);
+               break;
+       default:
+               ret = -ENOSYS;
+       }
+
+       return ret;
+}
+
+static enum led_state_t led_pwm_get_state(struct udevice *dev)
+{
+       struct led_pwm_priv *priv = dev_get_priv(dev);
+
+       return (priv->enabled) ? LEDST_ON : LEDST_OFF;
+}
+
+static int led_pwm_probe(struct udevice *dev)
+{
+       struct led_pwm_priv *priv = dev_get_priv(dev);
+       struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev);
+
+       /* Ignore the top-level LED node */
+       if (!uc_plat->label)
+               return 0;
+
+       return led_pwm_set_state(dev, (priv->enabled) ? LEDST_ON : LEDST_OFF);
+}
+
+static int led_pwm_of_to_plat(struct udevice *dev)
+{
+       struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev);
+       struct led_pwm_priv *priv = dev_get_priv(dev);
+       struct ofnode_phandle_args args;
+       uint def_brightness, max_brightness;
+       int ret;
+
+       /* Ignore the top-level LED node */
+       if (!uc_plat->label)
+               return 0;
+
+       ret = dev_read_phandle_with_args(dev, "pwms", "#pwm-cells", 0, 0, &args);
+       if (ret)
+               return ret;
+
+       ret = uclass_get_device_by_ofnode(UCLASS_PWM, args.node, &priv->pwm);
+       if (ret)
+               return ret;
+
+       priv->channel = args.args[0];
+       priv->period = args.args[1];
+       priv->active_low = dev_read_bool(dev, "active-low");
+
+       def_brightness = dev_read_u32_default(dev, "u-boot,default-brightness", 0);
+       max_brightness = dev_read_u32_default(dev, "max-brightness", 255);
+       priv->enabled =  !!def_brightness;
+
+       /*
+        * No need to handle pwm iverted case (active_low)
+        * because of pwm_set_invert function
+        */
+       if (def_brightness < max_brightness)
+               priv->duty = priv->period * def_brightness / max_brightness;
+       else
+               priv->duty = priv->period;
+
+       return 0;
+}
+
+static int led_pwm_bind(struct udevice *parent)
+{
+       struct udevice *dev;
+       ofnode node;
+       int ret;
+
+       dev_for_each_subnode(node, parent) {
+               struct led_uc_plat *uc_plat;
+               const char *label;
+
+               label = ofnode_read_string(node, "label");
+               if (!label)
+                       label = ofnode_get_name(node);
+
+               ret = device_bind_driver_to_node(parent, LEDS_PWM_DRIVER_NAME,
+                                                ofnode_get_name(node),
+                                                node, &dev);
+               if (ret)
+                       return ret;
+
+               uc_plat = dev_get_uclass_plat(dev);
+               uc_plat->label = label;
+       }
+       return 0;
+}
+
+static const struct led_ops led_pwm_ops = {
+       .set_state = led_pwm_set_state,
+       .get_state = led_pwm_get_state,
+};
+
+static const struct udevice_id led_pwm_ids[] = {
+       { .compatible = "pwm-leds" },
+       { }
+};
+
+U_BOOT_DRIVER(led_pwm) = {
+       .name = LEDS_PWM_DRIVER_NAME,
+       .id = UCLASS_LED,
+       .of_match = led_pwm_ids,
+       .ops = &led_pwm_ops,
+       .priv_auto = sizeof(struct led_pwm_priv),
+       .bind = led_pwm_bind,
+       .probe = led_pwm_probe,
+       .of_to_plat = led_pwm_of_to_plat,
+};
index 4119ea4..d077897 100644 (file)
@@ -887,10 +887,14 @@ int add_mtd_partitions_of(struct mtd_info *master)
        ofnode parts, child;
        int i = 0;
 
-       if (!master->dev)
+       if (!master->dev && !ofnode_valid(master->flash_node))
                return 0;
 
-       parts = ofnode_find_subnode(mtd_get_ofnode(master), "partitions");
+       if (master->dev)
+               parts = ofnode_find_subnode(mtd_get_ofnode(master), "partitions");
+       else
+               parts = ofnode_find_subnode(master->flash_node, "partitions");
+
        if (!ofnode_valid(parts) || !ofnode_is_available(parts) ||
            !ofnode_device_is_compatible(parts, "fixed-partitions"))
                return 0;
index f761698..a007603 100644 (file)
@@ -5257,6 +5257,7 @@ int nand_scan_tail(struct mtd_info *mtd)
                break;
        }
 
+       mtd->flash_node = chip->flash_node;
        /* Fill in remaining MTD driver data */
        mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH;
        mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM :
index e8b8f16..4fb1004 100644 (file)
@@ -50,6 +50,11 @@ enum {
        NOT_ON_MEDIA = 3,
 };
 
+static int try_read_node(const struct ubifs_info *c, void *buf, int type,
+                        int len, int lnum, int offs);
+static int fallible_read_node(struct ubifs_info *c, const union ubifs_key *key,
+                             struct ubifs_zbranch *zbr, void *node);
+
 /**
  * insert_old_idx - record an index node obsoleted since the last commit start.
  * @c: UBIFS file-system description object
@@ -402,7 +407,19 @@ static int tnc_read_node_nm(struct ubifs_info *c, struct ubifs_zbranch *zbr,
                return 0;
        }
 
-       err = ubifs_tnc_read_node(c, zbr, node);
+       if (c->replaying) {
+               err = fallible_read_node(c, &zbr->key, zbr, node);
+               /*
+                * When the node was not found, return -ENOENT, 0 otherwise.
+                * Negative return codes stay as-is.
+                */
+               if (err == 0)
+                       err = -ENOENT;
+               else if (err == 1)
+                       err = 0;
+       } else {
+               err = ubifs_tnc_read_node(c, zbr, node);
+       }
        if (err)
                return err;
 
@@ -2770,7 +2787,11 @@ struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
        if (nm->name) {
                if (err) {
                        /* Handle collisions */
-                       err = resolve_collision(c, key, &znode, &n, nm);
+                       if (c->replaying)
+                               err = fallible_resolve_collision(c, key, &znode, &n,
+                                                                nm, 0);
+                       else
+                               err = resolve_collision(c, key, &znode, &n, nm);
                        dbg_tnc("rc returned %d, znode %p, n %d",
                                err, znode, n);
                        if (unlikely(err < 0))
index 673b5f5..e4c6a50 100644 (file)
@@ -1309,7 +1309,7 @@ ll_entry_declare(struct crypto_algo, __name, cryptos)
 struct padding_algo {
        const char *name;
        int (*verify)(struct image_sign_info *info,
-                     uint8_t *pad, int pad_len,
+                     const uint8_t *pad, int pad_len,
                      const uint8_t *hash, int hash_len);
 };
 
index 7455400..af45e63 100644 (file)
@@ -305,6 +305,7 @@ struct mtd_info {
        struct device dev;
 #else
        struct udevice *dev;
+       ofnode flash_node;
 #endif
        int usecount;
 
index b9634e3..085363e 100644 (file)
@@ -101,11 +101,11 @@ int rsa_verify_with_pkey(struct image_sign_info *info,
                         const void *hash, uint8_t *sig, uint sig_len);
 
 int padding_pkcs_15_verify(struct image_sign_info *info,
-                          uint8_t *msg, int msg_len,
+                          const uint8_t *msg, int msg_len,
                           const uint8_t *hash, int hash_len);
 
 int padding_pss_verify(struct image_sign_info *info,
-                      uint8_t *msg, int msg_len,
+                      const uint8_t *msg, int msg_len,
                       const uint8_t *hash, int hash_len);
 
 #define RSA_DEFAULT_PADDING_NAME               "pkcs-1.5"
index 82c5c74..b832f01 100644 (file)
@@ -65,6 +65,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,
                return -ENOPKG;
        if (!strcmp(sinfo->sig->hash_algo, "sha256"))
                sig->digest_size = SHA256_SUM_LEN;
+       else if (!strcmp(sinfo->sig->hash_algo, "sha384"))
+               sig->digest_size = SHA384_SUM_LEN;
+       else if (!strcmp(sinfo->sig->hash_algo, "sha512"))
+               sig->digest_size = SHA512_SUM_LEN;
        else if (!strcmp(sinfo->sig->hash_algo, "sha1"))
                sig->digest_size = SHA1_SUM_LEN;
        else
index d557ab2..5c0e2b6 100644 (file)
@@ -71,6 +71,10 @@ int x509_get_sig_params(struct x509_certificate *cert)
                return -ENOPKG;
        if (!strcmp(sig->hash_algo, "sha256"))
                sig->digest_size = SHA256_SUM_LEN;
+       else if (!strcmp(sig->hash_algo, "sha384"))
+               sig->digest_size = SHA384_SUM_LEN;
+       else if (!strcmp(sig->hash_algo, "sha512"))
+               sig->digest_size = SHA512_SUM_LEN;
        else if (!strcmp(sig->hash_algo, "sha1"))
                sig->digest_size = SHA1_SUM_LEN;
        else
index 1126640..1d95cfb 100644 (file)
@@ -73,7 +73,7 @@ static int rsa_verify_padding(const uint8_t *msg, const int pad_len,
 }
 
 int padding_pkcs_15_verify(struct image_sign_info *info,
-                          uint8_t *msg, int msg_len,
+                          const uint8_t *msg, int msg_len,
                           const uint8_t *hash, int hash_len)
 {
        struct checksum_algo *checksum = info->checksum;
@@ -125,7 +125,7 @@ static void u32_i2osp(uint32_t val, uint8_t *buf)
  * Return: 0 if the octet string was correctly generated, others on error
  */
 static int mask_generation_function1(struct checksum_algo *checksum,
-                                    uint8_t *seed, int seed_len,
+                                    const uint8_t *seed, int seed_len,
                                     uint8_t *output, int output_len)
 {
        struct image_region region[2];
@@ -176,9 +176,9 @@ out:
 }
 
 static int compute_hash_prime(struct checksum_algo *checksum,
-                             uint8_t *pad, int pad_len,
-                             uint8_t *hash, int hash_len,
-                             uint8_t *salt, int salt_len,
+                             const uint8_t *pad, int pad_len,
+                             const uint8_t *hash, int hash_len,
+                             const uint8_t *salt, int salt_len,
                              uint8_t *hprime)
 {
        struct image_region region[3];
@@ -204,9 +204,11 @@ out:
 /*
  * padding_pss_verify() - verify the pss padding of a signature
  *
- * Only works with a rsa_pss_saltlen:-2 (default value) right now
- * saltlen:-1 "set the salt length to the digest length" is currently
- * not supported.
+ * Works with any salt length
+ *
+ * msg is a concatenation of : masked_db + h + 0xbc
+ * Once unmasked, db is a concatenation of : [0x00]* + 0x01 + salt
+ * Length of 0-padding at begin of db depends on salt length.
  *
  * @info:      Specifies key and FIT information
  * @msg:       byte array of message, len equal to msg_len
@@ -215,30 +217,28 @@ out:
  * @hash_len:  Length of the hash
  */
 int padding_pss_verify(struct image_sign_info *info,
-                      uint8_t *msg, int msg_len,
+                      const uint8_t *msg, int msg_len,
                       const uint8_t *hash, int hash_len)
 {
-       uint8_t *masked_db = NULL;
-       int masked_db_len = msg_len - hash_len - 1;
-       uint8_t *h = NULL, *hprime = NULL;
-       int h_len = hash_len;
+       const uint8_t *masked_db = NULL;
        uint8_t *db_mask = NULL;
-       int db_mask_len = masked_db_len;
-       uint8_t *db = NULL, *salt = NULL;
-       int db_len = masked_db_len, salt_len = msg_len - hash_len - 2;
+       uint8_t *db = NULL;
+       int db_len = msg_len - hash_len - 1;
+       const uint8_t *h = NULL;
+       uint8_t *hprime = NULL;
+       int h_len = hash_len;
+       uint8_t *db_nopad = NULL, *salt = NULL;
+       int db_padlen, salt_len;
        uint8_t pad_zero[8] = { 0 };
        int ret, i, leftmost_bits = 1;
        uint8_t leftmost_mask;
        struct checksum_algo *checksum = info->checksum;
 
        /* first, allocate everything */
-       masked_db = malloc(masked_db_len);
-       h = malloc(h_len);
-       db_mask = malloc(db_mask_len);
+       db_mask = malloc(db_len);
        db = malloc(db_len);
-       salt = malloc(salt_len);
        hprime = malloc(hash_len);
-       if (!masked_db || !h || !db_mask || !db || !salt || !hprime) {
+       if (!db_mask || !db || !hprime) {
                printf("%s: can't allocate some buffer\n", __func__);
                ret = -ENOMEM;
                goto out;
@@ -252,8 +252,8 @@ int padding_pss_verify(struct image_sign_info *info,
        }
 
        /* step 5 */
-       memcpy(masked_db, msg, masked_db_len);
-       memcpy(h, msg + masked_db_len, h_len);
+       masked_db = &msg[0];
+       h = &msg[db_len];
 
        /* step 6 */
        leftmost_mask = (0xff >> (8 - leftmost_bits)) << (8 - leftmost_bits);
@@ -265,7 +265,7 @@ int padding_pss_verify(struct image_sign_info *info,
        }
 
        /* step 7 */
-       mask_generation_function1(checksum, h, h_len, db_mask, db_mask_len);
+       mask_generation_function1(checksum, h, h_len, db_mask, db_len);
 
        /* step 8 */
        for (i = 0; i < db_len; i++)
@@ -275,19 +275,24 @@ int padding_pss_verify(struct image_sign_info *info,
        db[0] &= 0xff >> leftmost_bits;
 
        /* step 10 */
-       if (db[0] != 0x01) {
+       db_padlen = 0;
+       while (db[db_padlen] == 0x00 && db_padlen < (db_len - 1))
+               db_padlen++;
+       db_nopad = &db[db_padlen];
+       if (db_nopad[0] != 0x01) {
                printf("%s: invalid pss padding ", __func__);
-               printf("(leftmost byte of db isn't 0x01)\n");
+               printf("(leftmost byte of db after 0-padding isn't 0x01)\n");
                ret = EINVAL;
                goto out;
        }
 
        /* step 11 */
-       memcpy(salt, &db[1], salt_len);
+       salt_len = db_len - db_padlen - 1;
+       salt = &db_nopad[1];
 
        /* step 12 & 13 */
        compute_hash_prime(checksum, pad_zero, 8,
-                          (uint8_t *)hash, hash_len,
+                          hash, hash_len,
                           salt, salt_len, hprime);
 
        /* step 14 */
@@ -295,11 +300,8 @@ int padding_pss_verify(struct image_sign_info *info,
 
 out:
        free(hprime);
-       free(salt);
        free(db);
        free(db_mask);
-       free(h);
-       free(masked_db);
 
        return ret;
 }
index 0d31484..7652c8b 100644 (file)
@@ -41,6 +41,9 @@ static inline ulong map_to_sysmem(void *ptr)
        return (ulong)(uintptr_t)ptr;
 }
 
+#define ARCH_DMA_MINALIGN 1
+#define DEFINE_ALIGN_BUFFER(type, name, size, alugn) type name[size]
+
 #define MKIMAGE_TMPFILE_SUFFIX         ".tmp"
 #define MKIMAGE_MAX_TMPFILE_LEN                256
 #define MKIMAGE_DEFAULT_DTC_OPTIONS    "-I dts -O dtb -p 500"