Skip to content

Commit

Permalink
Store env on the boot device (eMMC/SDCard)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzyitc committed Oct 28, 2022
1 parent a3db680 commit 0038d74
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
6 changes: 5 additions & 1 deletion arch/arm/lib/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <asm/cache.h>

#include <asm/arch/reboot.h>
#include <asm/arch/romboot.h>
#include <partition_table.h>


Expand Down Expand Up @@ -534,7 +535,10 @@ unsigned int emmc_init(void)
{
int ret = -1;
struct mmc *mmc = NULL;
mmc = find_mmc_device(1);
if(C_ROM_BOOT_DEBUG->boot_id != 1) // boot from eMMC or USB
mmc = find_mmc_device(1);
else // boot from SDCard
mmc = find_mmc_device(0);
if (mmc) {
ret = mmc_init(mmc); // init eMMC/tSD+
}
Expand Down
11 changes: 11 additions & 0 deletions drivers/mmc/aml_sd_mmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <malloc.h>
#include <asm/dma-mapping.h>
#include <asm/arch/io.h>
#include <asm/arch/romboot.h>
#include <asm/arch/sdio.h>
#include <mmc.h>

Expand Down Expand Up @@ -819,3 +820,13 @@ bool aml_is_emmc_tsd (struct mmc *mmc) // is eMMC OR TSD

return ((sdio->sdio_port == SDIO_PORT_C) || (sdio->sdio_port == SDIO_PORT_XC_C));
}

bool aml_is_boot_device(struct mmc *mmc) // is boot device
{
struct aml_card_sd_info * sdio=mmc->priv;

if(C_ROM_BOOT_DEBUG->boot_id != 1) // boot from eMMC or USB
return ((sdio->sdio_port == SDIO_PORT_C) || (sdio->sdio_port == SDIO_PORT_XC_C));
else // boot from SDCard
return ((sdio->sdio_port == SDIO_PORT_B) || (sdio->sdio_port == SDIO_PORT_XC_B));
}
29 changes: 15 additions & 14 deletions drivers/mmc/emmc_partitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <malloc.h>
#include <asm/dma-mapping.h>
#include <asm/arch/io.h>
#include <asm/arch/romboot.h>
#include <asm/arch/sdio.h>
#include <mmc.h>
#include <linux/err.h>
Expand All @@ -10,7 +11,7 @@
extern struct partitions *part_table;
struct mmc_config * mmc_config_of =NULL;
bool is_partition_checked = false;
extern struct mmc *find_mmc_device_by_port (unsigned sdio_port);
extern struct mmc *find_mmc_device_by_port (unsigned sdio_port);

#define PARTITION_ELEMENT(na, sz, flags) {.name = na, .size = sz, .mask_flags = flags,}
struct partitions emmc_partition_table[]={
Expand Down Expand Up @@ -210,7 +211,7 @@ int mmc_get_partition_table (struct mmc *mmc)
}
part_num++;
}
strncpy((char *)(mmc_config_of->version), MMC_UBOOT_VERSION, MAX_MMC_PART_NAME_LEN);
strncpy((char *)(mmc_config_of->version), MMC_UBOOT_VERSION, MAX_MMC_PART_NAME_LEN);
mmc_config_of->part_num = part_num + 1;
mmc_config_of->private_data = mmc;

Expand Down Expand Up @@ -246,7 +247,7 @@ int mmc_partition_tbl_checksum_calc (struct partitions *part, int part_num)

int mmc_write_partition_tbl (struct mmc *mmc, struct mmc_config *mmc_cfg, struct mmc_partitions_fmt *pt_fmt)
{
int ret=0, start_blk, size, blk_cnt=0;
int ret=0, start_blk, size, blk_cnt=0;
char *buf, *src;
struct partitions *pp;

Expand Down Expand Up @@ -315,7 +316,7 @@ int mmc_write_partition_tbl (struct mmc *mmc, struct mmc_config *mmc_cfg, struct

int mmc_read_partition_tbl (struct mmc *mmc, struct mmc_partitions_fmt *pt_fmt)
{
int ret=0, start_blk, size, blk_cnt=0;
int ret=0, start_blk, size, blk_cnt=0;
char *buf, *dst;
struct partitions *pp;

Expand Down Expand Up @@ -397,7 +398,7 @@ int mmc_partition_verify (struct mmc_config * mmc_cfg, struct mmc_partitions_fmt
// printf("version: %s\n", mmc_cfg->version);
// show_mmc_patition(mmc_cfg->partitions, mmc_cfg->part_num);

if ((strncmp((const char *)(mmc_cfg->version), (const char *)(pt_fmt->version), sizeof(pt_fmt->version)) == 0x00)
if ((strncmp((const char *)(mmc_cfg->version), (const char *)(pt_fmt->version), sizeof(pt_fmt->version)) == 0x00)
&& (mmc_cfg->part_num == pt_fmt->part_num)) {
pp1 = mmc_cfg->partitions;
pp2 = pt_fmt->partitions;
Expand Down Expand Up @@ -467,20 +468,20 @@ int find_dev_num_by_partition_name (char *name)
int port=-1, port_xc, dev_num;
struct mmc *mmc;

if (!strncmp(name, MMC_CARD_PARTITION_NAME, sizeof(MMC_CARD_PARTITION_NAME))) { // card
port = SDIO_PORT_B;
port_xc = SDIO_PORT_XC_B;
} else { // eMMC OR TSD
if (find_mmc_partition_by_name(name)) { // partition name is valid
if (find_mmc_partition_by_name(name)) { // partition name is valid
if(C_ROM_BOOT_DEBUG->boot_id != 1) { // boot from eMMC or USB
port = SDIO_PORT_C;
port_xc = SDIO_PORT_XC_C;
} // else port=-1
}
} else { // boot from SDCard
port = SDIO_PORT_B;
port_xc = SDIO_PORT_XC_B;
}
} // else port=-1

if (port > 0) {
mmc = find_mmc_device_by_port((unsigned)port);
mmc = find_mmc_device_by_port((unsigned)port);
if (!mmc) { // not found yet
mmc = find_mmc_device_by_port((unsigned)port_xc);
mmc = find_mmc_device_by_port((unsigned)port_xc);
}

if (!mmc) { // not found
Expand Down
4 changes: 2 additions & 2 deletions drivers/mmc/mmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool emmckey_is_access_range_legal (struct mmc *mmc, ulong start, lbaint_t blkcn
struct aml_emmckey_info_t *emmckey_info;
emmckey_info = mmc->aml_emmckey_info;
#endif
if(aml_is_emmc_tsd(mmc)){
if (aml_is_boot_device(mmc)) { // is boot device

#ifdef CONFIG_STORE_COMPATIBLE
#ifdef CONFIG_SECURITYKEY
Expand Down Expand Up @@ -1385,7 +1385,7 @@ int mmc_init(struct mmc *mmc)
mmc->is_inited = true; // init OK
}

if (aml_is_emmc_tsd(mmc)) { // eMMC OR TSD
if (aml_is_boot_device(mmc)) { // is boot device
#if defined (CONFIG_PARTITIONS_STORE)
if (0 == is_init_partition_flag) {
mmc_device_partitions(mmc);
Expand Down

0 comments on commit 0038d74

Please sign in to comment.