blob: 3da7c262a3fcb4c9c2c3e487f650dfc27527b78b [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#include <common.h>
2#include <malloc.h>
3#include "tim.h"
4#include "asr_common.h"
5#include "obm2osl.h"
6#include <asm/io.h>
7#include <asm/arch/cpu.h>
8#ifdef CONFIG_LZMA
9#include <lzma/LzmaTypes.h>
10#include <lzma/LzmaDec.h>
11#include <lzma/LzmaTools.h>
12#endif /* CONFIG_LZMA */
13
14DECLARE_GLOBAL_DATA_PTR;
15
16/* set none-zero data to put it into data sesction */
17static struct asr_mflag *asr_mflag_g = 0xFFFFFFFF;
18
19u32 get_mem_size_bytes(void)
20{
21 int i;
22 u32 ram_size = 0;
23
24 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
25 ram_size += gd->bd->bi_dram[i].size;
26 }
27
28 return ram_size;
29}
30
31static pTIM pdtim_primary = NULL;
32
33#ifdef CONFIG_NSAID_MEM_IOSLATE
34static u32 nsaid_ddr_range_idx = 0;
35
36void nsaid_config_one_range(struct nsaid_range_desc *desc)
37{
38 u32 value;
39
40 value = readl(DDR_RANGE_ACCESS_CTRL);
41 value &= ~(0x1 << 9);
42 writel(value, DDR_RANGE_ACCESS_CTRL);
43
44 writel(/*(0x1 << 3) | (0x0 << 1) | (0x0 << 4) | (0x1 << 6)
45 | */(desc->buff_start & 0xfffff000),
46 (DDR_RANGE0_LOW_CFG + (8 * nsaid_ddr_range_idx)));
47 writel(((desc->buff_end) & 0xfffff000),
48 (DDR_RANGE0_TOP_LOW_CFG + (8 * nsaid_ddr_range_idx)));
49
50 value = readl(DDR_RANGE0_LOW_CFG + (8 * nsaid_ddr_range_idx));
51 value |= 0x1;
52 printf("R%d-reg0x%x: 0x%x ", nsaid_ddr_range_idx, (DDR_RANGE0_LOW_CFG + (8 * nsaid_ddr_range_idx)), value);
53 writel(value, (DDR_RANGE0_LOW_CFG + (8 * nsaid_ddr_range_idx)));
54 printf("buf[0x%x 0x%x] ", desc->buff_start, desc->buff_end);
55
56 value = desc->perm_desc.value;
57 writel(value, (DDR_RANGE0_MASK_CFG + (nsaid_ddr_range_idx * 4)));
58 printf("perm: 0x%x\n", value);
59
60 nsaid_ddr_range_idx++;
61}
62
63void nsaid_basic_init(void)
64{
65 int i;
66 u32 val;
67
68 /*allow r/w on all ranges/masters */
69 for (i = 0; i < 0x10; i++)
70 writel(0x0, (DDR_RANGE0_MASK_CFG + (i * 4)));
71
72 for (i = 0; i < 0x20; i++)
73 writel(0x0, (DDR_RANGE0_LOW_CFG + (i * 4)));
74
75 for (i = 0; i < 0x20; i++)
76 writel(0x0, (DDR_RANGE0_TOP_LOW_CFG + (i * 4)));
77
78 /* set nsaid for master ports, CIU + 0x150
79 * [0 - 3]: CR7
80 * [4 - 7]: DTC
81 * [8 -11]: BX2U1
82 * [12-15]: BX2U0
83 * [16-19]: BX2C
84 * [20-23]: MSA
85 * [24-27]: 4GM
86 * [28-31]: 5GM
87 */
88 val = (0x1 << 0)
89 | (0x2 << 4)
90 | (0x3 << 8)
91 | (0x4 << 12)
92 | (0x5 << 16)
93 | (0x6 << 20)
94 | (0x7 << 24)
95 | (0x8 << 28);
96 asr_ciu_write(CIU_NSAID_SETTING0, val);
97
98 /* set nsaid for master ports, CIU + 0x150
99 * [0 - 3]: CA7
100 * [4 - 7]: TOE
101 * [8 -11]: PCIE0
102 * [12-15]: PCIE1
103 * [16-19]: HSDMA
104 * [20-23]: AP FAB
105 * [24-27]: MFC
106 * [31]: AP_FAB_L2_EN
107 */
108 val = (0x0 << 0)
109 | (0x9 << 4)
110 | (0xA << 8)
111 | (0xB << 12)
112 | (0xC << 16)
113 | (0xD << 20)
114 | (0xE << 24);
115 asr_ciu_write(CIU_NSAID_SETTING1, val);
116
117 printf("adc_err_info: 0x%x 0x%x 0x%x 0x%x\n",
118 readl(DDR_ADC_ERR_INFO + 0),
119 readl(DDR_ADC_ERR_INFO + 4),
120 readl(DDR_ADC_ERR_INFO + 8),
121 readl(DDR_ADC_ERR_INFO + 0xc));
122
123 /* clear error */
124 writel(readl(DDR_ADC_ERR_INFO + 0) | (0x1 << 24),
125 (DDR_ADC_ERR_INFO + 0));
126 printf("nsaid begin\n");
127}
128#endif
129
130char *image_id_to_string(unsigned int id)
131{
132 static char str[5];
133 memset(str, 0, sizeof(str));
134 str[0] = (id >> 24) & 0xff;
135 str[1] = (id >> 16) & 0xff;
136 str[2] = (id >> 8) & 0xff;
137 str[3] = id & 0xff;
138 return str;
139}
140
141void asr_free_dtim_primary(void)
142{
143 if (pdtim_primary) {
144 free(pdtim_primary);
145 pdtim_primary = NULL;
146 }
147}
148
149pTIM asr_get_dtim_primary(void)
150{
151 pTIM ptim = NULL;
152 pTIM pdtim = NULL;
153 int ret = 0;
154 struct OBM2OSL *params = NULL;
155 unsigned char *tim_addr;
156 unsigned int flash_addr = DTIM_PRI_FLASH_OFFSET;
157
158 if(pdtim_primary)
159 return pdtim_primary;
160
161 pdtim = malloc(sizeof(struct TIM));
162 if(pdtim == NULL)
163 {
164 return 0;
165 }
166
167 tim_addr = malloc(DTIM_PRI_FLASH_LEN);
168 if(tim_addr == NULL)
169 {
170 free(pdtim);
171 return 0;
172 }
173
174#ifdef CONFIG_AB_SYSTEM
175 flash_addr = ab_get_image_offset(DTIM_PRIMARY);
176#else
177 ptim = asr_read_tim();
178 if (ptim)
179 flash_addr = get_image_offset_in_tim(ptim, DTIM_PRIMARY, PrimaryImage);
180#endif
181 flash_read(tim_addr, flash_addr, DTIM_PRI_FLASH_LEN);
182
183 /* dtim itself must be validated in OBM */
184 ret = set_tim_pointers(tim_addr, pdtim);
185
186 if (ptim) {
187 ret = verify_dtim(pdtim, ptim);
188 }
189
190 if(ret == 0){
191 pdtim_primary = pdtim;
192 return pdtim;
193 }
194
195 /* If no DTIM.Primary found, free the buffers */
196 free(pdtim);
197 free(tim_addr);
198 return 0;
199}
200
201/*
202* In current design, kernel/CP/MSA/RF image is included in DTIM.Primary or not.
203* If it's included in DTIM.Primay and it's load address is not 0xFFFFFFFF, it's
204* loaded by OBM, then U-boot don't need to load it any more.
205*/
206int image_load_by_obm(unsigned int image_id)
207{
208 unsigned int tim_addr;
209 struct TIM* p_dtim = NULL;
210 struct IMAGE_INFO_3_4_0 * pimg;
211
212 p_dtim = asr_get_dtim_primary();
213 if(p_dtim == NULL)
214 return 0;
215
216 pimg = find_image_intim(p_dtim, DTIM_TIM_VER_3_4_0, image_id);
217 if(pimg == NULL)
218 return 0;
219
220#ifdef CONFIG_ASR_SDTIM
221 if(image_is_stdim_included(pimg)) {
222 /* to simplify the design, uboot loads all the sdtim included
223 * images except itself.
224 */
225 return 0;
226 }
227#endif
228
229 if(pimg && pimg->load_addr != 0xffffffff)
230 return 1;
231
232 return 0;
233}
234#define LZMA_HEADER 0x5D
235int asr_load_dtim_image(unsigned int load_addr, struct TIM* p_dtim,
236 unsigned int image_id, int validate)
237{
238 int ret = 0;
239 struct IMAGE_INFO_3_4_0 * pimg = NULL;
240 unsigned int offset = 0;
241#ifdef CONFIG_ASR_SDTIM
242 struct IMAGE_INFO_3_4_0 * psdtim_img = NULL;
243 struct IMAGE_INFO_3_4_0 * pimg_in_sdtim = NULL;
244 struct TIM* p_sdtim = NULL;
245 char *sdtim_buf = NULL;
246 unsigned int sdtim_space_size = SDTIM_MAX_SIZE;
247 unsigned int sec_cfg = 0;
248#endif
249 char *rf_h;
250 u32 dict_size;
251#ifdef CONFIG_ASR_RF_LZMA
252 int size;
253 u32 pBuf, tmp_buf;
254#endif
255 if(load_addr == 0 && validate == 0)
256 return 0; /* need to do nothing */
257
258 pimg = find_image_intim(p_dtim, DTIM_TIM_VER_3_4_0, image_id);
259 if(pimg == NULL) {
260 printf("%s is not in DTIM_Primary\n", image_id_to_string(image_id));
261 return 0;
262 }
263
264#ifdef CONFIG_AB_SYSTEM
265 offset = ab_get_image_offset(image_id);
266#else
267 offset = pimg->flash_entryaddr;
268#endif
269
270#ifdef CONFIG_ASR_SDTIM
271 if ( image_is_stdim_included(pimg) ) { /* sdtim enabled */
272 p_sdtim = malloc(sizeof(struct TIM));
273 if(p_sdtim == NULL)
274 return -1;
275
276 sdtim_buf = malloc(sdtim_space_size);
277 if(sdtim_buf == NULL) {
278 free(p_sdtim);
279 return -1;
280 }
281
282 flash_read(sdtim_buf, offset, sdtim_space_size);
283 ret = set_tim_pointers(sdtim_buf, p_sdtim);
284 if(ret) {
285 free(p_sdtim);
286 return -1;
287 }
288
289 psdtim_img = find_image_intim(p_sdtim, DTIM_TIM_VER_3_4_0, SDTIM);
290 if(psdtim_img == NULL)
291 goto sdtim_img_err;
292
293 sdtim_space_size = get_sdtim_space_size(psdtim_img);
294
295 pimg_in_sdtim = find_image_intim(p_sdtim, DTIM_TIM_VER_3_4_0, image_id);
296 if(pimg_in_sdtim == NULL)
297 goto sdtim_img_err;
298
299 offset += sdtim_space_size;
300
301 if (load_addr) {
302 if(image_id == RFBIID) { /* for multi rfbin, decompress */
303 flash_read(load_addr, offset, 0x1000);
304 rf_h = (char *)load_addr;
305 dict_size = (*(rf_h+4)<<24) + (*(rf_h+3)<<16) + (*(rf_h+2)<<8) + (*(rf_h+1));
306 if((*rf_h == LZMA_HEADER) && !(dict_size&(dict_size-1))) { /* NAND use LZMA rfbin */
307#ifdef CONFIG_ASR_RF_LZMA
308 size = CONFIG_ASR_RF_LZMA_DDR_SIZE;
309 tmp_buf = (u32)malloc(CONFIG_ASR_RF_LZMA_DDR_SIZE + 0x20000); //malloc more memory for lzma
310 pBuf = roundup(tmp_buf, 0x100);
311 flash_read((u32)pBuf, (u32)offset, (u32)CONFIG_ASR_RF_LZMA_FLASH_SIZE);
312 lzmaBuffToBuffDecompress((unsigned char *)load_addr, (SizeT *)&size,
313 (u8 *)pBuf, (SizeT )CONFIG_ASR_RF_LZMA_FLASH_SIZE);
314 free(tmp_buf);
315#endif
316 } else { /* NAND use RAW rfbin */
317 flash_read(load_addr, offset, pimg_in_sdtim->image_size_to_hash);
318 }
319 } else {
320 flash_read(load_addr, offset, pimg_in_sdtim->image_size_to_hash);
321 }
322 }
323
324#ifdef CONFIG_AB_SYSTEM
325 sec_cfg = 1; /* AB always validate image */
326#else
327 sec_cfg = get_sdtim_secure_cfg(psdtim_img);
328#endif
329
330#ifdef TRUSTED_BOOT
331 if(validate && sec_cfg) {
332 if (load_addr)
333 ret = validate_image(load_addr, image_id, p_sdtim);
334 else /* just to verify */
335 ret = validate_image_segment(offset, image_id, p_sdtim, flash_read);
336 printf("%s verified, %s, offset: 0x%x, size: 0x%x\n", image_id_to_string(image_id),
337 (ret == 0)?"PASS":"FAIL", offset, pimg_in_sdtim->image_size_to_hash);
338 }
339#endif
340
341sdtim_img_err:
342 if(p_sdtim) free(p_sdtim);
343 if(sdtim_buf) free(sdtim_buf);
344 return ret;
345 }
346#endif
347 if (load_addr) {
348 if(image_id == RFBIID) { /* for multi rfbin, decompress */
349 flash_read(load_addr, offset, 0x1000);
350 rf_h = (char *)load_addr;
351 dict_size = (*(rf_h+4)<<24) + (*(rf_h+3)<<16) + (*(rf_h+2)<<8) + (*(rf_h+1));
352 if((*rf_h == LZMA_HEADER) && !(dict_size&(dict_size-1))) { /* NAND use LZMA rfbin */
353#ifdef CONFIG_ASR_RF_LZMA
354 size = CONFIG_ASR_RF_LZMA_DDR_SIZE;
355 tmp_buf = (u32)malloc(CONFIG_ASR_RF_LZMA_DDR_SIZE + 0x20000); //malloc more memory for lzma
356 pBuf = roundup(tmp_buf, 0x100);
357 flash_read((u32)pBuf, (u32)offset, (u32)CONFIG_ASR_RF_LZMA_FLASH_SIZE);
358 lzmaBuffToBuffDecompress((unsigned char *)load_addr, (SizeT *)&size,
359 (u8 *)pBuf, (SizeT )CONFIG_ASR_RF_LZMA_FLASH_SIZE);
360 free(tmp_buf);
361#endif
362 } else {
363 flash_read(load_addr, offset, pimg->image_size_to_hash);
364 }
365 } else {
366 flash_read(load_addr, offset, pimg->image_size_to_hash);
367 }
368 }
369
370#if TRUSTED_BOOT
371 if(validate) {
372 if (load_addr)
373 ret = validate_image(load_addr, image_id, p_dtim);
374 else /* just to verify */
375 ret = validate_image_segment(offset, image_id, p_dtim, flash_read);
376 printf("%s verified, %s, offset: 0x%x, size: 0x%x\n", image_id_to_string(image_id),
377 (ret == 0)?"PASS":"FAIL", offset, pimg->image_size_to_hash);
378 }
379#endif
380
381 return ret;
382}
383
384int asr_load_verify_kernel(unsigned char load_status, int ramdump_boot)
385{
386 int ret = 0;
387 struct TIM* p_dtim = NULL;
388 int validate = 1;
389
390 /* kernel is already loaded and verified by OBM */
391 if(!load_status)
392 return 0;
393
394 p_dtim = asr_get_dtim_primary();
395 if(p_dtim == NULL) {
396 printf("Get DTIM.Primary error\n\r");
397 return -1;
398 }
399
400#if 0
401 if(ramdump_boot)
402 validate = 0;
403#endif
404
405 if (find_image_intim(p_dtim, DTIM_TIM_VER_3_4_0, ZIMG)) {
406 ret = asr_load_dtim_image(CONFIG_LOADADDR, p_dtim, ZIMG, validate);
407
408 if(ret) {
409#ifndef CONFIG_AB_SYSTEM
410 asr_flag_trust_boot_update(TB_ZIMG_ERROR);
411#endif
412 return ret;
413 }
414 } else {
415 flash_read(CONFIG_LOADADDR, KERNEL_FLASH_OFFSET, KERNEL_SIZE);
416 }
417
418 return 0;
419}
420
421int asr_load_verify_ap_images(struct ap_img_info * ap_imgs, int num)
422{
423 int i = 0;
424 int ret = 0;
425 int validate = 0;
426 struct TIM* p_dtim = NULL;
427 unsigned int load_addr, image_id;
428
429#ifdef TRUSTED_BOOT
430 validate = 1;
431#endif
432
433 p_dtim = asr_get_dtim_primary();
434 if(p_dtim == NULL) {
435 printf("Get DTIM.Primary error\n\r");
436 return -1;
437 }
438
439 for(i = 0; i < num; i++)
440 {
441 image_id = ap_imgs[i].image_id;
442 load_addr = ap_imgs[i].load_addr;
443 ret = asr_load_dtim_image(load_addr, p_dtim, image_id, validate);
444 if(ret) {
445 printf("%s load/verify error\n", image_id_to_string(image_id));
446#ifndef CONFIG_AB_SYSTEM
447 asr_flag_trust_boot_image_error(image_id);
448#endif
449 return ret;
450 }
451 }
452
453 return ret;
454}
455
456int asr_load_verify_cp_images(u32 cpbt_mode, struct cp_img_flash_layout *lwg_layout)
457{
458 int ret;
459 unsigned int arbel_flash_offset;
460 unsigned int msa_flash_offset;
461 unsigned int rf_flash_offset;
462 unsigned int bx2_flash_offset;
463
464 if (lwg_layout == NULL) //ltg_layout could be NULL but lwg_layout couldn't
465 {
466 printf("main cp image layout is NULL\n");
467 return -1;
468 }
469
470 if (lwg_layout)
471 {
472 ret = cp_load_table_init(lwg_layout->arbel_offset);
473 if (ret) {
474#ifndef CONFIG_AB_SYSTEM
475 asr_flag_trust_boot_update(TB_CPHD_ERROR);
476 set_nocp_mode(1);
477#endif
478 goto tb_error;
479 } else {
480 arbel_flash_offset = lwg_layout->arbel_offset;
481 msa_flash_offset = lwg_layout->msa_offset;
482 rf_flash_offset = lwg_layout->rf_offset;
483 bx2_flash_offset = lwg_layout->bx2_offset;
484 goto load_modem;
485 }
486 }
487
488load_modem:
489 if( load_arbel_image(arbel_flash_offset) ||
490 load_msa_image(msa_flash_offset) ||
491 load_rf_image(rf_flash_offset) )
492 goto tb_error;
493
494 if (cpu_is_asr1901() || cpu_is_asr1903() || cpu_is_asr1906()) {
495 if(bx2_flash_offset && load_bx2_image(bx2_flash_offset))
496 goto tb_error;
497 }
498
499#ifdef CONFIG_AB_SYSTEM
500#ifndef CONFIG_ASR_EMMC_BOOT
501#ifdef OEM_DATA_AB_ENABLED
502 mtd_part_add(OEM_DATA_ADDR, OEM_DATA_SIZE, OEM_NVM_UBI_VOLUME);
503 mtd_part_add(NVM_MTD_PART_ADDR, NVM_MTD_PART_SIZE, NVM_MTD_PART);
504 // for print the info
505 run_command("mtdparts", 0);
506#endif
507#endif
508#endif
509
510 asr_platform_update_cp_param(NULL);
511 load_cp_reliable_data(lwg_layout->cp_rd_offset, lwg_layout->cp_rd_bk_offset);
512 load_ap_reliable_data(lwg_layout->ap_rd_offset, lwg_layout->ap_rd_bk_offset);
513 if(lwg_layout->nvm_tbl && lwg_layout->nvm_tbl_size)
514 load_ubifs_nvm_for_cp(lwg_layout->nvm_tbl, lwg_layout->nvm_tbl_size);
515 cp_keysection_data_init();
516 if (!cpbt_mode)
517 asr_cp_release();
518 return 0;
519
520tb_error:
521 return -1;
522}
523
524int asr_get_sim_lock_fuse(void)
525{
526 unsigned aes_clk_res_ctrl;
527 unsigned value = 0;
528
529#ifdef CONFIG_PXA182X
530 aes_clk_res_ctrl = readl(APMU_AES_CLK_RES_CTRL);
531 writel(0x9, APMU_AES_CLK_RES_CTRL); //turn on clock
532 value = readl(GEU_FUSE_VAL_APCFG1);
533 value = (value >> 16) & 1;
534 writel(aes_clk_res_ctrl, APMU_AES_CLK_RES_CTRL);
535#elif defined(CONFIG_ASR1802S)
536 aes_clk_res_ctrl = readl(APMU_AES_CLK_RES_CTRL);
537 writel(0x9, APMU_AES_CLK_RES_CTRL); //turn on clock
538 value = readl(GEU_FUSE_VAL_APCFG1);
539 value &= 1;
540 writel(aes_clk_res_ctrl, APMU_AES_CLK_RES_CTRL);
541#else
542 printf("warning: sim lock fuse read\n"); /* TODO, 1901 */
543#endif
544
545 return value;
546}
547
548#ifdef CONFIG_TEE_OS
549unsigned int asr_get_tos_load_address(void)
550{
551 struct OBM2OSL *params = NULL;
552 struct TIM* ptim = NULL;
553 struct IMAGE_INFO_3_4_0 * pimg;
554 unsigned int addr = 0x2000000;
555
556 ptim = asr_get_dtim_primary();
557
558 if(ptim == NULL)
559 return addr;
560
561 pimg = find_image_intim(ptim, DTIM_TIM_VER_3_4_0, TZSI);
562 if(pimg == NULL) {
563 return addr;
564 }
565
566#ifdef CONFIG_ASR_SDTIM
567 if ( image_is_stdim_included(pimg) ) { /* sdtim enabled */
568 int ret = 0;
569 struct TIM* p_sdtim = NULL;
570 uint8_t *sdtim_buf = NULL;
571 uint32_t offset;
572 p_sdtim = malloc(sizeof(struct TIM));
573 if(p_sdtim == NULL)
574 return addr;
575
576 sdtim_buf = malloc(SDTIM_MAX_SIZE);
577 if(sdtim_buf == NULL) {
578 free(p_sdtim);
579 return addr;
580 }
581
582#ifdef CONFIG_AB_SYSTEM
583 offset = ab_get_image_offset(pimg->imageid);
584#else
585 offset = pimg->flash_entryaddr;
586#endif
587
588 flash_read(sdtim_buf, offset, SDTIM_MAX_SIZE);
589 ret = set_tim_pointers(sdtim_buf, p_sdtim);
590 if(ret)
591 {
592 free(p_sdtim);
593 free(sdtim_buf);
594 return addr;
595 }
596
597 pimg = find_image_intim(p_sdtim, DTIM_TIM_VER_3_4_0, TZSI);
598 if(pimg != NULL)
599 addr = pimg->load_addr;
600 free(p_sdtim);
601 free(sdtim_buf);
602 return addr;
603 }
604#endif
605
606 addr = pimg->load_addr;
607 return addr;
608}
609#endif
610
611
612int get_ramdump_flag_f_apcp(void)
613{
614 unsigned int *ramdump_indicator = (unsigned int *)CONFIG_CRASHKERNEL_INDICATOR;
615 /* returns 1 for ap/cp assert */
616 if ((*ramdump_indicator == 0x454d4d44))
617 return 1;
618 else
619 return 0;
620}
621
622
623int get_ramdump_flag_f(void)
624{
625 unsigned int *ramdump_indicator = (unsigned int *)CONFIG_CRASHKERNEL_INDICATOR;
626 /* returns 0 for cpassert dump to use long malloc buffer */
627 if ((*ramdump_indicator == 0x454d4d44) && (!ramdump_is_cpssert()))
628 return 1;
629 else
630 return 0;
631}
632
633struct asr_mflag *get_asr_mflag(void)
634{
635 asr_mflag_g = (struct asr_mflag *)(CONFIG_CRASHKERNEL_INDICATOR + ASR_MFLAG_OFFSET_FROM_CRASHKERNEL);
636 return asr_mflag_g;
637}
638
639#ifdef CONFIG_CMD_FASTBOOT
640int get_fastboot_flag_f(void)
641{
642 struct asr_mflag *asr_flag = get_asr_mflag();
643 if (asr_flag->fastboot_flag == 0x46415354)
644 return 1;
645 return 0;
646}
647
648int reset_fastboot_flag_f(void)
649{
650 struct asr_mflag *asr_flag = get_asr_mflag();
651 asr_flag->fastboot_flag = 0;
652 flush_cache((unsigned long)&(asr_flag->fastboot_flag),
653 (unsigned long)sizeof(asr_flag->fastboot_flag));
654}
655
656void run_fastboot_cmd(void)
657{
658 if (get_fastboot_flag_f())
659 {
660 printf("Detect FASTBOOT signature!!\n");
661 reset_fastboot_flag_f();
662 setenv("fbenv", "nand0");
663 run_command("fb", 0);
664 }
665}
666#endif
667
668int prepare_ap_diag_buff(u32 buff_st, u32 buff_end)
669{
670 u32 buff_len;
671 struct asr_mflag *mflag = get_asr_mflag();
672
673 printf("diagbf magic: %08x, len: %x, buff[0x%08x, 0x%08x]\n",
674 mflag->diag_buff_magic, mflag->diag_buff_len, buff_st, buff_end);
675 if ((mflag->diag_buff_magic != AP_DIAG_BUF_SET_MAGIC && mflag->diag_buff_magic != AP_DIAG_BUF_SET_MAGIC2)
676 || (!mflag->diag_buff_len)) {
677 return -1;
678 }
679
680 if (buff_st & 0x3fffff) {
681 buff_st += 0x3fffff;
682 buff_st &= 0xffc00000;
683 }
684
685 buff_len = buff_end - buff_st;
686
687#ifdef CONFIG_MAX_DIAG_BUFF_LEN
688 if (buff_len > CONFIG_MAX_DIAG_BUFF_LEN)
689 buff_len = CONFIG_MAX_DIAG_BUFF_LEN;
690#endif
691
692 if (mflag->diag_buff_len > buff_len) {
693 mflag->diag_buff_len = buff_len;
694 if (mflag->diag_buff_len >= (4 * 1024 * 1024))
695 mflag->diag_buff_len = (4 * 1024 * 1024);
696 else if (mflag->diag_buff_len >= (2 * 1024 * 1024))
697 mflag->diag_buff_len = (2 * 1024 * 1024);
698 else
699 mflag->diag_buff_len = (1 * 1024 * 1024);
700 }
701
702 mflag->diag_buff_addr = buff_st;
703 printf("final diag buf: %08x len: %x\n", mflag->diag_buff_addr, mflag->diag_buff_len);
704 memset(mflag->diag_buff_addr, 0x0, mflag->diag_buff_len);
705 return 0;
706}
707