mirror of
https://git.codelinaro.org/clo/qsdk/oss/boot/u-boot-2016.git
synced 2025-12-10 07:44:53 +01:00
ARM: qca: mmc protection based on gpt attribute
If readonly bit of gpt attribute is set, power-on write protection will be enabled. Change-Id: I7dd9250fd592988626e889f92f07c6839585eb7d Signed-off-by: Gokul Sriram Palanisamy <gokulsri@codeaurora.org>
This commit is contained in:
parent
201def52b9
commit
735b05f59c
4 changed files with 56 additions and 0 deletions
|
|
@ -16,7 +16,10 @@
|
|||
#include <asm/arch-qca-common/smem.h>
|
||||
#include <asm/arch-qca-common/uart.h>
|
||||
#include <asm/arch-qca-common/gpio.h>
|
||||
#include <memalign.h>
|
||||
#include <fdtdec.h>
|
||||
#include <mmc.h>
|
||||
#include <sdhci.h>
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
|
|
@ -31,6 +34,12 @@ extern int sf_saveenv(void);
|
|||
extern env_t *mmc_env_ptr;
|
||||
extern char *mmc_env_name_spec;
|
||||
extern int mmc_saveenv(void);
|
||||
|
||||
#ifndef CONFIG_SDHCI_SUPPORT
|
||||
extern qca_mmc mmc_host;
|
||||
#else
|
||||
extern struct sdhci_host mmc_host;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
env_t *env_ptr;
|
||||
|
|
@ -222,6 +231,39 @@ int board_early_init_f(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FLASH_PROTECT
|
||||
void board_flash_protect(void)
|
||||
{
|
||||
unsigned int num_part;
|
||||
int i;
|
||||
#ifdef CONFIG_QCA_MMC
|
||||
block_dev_desc_t *mmc_dev;
|
||||
disk_partition_t info;
|
||||
|
||||
mmc_dev = mmc_get_dev(mmc_host.dev_num);
|
||||
if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
|
||||
ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header,
|
||||
gpt_head, 1, mmc_dev->blksz);
|
||||
if (mmc_dev->block_read(mmc_dev->dev,
|
||||
(lbaint_t)GPT_PRIMARY_PARTITION_TABLE_LBA,
|
||||
1, gpt_head) == 1) {
|
||||
num_part = le32_to_cpu(gpt_head->num_partition_entries);
|
||||
for (i = 1; i <= num_part; i++) {
|
||||
if (!get_partition_info_efi(mmc_dev, i, &info)
|
||||
&& info.readonly
|
||||
&& !mmc_write_protect(mmc_host.mmc,
|
||||
info.start,
|
||||
info.size, 1))
|
||||
printf("\"%s\""
|
||||
"-protected MMC partition\n",
|
||||
info.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
int board_late_init(void)
|
||||
{
|
||||
unsigned int machid;
|
||||
|
|
@ -238,6 +280,9 @@ int board_late_init(void)
|
|||
setenv_addr("machid", (void *)machid);
|
||||
gd->bd->bi_arch_number = machid;
|
||||
}
|
||||
#ifdef CONFIG_FLASH_PROTECT
|
||||
board_flash_protect();
|
||||
#endif
|
||||
set_ethmac_addr();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,14 @@ static inline int is_bootable(gpt_entry *p)
|
|||
sizeof(efi_guid_t));
|
||||
}
|
||||
|
||||
static inline int is_readonly(gpt_entry *p)
|
||||
{
|
||||
/* bit 60 of gpt attribute denotes read-only flag */
|
||||
if (p->attributes.raw & ((unsigned long long)1 << 60))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba,
|
||||
lbaint_t lastlba)
|
||||
{
|
||||
|
|
@ -283,6 +291,7 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
|
|||
print_efiname(&gpt_pte[part - 1]));
|
||||
snprintf((char *)info->type, sizeof(info->type), "U-Boot");
|
||||
info->bootable = is_bootable(&gpt_pte[part - 1]);
|
||||
info->readonly = is_readonly(&gpt_pte[part - 1]);
|
||||
#ifdef CONFIG_PARTITION_UUIDS
|
||||
uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid,
|
||||
UUID_STR_FORMAT_GUID);
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ extern loff_t board_env_size;
|
|||
#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE_MAX + (1024 << 10))
|
||||
|
||||
#define CONFIG_ENV_IS_IN_NAND 1
|
||||
#define CONFIG_FLASH_PROTECT
|
||||
|
||||
/* Allow to overwrite serial and ethaddr */
|
||||
#define CONFIG_ENV_OVERWRITE
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ typedef struct disk_partition {
|
|||
#ifdef CONFIG_PARTITION_TYPE_GUID
|
||||
char type_guid[37]; /* type GUID as string, if exists */
|
||||
#endif
|
||||
int readonly; /* read-only flag is set */
|
||||
} disk_partition_t;
|
||||
|
||||
/* Misc _get_dev functions */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue