blob: 5f362bdd9a06259e2a9e5dc7bf0c7c458310cd32 [file] [log] [blame]
Bo Lv6170c3e2023-04-04 10:56:51 +08001// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
4 */
5
6#include <common.h>
7#include <command.h>
8#include <memalign.h>
9#ifdef CONFIG_HAVE_BLOCK_DEVICE
10extern int get_part_info_from_tbl(struct blk_desc * dev_desc,
11 int part_num, disk_partition_t * info);
12int get_part_info_by_name(struct blk_desc *dev_desc,
13 const char *name, disk_partition_t *info);
14#define AML_PART_DEBUG (0)
15
16#if (AML_PART_DEBUG)
17#define PRINTF(fmt,args...) printf (fmt ,##args)
18#else
19#define PRINTF(fmt,args...)
20#endif
21
22#define AML_SEC_SIZE (512)
23#define MAGIC_OFFSET (1)
24
25/* read back boot partitions */
26static int _get_partition_info_aml(struct blk_desc * dev_desc,
27 int part_num, disk_partition_t * info, int verb)
28{
29 int ret = 0;
30
31 if (IF_TYPE_MMC != dev_desc->if_type)
32 return -1;
33
34 info->blksz=dev_desc->blksz;
35 sprintf ((char *)info->type, "U-Boot");
36 /* using partition name in partition tables */
Bo Lva1bffde2023-08-16 21:04:03 +080037#ifdef CONFIG_MMC
Bo Lv6170c3e2023-04-04 10:56:51 +080038 ret = get_part_info_from_tbl(dev_desc, part_num, info);
Bo Lva1bffde2023-08-16 21:04:03 +080039#else
40 ret = -1;
41#endif
Bo Lv6170c3e2023-04-04 10:56:51 +080042 if (ret) {
43 printf ("** Partition %d not found on device %d **\n",
44 part_num,dev_desc->devnum);
45 return -1;
46 }
47
48 PRINTF(" part %d found @ %lx size %lx\n",part_num,info->start,info->size);
49 return 0;
50}
51
52int get_partition_info_aml(struct blk_desc * dev_desc,
53 int part_num, disk_partition_t * info)
54{
55 return(_get_partition_info_aml(dev_desc, part_num, info, 1));
56}
57
58int get_partition_info_aml_by_name(struct blk_desc *dev_desc,
59 const char *name, disk_partition_t *info)
60{
61 return (get_part_info_by_name(dev_desc,
62 name, info));
63}
64
65void print_part_aml(struct blk_desc * dev_desc)
66{
67 disk_partition_t info;
68 int i;
69 if (_get_partition_info_aml(dev_desc,0,&info,0) == -1) {
70 printf("** No boot partition found on device %d **\n",dev_desc->devnum);
71 return;
72 }
73 printf("Part Start Sect x Size Type name\n");
74 i=0;
75 do {
76 printf(" %02d " LBAFU " " LBAFU " %6ld %.32s %.32s\n",
77 i++, info.start, info.size, info.blksz, info.type, info.name);
78 } while (_get_partition_info_aml(dev_desc,i,&info,0)!=-1);
79}
80#define AML_MPT_OFFSET (73728) /* 36M */
81/* fix 40Mbyte to check the MPT magic */
82int test_part_aml (struct blk_desc *dev_desc)
83{
84 ALLOC_CACHE_ALIGN_BUFFER(char, buffer, dev_desc->blksz);
85 if (blk_dread(dev_desc, AML_MPT_OFFSET, 1, (ulong *) buffer) != 1)
86 return -1;
87 if (!strncmp(buffer, "MPT", 3))
88 return 0;
89 return 1;
90}
91
92
93U_BOOT_PART_TYPE(aml) = {
94 .name = "AML",
95 .part_type = PART_TYPE_AML,
96 .max_entries = AML_ENTRY_NUMBERS,
97 .get_info = get_partition_info_aml,
98 .print = print_part_aml,
99 .test = test_part_aml,
100};
101
102
103#endif