# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/mtd/partitions/openwrt,uimage.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: OpenWrt variations of U-Boot Image partitions

maintainers:
  - Bjørn Mork <bjorn@mork.no>

description: |
  The image format defined by the boot loader "Das U-Boot" is often
  modified or extended by device vendors. This defines a few optional
  properties which can be used to describe such modifications.

# partition.txt defines common properties, but has not yet been
# converted to YAML
#allOf:
#  - $ref: ../partition.yaml#

properties:
  compatible:
    items:
      - enum:
          - openwrt,uimage
      - const: denx,uimage

  openwrt,padding:
    description: Number of padding bytes between header and data
    $ref: /schemas/types.yaml#/definitions/uint32
    default: 0

  openwrt,ih-magic:
    description: U-Boot Image Header magic number.
    $ref: /schemas/types.yaml#/definitions/uint32
    default: 0x27051956 # IH_MAGIC

  openwrt,ih-type:
    description: U-Boot Image type
    $ref: /schemas/types.yaml#/definitions/uint32
    default: 2 # IH_TYPE_KERNEL

  openwrt,offset:
    description:
      Offset between partition start and U-Boot Image in bytes
    $ref: /schemas/types.yaml#/definitions/uint32
    default: 0

  openwrt,partition-magic:
    description:
      Magic number found at the start of the partition. Will only be
      validated if both this property and openwrt,offset is non-zero
    $ref: /schemas/types.yaml#/definitions/uint32
    default: 0

required:
  - compatible
  - reg

#unevaluatedProperties: false
additionalProperties: false

examples:
  - |
    // device with non-default magic
    partition@300000 {
          compatible = "openwrt,uimage", "denx,uimage";
          reg = <0x00300000 0xe80000>;
          label = "firmware";
          openwrt,ih-magic = <0x4e474520>;
    };
  - |
    // device with U-Boot Image at an offset, with a partition magic value
    partition@70000 {
          compatible = "openwrt,uimage", "denx,uimage";
          reg = <0x00070000 0x00790000>;
          label = "firmware";
          openwrt,offset = <20>;
          openwrt,partition-magic = <0x43535953>;
    };
  - |
    // device using a non-default image type
    #include "dt-bindings/mtd/partitions/uimage.h"
    partition@6c0000 {
          compatible = "openwrt,uimage", "denx,uimage";
          reg = <0x6c0000 0x1900000>;
          label = "firmware";
          openwrt,ih-magic = <0x33373033>;
          openwrt,ih-type = <IH_TYPE_FILESYSTEM>;
    };
