/*
 * Copyright 2023 Sony Corporation
 */

#include <common.h>
#include <utility.h>

#include "boot_impl.h"
#include "sony_fs.h"

#define CACHE_PART_NAME "cache"
#define PANEL_SELF_RUN_FILE "recovery/command"
#define PANEL_SELF_RUN_COMMAND "--panel_self_run"

bool is_panel_self_run(void)
{
	int size;
	char *buf;
	int boot_mode;

	boot_mode = get_boot_mode_flag();
	if (boot_mode != EN_BOOT_MODE_RECOVERY)
		return false;

	size = ext4_f_size(CACHE_PART_NAME, PANEL_SELF_RUN_FILE);
	printf("%s %d file size=%d\n", __func__, __LINE__, size);

	if (size < 0) // file not exist
		return false;

	buf = malloc(size+1);
	if (ext4_f_load(CACHE_PART_NAME, PANEL_SELF_RUN_FILE, buf) > 0) {
		if (strncmp(buf, PANEL_SELF_RUN_COMMAND, 16) == 0)
			return true;
	} else {
		printf("file cannot read\n");
	}
	return false;
}

int is_qhb_custom_condition(void)
{
	if (is_panel_self_run())
		return 1;
	else
		return 0;
}
