// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
 */

#include "k3-binman.dtsi"

#if defined(CONFIG_CPU_V7R)

&rcfg_yaml_tifs {
	config = "tifs-rm-cfg.yaml";
};

&binman {
	tiboot3_j784s4_hs: template-9 {
		section {
		ti-secure-rom {
			content = <&u_boot_spl>, <&ti_fs_enc>, <&combined_tifs_cfg>,
				<&combined_dm_cfg>, <&sysfw_inner_cert>;
			combined;
			dm-data;
			sysfw-inner-cert;
			keyfile = "custMpk.pem";
			sw-rev = <1>;
			content-sbl = <&u_boot_spl>;
			content-sysfw = <&ti_fs_enc>;
			content-sysfw-data = <&combined_tifs_cfg>;
			content-sysfw-inner-cert = <&sysfw_inner_cert>;
			content-dm-data = <&combined_dm_cfg>;
			load = <CONFIG_SPL_TEXT_BASE>;
			load-sysfw = <0x40000>;
			load-sysfw-data = <0x66800>;
			load-dm-data = <0x41c80000>;
		};

		u_boot_spl: u-boot-spl {
			no-expanded;
		};

		ti_fs_enc: ti-fs-enc.bin {
			type = "blob-ext";
		};

		combined_tifs_cfg: combined-tifs-cfg.bin {
			filename = "combined-tifs-cfg.bin";
			type = "blob-ext";
		};

		sysfw_inner_cert: sysfw-inner-cert {
			type = "blob-ext";
		};

		combined_dm_cfg: combined-dm-cfg.bin {
			filename = "combined-dm-cfg.bin";
			type = "blob-ext";
		};
		};
	};
};

&binman {
	tiboot3_j784s4_hs_fs: template-10 {
		section {
		ti-secure-rom {
			content = <&u_boot_spl_fs>, <&ti_fs_enc_fs>, <&combined_tifs_cfg_fs>,
				<&combined_dm_cfg_fs>, <&sysfw_inner_cert_fs>;
			combined;
			dm-data;
			sysfw-inner-cert;
			keyfile = "custMpk.pem";
			sw-rev = <1>;
			content-sbl = <&u_boot_spl_fs>;
			content-sysfw = <&ti_fs_enc_fs>;
			content-sysfw-data = <&combined_tifs_cfg_fs>;
			content-sysfw-inner-cert = <&sysfw_inner_cert_fs>;
			content-dm-data = <&combined_dm_cfg_fs>;
			load = <CONFIG_SPL_TEXT_BASE>;
			load-sysfw = <0x40000>;
			load-sysfw-data = <0x66800>;
			load-dm-data = <0x41c80000>;
		};

		u_boot_spl_fs: u-boot-spl {
			no-expanded;
		};

		ti_fs_enc_fs: ti-fs-enc.bin {
			type = "blob-ext";
		};

		combined_tifs_cfg_fs: combined-tifs-cfg.bin {
			filename = "combined-tifs-cfg.bin";
			type = "blob-ext";
		};

		sysfw_inner_cert_fs: sysfw-inner-cert {
			type = "blob-ext";
		};

		combined_dm_cfg_fs: combined-dm-cfg.bin {
			filename = "combined-dm-cfg.bin";
			type = "blob-ext";
		};
		};
	};
};

&binman {
	tiboot3_j784s4_gp: template-11 {
		section {
		ti-secure-rom {
			content = <&u_boot_spl_unsigned>, <&ti_fs_gp>,
				<&combined_tifs_cfg_gp>, <&combined_dm_cfg_gp>;
			combined;
			dm-data;
			content-sbl = <&u_boot_spl_unsigned>;
			load = <CONFIG_SPL_TEXT_BASE>;
			content-sysfw = <&ti_fs_gp>;
			load-sysfw = <0x40000>;
			content-sysfw-data = <&combined_tifs_cfg_gp>;
			load-sysfw-data = < 0x66800>;
			content-dm-data = <&combined_dm_cfg_gp>;
			load-dm-data = <0x41c80000>;
			sw-rev = <1>;
			keyfile = "ti-degenerate-key.pem";
		};

		u_boot_spl_unsigned: u-boot-spl {
			no-expanded;
		};

		ti_fs_gp: ti-fs-gp.bin {
			type = "blob-ext";
		};

		combined_tifs_cfg_gp: combined-tifs-cfg-gp.bin {
			filename = "combined-tifs-cfg.bin";
			type = "blob-ext";
		};

		combined_dm_cfg_gp: combined-dm-cfg-gp.bin {
			filename = "combined-dm-cfg.bin";
			type = "blob-ext";
		};
		};
	};
};

#else

&binman {
	ti_spl: template-12 {
		insert-template = <&ti_spl_template>;

		fit {
			images {
				dm {
					ti-secure {
						content = <&dm>;
						keyfile = "custMpk.pem";
					};

					dm: ti-dm {
					};
				};

				fdt-0 {
					description = BOARD_DESCRIPTION;
					type = "flat_dt";
					arch = "arm";
					compression = "none";

					ti-secure {
						content = <&spl_board_dtb>;
						keyfile = "custMpk.pem";
					};

					spl_board_dtb: blob-ext {
						filename = SPL_BOARD_DTB;
					};

				};
			};

			configurations {
				default = "conf-0";

				conf-0 {
					description = BOARD_DESCRIPTION;
					firmware = "atf";
					loadables = "tee", "dm", "spl";
					fdt = "fdt-0";
				};
			};
		};
	};
};

&binman {
	u_boot: template-13 {
		insert-template = <&u_boot_template>;

		fit {
			images {
				uboot {
					description = UBOOT_BOARD_DESCRIPTION;
				};

				fdt-0 {
					description = BOARD_DESCRIPTION;
					type = "flat_dt";
					arch = "arm";
					compression = "none";

					ti-secure {
						content = <&j784s4_evm_dtb>;
						keyfile = "custMpk.pem";
					};

					j784s4_evm_dtb: blob-ext {
						filename = "u-boot.dtb";
					};

					hash {
						algo = "crc32";
					};
				};
			};

			configurations {
				default = "conf-0";

				conf-0 {
					description = BOARD_DESCRIPTION;
					firmware = "uboot";
					loadables = "uboot";
					fdt = "fdt-0";
				};
			};
		};
	};
};

&binman {
	ti_spl_unsigned: template-14 {
		insert-template = <&ti_spl_unsigned_template>;

		fit {
			images {
				dm {
					ti-dm {
					};
				};

				fdt-0 {
					description = BOARD_DESCRIPTION;
					type = "flat_dt";
					arch = "arm";
					compression = "none";

					spl_j784s4_evm_dtb_unsigned: blob {
						filename = SPL_BOARD_DTB;
					};
				};
			};

			configurations {
				default = "conf-0";

				conf-0 {
					description = BOARD_DESCRIPTION;
					firmware = "atf";
					loadables = "tee", "dm", "spl";
					fdt = "fdt-0";
				};
			};
		};
	};
};

&binman {
	u_boot_unsigned: template-15 {
		insert-template = <&u_boot_unsigned_template>;

		fit {
			images {
				uboot {
					description = UBOOT_BOARD_DESCRIPTION;
				};

				fdt-0 {
					description = BOARD_DESCRIPTION;
					type = "flat_dt";
					arch = "arm";
					compression = "none";

					j784s4_evm_dtb_unsigned: blob {
						filename = "u-boot.dtb";
					};

					hash {
						algo = "crc32";
					};
				};
			};

			configurations {
				default = "conf-0";

				conf-0 {
					description = BOARD_DESCRIPTION;
					firmware = "uboot";
					loadables = "uboot";
					fdt = "fdt-0";
				};
			};
		};
	};
};
#endif
