lib/sw_services/xilloader/src/xloader_cmd.c
static int XLoader_UpdateMultiboot(XPlmi_Cmd *Cmd)
{
	int Status = XST_FAILURE;
	u32 ImageLocation;
	u32 MultiBootVal = XLOADER_DEFAULT_MULTIBOOT_VAL;
	u32 RawBootVal = XLOADER_DEFAULT_RAWBOOT_VAL;
	u8 FlashType;
	PdiSrc_t PdiSrc;

	FlashType = (u8)(Cmd->Payload[XLOADER_CMD_MULTIBOOT_BOOTMODE_INDEX] &
				XLOADER_CMD_MULTIBOOT_FLASHTYPE_MASK);
	PdiSrc = (PdiSrc_t)((Cmd->Payload[XLOADER_CMD_MULTIBOOT_BOOTMODE_INDEX] &
			XLOADER_CMD_MULTIBOOT_PDISRC_MASK) >>
			XLOADER_CMD_MULTIBOOT_PDISRC_SHIFT);
	ImageLocation = Cmd->Payload[XLOADER_CMD_MULTIBOOT_IMG_LOCATION_INDEX];

	if ((PdiSrc == XLOADER_PDI_SRC_SD0) || (PdiSrc == XLOADER_PDI_SRC_SD1)
		|| (PdiSrc == XLOADER_PDI_SRC_SD1_LS)) {
		if (FlashType == XLOADER_FLASHTYPE_RAW) {
			RawBootVal = XLOADER_SD_RAWBOOT_VAL;
		}
		else if (FlashType == XLOADER_FLASHTYPE_FS) {
			RawBootVal = XLOADER_SD_FILE_SYSTEM_VAL;
		}
		else {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported Flash Type\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_MULTIBOOT_FLASH_TYPE;
			goto END;
		}
	}
	else if (PdiSrc == XLOADER_PDI_SRC_EMMC1) {
		if (FlashType == XLOADER_FLASHTYPE_RAW) {
			RawBootVal = XLOADER_SD_RAWBOOT_VAL;
		}
		else if (FlashType == XLOADER_FLASHTYPE_FS) {
			RawBootVal = XLOADER_SD_FILE_SYSTEM_VAL;

		}
		else if (FlashType == XLOADER_FLASHTYPE_RAW_BP1) {
			RawBootVal = XLOADER_EMMC_BP1_RAW_VAL;
		}
		else if (FlashType == XLOADER_FLASHTYPE_RAW_BP2) {
			RawBootVal = XLOADER_EMMC_BP2_RAW_VAL;
		}
		else {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported Flash Type\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_MULTIBOOT_FLASH_TYPE;
			goto END;
		}
	}
	else {
		 if ((PdiSrc != XLOADER_PDI_SRC_QSPI24) &&
			(PdiSrc != XLOADER_PDI_SRC_QSPI32) &&
			(PdiSrc != XLOADER_PDI_SRC_OSPI)) {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported PdiSrc\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_MULTIBOOT_PDISRC;
			goto END;
		}
	}

	if (RawBootVal == XLOADER_SD_FILE_SYSTEM_VAL) {
		if (ImageLocation < XLOADER_SD_MAX_BOOT_FILES_LIMIT) {
			MultiBootVal = ImageLocation;
		}
		else {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported Boot File Num\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_FILE_NUM;
			goto END;
		}
	}
	else {
		if ((ImageLocation % XLOADER_IMAGE_SEARCH_OFFSET) == 0U) {
			MultiBootVal = ImageLocation / XLOADER_IMAGE_SEARCH_OFFSET;
		}
		else {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported Image Location\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_MULTIBOOT_OFFSET;
			goto END;
		}
	}

	MultiBootVal = (RawBootVal & XLOADER_SD_RAWBOOT_MASK) |
			(MultiBootVal & XLOADER_MULTIBOOT_OFFSET_MASK);
	XPlmi_Out32(PMC_GLOBAL_PMC_MULTI_BOOT, MultiBootVal);
	Status = XST_SUCCESS;

END:
	Cmd->Response[XLOADER_RESP_CMD_EXEC_STATUS_INDEX] = (u32)Status;
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function updates multiboot register value during run-time
 *  Command payload parameters are
 *	- BootMode[15:8] - Boot Mode value
 *	- FlashType[3:0] - Type of Flash
 *	- Image Location - Location of Image in the boot device
 *
 * @param	Cmd is pointer to the command structure
 *
 * @return	XST_SUCCESS on success and error code on failure
 *
 *****************************************************************************/


@param       Cmd is pointer to the command structure

@return      XST_SUCCESS on success and error code on failure
@param Cmd is pointer to the command structure @return XST_SUCCESS on success and error code on failure
static int XLoader_UpdateMultiboot(XPlmi_Cmd *Cmd)
{
	int Status = XST_FAILURE;
	u32 ImageLocation;
	u32 MultiBootVal = XLOADER_DEFAULT_MULTIBOOT_VAL;
	u32 RawBootVal = XLOADER_DEFAULT_RAWBOOT_VAL;
	u8 FlashType;
	PdiSrc_t PdiSrc;
	FlashType = (u8)(Cmd->Payload[XLOADER_CMD_MULTIBOOT_BOOTMODE_INDEX] &
				XLOADER_CMD_MULTIBOOT_FLASHTYPE_MASK);
	PdiSrc = (PdiSrc_t)((Cmd->Payload[XLOADER_CMD_MULTIBOOT_BOOTMODE_INDEX] &
			XLOADER_CMD_MULTIBOOT_PDISRC_MASK) >>
			XLOADER_CMD_MULTIBOOT_PDISRC_SHIFT);
	ImageLocation = Cmd->Payload[XLOADER_CMD_MULTIBOOT_IMG_LOCATION_INDEX];
	if ((PdiSrc == XLOADER_PDI_SRC_SD0) || (PdiSrc == XLOADER_PDI_SRC_SD1)
		|| (PdiSrc == XLOADER_PDI_SRC_SD1_LS)) {
		if (FlashType == XLOADER_FLASHTYPE_RAW) {
			RawBootVal = XLOADER_SD_RAWBOOT_VAL;
		}
		else if (FlashType == XLOADER_FLASHTYPE_FS) {
			RawBootVal = XLOADER_SD_FILE_SYSTEM_VAL;
		}
		else {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported Flash Type\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_MULTIBOOT_FLASH_TYPE;
			goto END;
		}
	}
	else if (PdiSrc == XLOADER_PDI_SRC_EMMC1) {
		if (FlashType == XLOADER_FLASHTYPE_RAW) {
			RawBootVal = XLOADER_SD_RAWBOOT_VAL;
		}
		else if (FlashType == XLOADER_FLASHTYPE_FS) {
			RawBootVal = XLOADER_SD_FILE_SYSTEM_VAL;
		}
		else if (FlashType == XLOADER_FLASHTYPE_RAW_BP1) {
			RawBootVal = XLOADER_EMMC_BP1_RAW_VAL;
		}
		else if (FlashType == XLOADER_FLASHTYPE_RAW_BP2) {
			RawBootVal = XLOADER_EMMC_BP2_RAW_VAL;
		}
		else {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported Flash Type\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_MULTIBOOT_FLASH_TYPE;
			goto END;
		}
	}
	else {
		 if ((PdiSrc != XLOADER_PDI_SRC_QSPI24) &&
			(PdiSrc != XLOADER_PDI_SRC_QSPI32) &&
			(PdiSrc != XLOADER_PDI_SRC_OSPI)) {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported PdiSrc\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_MULTIBOOT_PDISRC;
			goto END;
		}
	}
	if (RawBootVal == XLOADER_SD_FILE_SYSTEM_VAL) {
		if (ImageLocation < XLOADER_SD_MAX_BOOT_FILES_LIMIT) {
			MultiBootVal = ImageLocation;
		}
		else {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported Boot File Num\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_FILE_NUM;
			goto END;
		}
	}
	else {
		if ((ImageLocation % XLOADER_IMAGE_SEARCH_OFFSET) == 0U) {
			MultiBootVal = ImageLocation / XLOADER_IMAGE_SEARCH_OFFSET;
		}
		else {
			XPlmi_Printf(DEBUG_GENERAL, "Unsupported Image Location\n");
			Status = (int)XLOADER_ERR_UNSUPPORTED_MULTIBOOT_OFFSET;
			goto END;
		}
	}
	MultiBootVal = (RawBootVal & XLOADER_SD_RAWBOOT_MASK) |
			(MultiBootVal & XLOADER_MULTIBOOT_OFFSET_MASK);
	XPlmi_Out32(PMC_GLOBAL_PMC_MULTI_BOOT, MultiBootVal);
	Status = XST_SUCCESS;
END:
	Cmd->Response[XLOADER_RESP_CMD_EXEC_STATUS_INDEX] = (u32)Status;
	return Status;
}
static int XLoader_UpdateMultiboot ( XPlmi_Cmd * Cmd ) { int Status = XST_FAILURE ; u32 ImageLocation ; u32 MultiBootVal = XLOADER_DEFAULT_MULTIBOOT_VAL ; u32 RawBootVal = XLOADER_DEFAULT_RAWBOOT_VAL ; u8 FlashType ; PdiSrc_t PdiSrc ; FlashType = ( u8 ) ( Cmd -> Payload [ XLOADER_CMD_MULTIBOOT_BOOTMODE_INDEX ] & XLOADER_CMD_MULTIBOOT_FLASHTYPE_MASK ) ; PdiSrc = ( PdiSrc_t ) ( ( Cmd -> Payload [ XLOADER_CMD_MULTIBOOT_BOOTMODE_INDEX ] & XLOADER_CMD_MULTIBOOT_PDISRC_MASK ) >> XLOADER_CMD_MULTIBOOT_PDISRC_SHIFT ) ; ImageLocation = Cmd -> Payload [ XLOADER_CMD_MULTIBOOT_IMG_LOCATION_INDEX ] ; if ( ( PdiSrc == XLOADER_PDI_SRC_SD0 ) || ( PdiSrc == XLOADER_PDI_SRC_SD1 ) || ( PdiSrc == XLOADER_PDI_SRC_SD1_LS ) ) { if ( FlashType == XLOADER_FLASHTYPE_RAW ) { RawBootVal = XLOADER_SD_RAWBOOT_VAL ; } else if ( FlashType == XLOADER_FLASHTYPE_FS ) { RawBootVal = XLOADER_SD_FILE_SYSTEM_VAL ; } else { XPlmi_Printf ( DEBUG_GENERAL , " \n " ) ; Status = ( int ) XLOADER_ERR_UNSUPPORTED_MULTIBOOT_FLASH_TYPE ; goto END ; } } else if ( PdiSrc == XLOADER_PDI_SRC_EMMC1 ) { if ( FlashType == XLOADER_FLASHTYPE_RAW ) { RawBootVal = XLOADER_SD_RAWBOOT_VAL ; } else if ( FlashType == XLOADER_FLASHTYPE_FS ) { RawBootVal = XLOADER_SD_FILE_SYSTEM_VAL ; } else if ( FlashType == XLOADER_FLASHTYPE_RAW_BP1 ) { RawBootVal = XLOADER_EMMC_BP1_RAW_VAL ; } else if ( FlashType == XLOADER_FLASHTYPE_RAW_BP2 ) { RawBootVal = XLOADER_EMMC_BP2_RAW_VAL ; } else { XPlmi_Printf ( DEBUG_GENERAL , " \n " ) ; Status = ( int ) XLOADER_ERR_UNSUPPORTED_MULTIBOOT_FLASH_TYPE ; goto END ; } } else { if ( ( PdiSrc != XLOADER_PDI_SRC_QSPI24 ) && ( PdiSrc != XLOADER_PDI_SRC_QSPI32 ) && ( PdiSrc != XLOADER_PDI_SRC_OSPI ) ) { XPlmi_Printf ( DEBUG_GENERAL , " \n " ) ; Status = ( int ) XLOADER_ERR_UNSUPPORTED_MULTIBOOT_PDISRC ; goto END ; } } if ( RawBootVal == XLOADER_SD_FILE_SYSTEM_VAL ) { if ( ImageLocation < XLOADER_SD_MAX_BOOT_FILES_LIMIT ) { MultiBootVal = ImageLocation ; } else { XPlmi_Printf ( DEBUG_GENERAL , " \n " ) ; Status = ( int ) XLOADER_ERR_UNSUPPORTED_FILE_NUM ; goto END ; } } else { if ( ( ImageLocation % XLOADER_IMAGE_SEARCH_OFFSET ) == 0U ) { MultiBootVal = ImageLocation / XLOADER_IMAGE_SEARCH_OFFSET ; } else { XPlmi_Printf ( DEBUG_GENERAL , " \n " ) ; Status = ( int ) XLOADER_ERR_UNSUPPORTED_MULTIBOOT_OFFSET ; goto END ; } } MultiBootVal = ( RawBootVal & XLOADER_SD_RAWBOOT_MASK ) | ( MultiBootVal & XLOADER_MULTIBOOT_OFFSET_MASK ) ; XPlmi_Out32 ( PMC_GLOBAL_PMC_MULTI_BOOT , MultiBootVal ) ; Status = XST_SUCCESS ; END : Cmd -> Response [ XLOADER_RESP_CMD_EXEC_STATUS_INDEX ] = ( u32 ) Status ; return Status ; }
@brief       This function updates multiboot register value during run-time
  Command payload parameters are
      - BootMode[15:8] - Boot Mode value
      - FlashType[3:0] - Type of Flash
      - Image Location - Location of Image in the boot device
@brief This function updates multiboot register value during run - time Command payload parameters are - BootMode [ 15 : 8 ] - Boot Mode value - FlashType [ 3 : 0 ] - Type of Flash - Image Location - Location of Image in the boot device