blob: de13cc0db750a1e06c69a44d164f499f3432aabb [file] [log] [blame]
Bo Lv72d0e902023-01-02 14:27:34 +00001/* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */
2/*
3 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
4 */
5
6#ifndef __AML_MMC_H__
7#define __AML_MMC_H__
8
9#include <common.h>
10#include <mmc.h>
11
12/* bootloader operation */
13#define AML_BL_USER (0x1 << 0)
14#define AML_BL_BOOT0 (0x1 << 1)
15#define AML_BL_BOOT1 (0x1 << 2)
16#define AML_BL_BOOT (0x6)
17#define AML_BL_ALL (0x7)
18
19/** For actually partitions with mask 8 store into bootinfo
20 * name: partition name.
21 * addr: sector addr of the partition
22 * size: sector cont of the partition
23*/
24struct part_property
25{
26 char name[8];
27 uint32_t addr;
28 uint32_t size;
29};
30#define PART_PROPERTY_SIZE sizeof(struct part_property)
31#define BOOTINFO_MAX_PARTITIONS (4)
32#define BOOTINFO_PARTITIONS_SIZE (PART_PROPERTY_SIZE * BOOTINFO_MAX_PARTITIONS)
33
34
35#define VPART_PROPERTY_SIZE sizeof(struct vpart_property)
36struct vpart_property {
37 u32 addr;
38 u32 size;
39};
40
41/*
42 * sizeof(struct storage_emmc_boot_info) is strictly
43 * smaller than or equal to one sector. we will bind
44 * it in one sector with u-boot.bin together and
45 * write into boot loader area.
46 * @rsv_base_addr : the sector address of reserved area
47 * @dtb : the sector address and size of dtb property
48 * @ddr : the sector address and size of ddr property
49 */
50#define EMMC_BOOT_INFO_SIZE 512
51struct storage_emmc_boot_info {
52 u32 version;
53 u32 rsv_base_addr;
54 struct vpart_property dtb;
55 struct vpart_property ddr;
56
57 struct part_property parts[BOOTINFO_MAX_PARTITIONS];
58 uint8_t reserved[512 - 2 * VPART_PROPERTY_SIZE - BOOTINFO_PARTITIONS_SIZE - 12];
59 u32 checksum;
60};
61
62int amlmmc_write_bootloader(int dev, int map,
63 unsigned int size, const void *src);
64int amlmmc_erase_bootloader(int dev, int map);
65
66
67/* interface on reserved area. */
68void mmc_write_cali_mattern(void *addr);
69
70/* dtb operation */
71int dtb_write(void *addr);
72
73/* emmc key operation */
74int mmc_key_read(unsigned char *buf,
75 unsigned int size, uint32_t *actual_length);
76int mmc_key_write(unsigned char *buf,
77 unsigned int size, uint32_t *actual_length);
78int mmc_key_erase(void);
79
80/* partition operation */
81int renew_partition_tbl(unsigned char *buffer);
82int find_dev_num_by_partition_name (char const *name);
83
84#ifdef CONFIG_AML_PARTITION
85int emmc_update_mbr(unsigned char *buffer);
86#endif
87
88/*mmc ext_csd register operation*/
89int mmc_get_ext_csd(struct mmc *mmc, u8 *ext_csd);
90int mmc_set_ext_csd(struct mmc *mmc, u8 index, u8 value);
91
92/* mmc caps quirks */
93int emmc_quirks(void);
94#endif /* __AML_MMC_H__ */