xref: /OK3568_Linux_fs/u-boot/arch/arm/mach-tegra/tegra20/warmboot.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2010 - 2011
3*4882a593Smuzhiyun  * NVIDIA Corporation <www.nvidia.com>
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include <common.h>
9*4882a593Smuzhiyun #include <asm/io.h>
10*4882a593Smuzhiyun #include <linux/errno.h>
11*4882a593Smuzhiyun #include <asm/arch/clock.h>
12*4882a593Smuzhiyun #include <asm/arch/emc.h>
13*4882a593Smuzhiyun #include <asm/arch/gp_padctrl.h>
14*4882a593Smuzhiyun #include <asm/arch/pinmux.h>
15*4882a593Smuzhiyun #include <asm/arch/sdram_param.h>
16*4882a593Smuzhiyun #include <asm/arch/tegra.h>
17*4882a593Smuzhiyun #include <asm/arch-tegra/ap.h>
18*4882a593Smuzhiyun #include <asm/arch-tegra/apb_misc.h>
19*4882a593Smuzhiyun #include <asm/arch-tegra/clk_rst.h>
20*4882a593Smuzhiyun #include <asm/arch-tegra/pmc.h>
21*4882a593Smuzhiyun #include <asm/arch-tegra/fuse.h>
22*4882a593Smuzhiyun #include <asm/arch-tegra/warmboot.h>
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #ifndef CONFIG_TEGRA_CLOCK_SCALING
27*4882a593Smuzhiyun #error "You must enable CONFIG_TEGRA_CLOCK_SCALING to use CONFIG_TEGRA_LP0"
28*4882a593Smuzhiyun #endif
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun  * This is the place in SRAM where the SDRAM parameters are stored. There
32*4882a593Smuzhiyun  * are 4 blocks, one for each RAM code
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun #define SDRAM_PARAMS_BASE	(NV_PA_BASE_SRAM + 0x188)
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* TODO: If we later add support for the Misc GP controller, refactor this */
37*4882a593Smuzhiyun union xm2cfga_reg {
38*4882a593Smuzhiyun 	struct {
39*4882a593Smuzhiyun 		u32 reserved0:2;
40*4882a593Smuzhiyun 		u32 hsm_en:1;
41*4882a593Smuzhiyun 		u32 reserved1:2;
42*4882a593Smuzhiyun 		u32 preemp_en:1;
43*4882a593Smuzhiyun 		u32 vref_en:1;
44*4882a593Smuzhiyun 		u32 reserved2:5;
45*4882a593Smuzhiyun 		u32 cal_drvdn:5;
46*4882a593Smuzhiyun 		u32 reserved3:3;
47*4882a593Smuzhiyun 		u32 cal_drvup:5;
48*4882a593Smuzhiyun 		u32 reserved4:3;
49*4882a593Smuzhiyun 		u32 cal_drvdn_slwr:2;
50*4882a593Smuzhiyun 		u32 cal_drvup_slwf:2;
51*4882a593Smuzhiyun 	};
52*4882a593Smuzhiyun 	u32 word;
53*4882a593Smuzhiyun };
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun union xm2cfgd_reg {
56*4882a593Smuzhiyun 	struct {
57*4882a593Smuzhiyun 		u32 reserved0:2;
58*4882a593Smuzhiyun 		u32 hsm_en:1;
59*4882a593Smuzhiyun 		u32 schmt_en:1;
60*4882a593Smuzhiyun 		u32 lpmd:2;
61*4882a593Smuzhiyun 		u32 vref_en:1;
62*4882a593Smuzhiyun 		u32 reserved1:5;
63*4882a593Smuzhiyun 		u32 cal_drvdn:5;
64*4882a593Smuzhiyun 		u32 reserved2:3;
65*4882a593Smuzhiyun 		u32 cal_drvup:5;
66*4882a593Smuzhiyun 		u32 reserved3:3;
67*4882a593Smuzhiyun 		u32 cal_drvdn_slwr:2;
68*4882a593Smuzhiyun 		u32 cal_drvup_slwf:2;
69*4882a593Smuzhiyun 	};
70*4882a593Smuzhiyun 	u32 word;
71*4882a593Smuzhiyun };
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /*
74*4882a593Smuzhiyun  * TODO: This register is not documented in the TRM yet. We could move this
75*4882a593Smuzhiyun  * into the EMC and give it a proper interface, but not while it is
76*4882a593Smuzhiyun  * undocumented.
77*4882a593Smuzhiyun  */
78*4882a593Smuzhiyun union fbio_spare_reg {
79*4882a593Smuzhiyun 	struct {
80*4882a593Smuzhiyun 		u32 reserved:24;
81*4882a593Smuzhiyun 		u32 cfg_wb0:8;
82*4882a593Smuzhiyun 	};
83*4882a593Smuzhiyun 	u32 word;
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /* We pack the resume information into these unions for later */
87*4882a593Smuzhiyun union scratch2_reg {
88*4882a593Smuzhiyun 	struct {
89*4882a593Smuzhiyun 		u32 pllm_base_divm:5;
90*4882a593Smuzhiyun 		u32 pllm_base_divn:10;
91*4882a593Smuzhiyun 		u32 pllm_base_divp:3;
92*4882a593Smuzhiyun 		u32 pllm_misc_lfcon:4;
93*4882a593Smuzhiyun 		u32 pllm_misc_cpcon:4;
94*4882a593Smuzhiyun 		u32 gp_xm2cfga_padctrl_preemp:1;
95*4882a593Smuzhiyun 		u32 gp_xm2cfgd_padctrl_schmt:1;
96*4882a593Smuzhiyun 		u32 osc_ctrl_xobp:1;
97*4882a593Smuzhiyun 		u32 memory_type:3;
98*4882a593Smuzhiyun 	};
99*4882a593Smuzhiyun 	u32 word;
100*4882a593Smuzhiyun };
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun union scratch4_reg {
103*4882a593Smuzhiyun 	struct {
104*4882a593Smuzhiyun 		u32 emc_clock_divider:8;
105*4882a593Smuzhiyun 		u32 pllm_stable_time:8;
106*4882a593Smuzhiyun 		u32 pllx_stable_time:8;
107*4882a593Smuzhiyun 		u32 emc_fbio_spare_cfg_wb0:8;
108*4882a593Smuzhiyun 	};
109*4882a593Smuzhiyun 	u32 word;
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun union scratch24_reg {
113*4882a593Smuzhiyun 	struct {
114*4882a593Smuzhiyun 		u32 emc_auto_cal_wait:8;
115*4882a593Smuzhiyun 		u32 emc_pin_program_wait:8;
116*4882a593Smuzhiyun 		u32 warmboot_wait:8;
117*4882a593Smuzhiyun 		u32 reserved:8;
118*4882a593Smuzhiyun 	};
119*4882a593Smuzhiyun 	u32 word;
120*4882a593Smuzhiyun };
121*4882a593Smuzhiyun 
warmboot_save_sdram_params(void)122*4882a593Smuzhiyun int warmboot_save_sdram_params(void)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun 	u32 ram_code;
125*4882a593Smuzhiyun 	struct sdram_params sdram;
126*4882a593Smuzhiyun 	struct apb_misc_pp_ctlr *apb_misc =
127*4882a593Smuzhiyun 				(struct apb_misc_pp_ctlr *)NV_PA_APB_MISC_BASE;
128*4882a593Smuzhiyun 	struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
129*4882a593Smuzhiyun 	struct apb_misc_gp_ctlr *gp =
130*4882a593Smuzhiyun 			(struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
131*4882a593Smuzhiyun 	struct emc_ctlr *emc = emc_get_controller(gd->fdt_blob);
132*4882a593Smuzhiyun 	union scratch2_reg scratch2;
133*4882a593Smuzhiyun 	union scratch4_reg scratch4;
134*4882a593Smuzhiyun 	union scratch24_reg scratch24;
135*4882a593Smuzhiyun 	union xm2cfga_reg xm2cfga;
136*4882a593Smuzhiyun 	union xm2cfgd_reg xm2cfgd;
137*4882a593Smuzhiyun 	union fbio_spare_reg fbio_spare;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun 	/* get ram code that is used as index to array sdram_params in BCT */
140*4882a593Smuzhiyun 	ram_code = (readl(&apb_misc->strapping_opt_a) >>
141*4882a593Smuzhiyun 			  STRAP_OPT_A_RAM_CODE_SHIFT) & 3;
142*4882a593Smuzhiyun 	memcpy(&sdram,
143*4882a593Smuzhiyun 	       (char *)((struct sdram_params *)SDRAM_PARAMS_BASE + ram_code),
144*4882a593Smuzhiyun 	       sizeof(sdram));
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	xm2cfga.word = readl(&gp->xm2cfga);
147*4882a593Smuzhiyun 	xm2cfgd.word = readl(&gp->xm2cfgd);
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun 	scratch2.word = 0;
150*4882a593Smuzhiyun 	scratch2.osc_ctrl_xobp = clock_get_osc_bypass();
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	/* Get the memory PLL settings */
153*4882a593Smuzhiyun 	{
154*4882a593Smuzhiyun 		u32 divm, divn, divp, cpcon, lfcon;
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun 		if (clock_ll_read_pll(CLOCK_ID_MEMORY, &divm, &divn, &divp,
157*4882a593Smuzhiyun 					&cpcon, &lfcon))
158*4882a593Smuzhiyun 			return -1;
159*4882a593Smuzhiyun 		scratch2.pllm_base_divm = divm;
160*4882a593Smuzhiyun 		scratch2.pllm_base_divn = divn;
161*4882a593Smuzhiyun 		scratch2.pllm_base_divp = divp;
162*4882a593Smuzhiyun 		scratch2.pllm_misc_cpcon = cpcon;
163*4882a593Smuzhiyun 		scratch2.pllm_misc_lfcon = lfcon;
164*4882a593Smuzhiyun 	}
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	scratch2.gp_xm2cfga_padctrl_preemp = xm2cfga.preemp_en;
167*4882a593Smuzhiyun 	scratch2.gp_xm2cfgd_padctrl_schmt = xm2cfgd.schmt_en;
168*4882a593Smuzhiyun 	scratch2.memory_type = sdram.memory_type;
169*4882a593Smuzhiyun 	writel(scratch2.word, &pmc->pmc_scratch2);
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	/* collect data from various sources for pmc_scratch4 */
172*4882a593Smuzhiyun 	fbio_spare.word = readl(&emc->fbio_spare);
173*4882a593Smuzhiyun 	scratch4.word = 0;
174*4882a593Smuzhiyun 	scratch4.emc_fbio_spare_cfg_wb0 = fbio_spare.cfg_wb0;
175*4882a593Smuzhiyun 	scratch4.emc_clock_divider = sdram.emc_clock_divider;
176*4882a593Smuzhiyun 	scratch4.pllm_stable_time = -1;
177*4882a593Smuzhiyun 	scratch4.pllx_stable_time = -1;
178*4882a593Smuzhiyun 	writel(scratch4.word, &pmc->pmc_scratch4);
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun 	/* collect various data from sdram for pmc_scratch24 */
181*4882a593Smuzhiyun 	scratch24.word = 0;
182*4882a593Smuzhiyun 	scratch24.emc_pin_program_wait = sdram.emc_pin_program_wait;
183*4882a593Smuzhiyun 	scratch24.emc_auto_cal_wait = sdram.emc_auto_cal_wait;
184*4882a593Smuzhiyun 	scratch24.warmboot_wait = sdram.warm_boot_wait;
185*4882a593Smuzhiyun 	writel(scratch24.word, &pmc->pmc_scratch24);
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun 	return 0;
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun 
get_major_version(void)190*4882a593Smuzhiyun static u32 get_major_version(void)
191*4882a593Smuzhiyun {
192*4882a593Smuzhiyun 	u32 major_id;
193*4882a593Smuzhiyun 	struct apb_misc_gp_ctlr *gp =
194*4882a593Smuzhiyun 		(struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	major_id = (readl(&gp->hidrev) & HIDREV_MAJORPREV_MASK) >>
197*4882a593Smuzhiyun 			HIDREV_MAJORPREV_SHIFT;
198*4882a593Smuzhiyun 	return major_id;
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun 
is_production_mode_fuse_set(struct fuse_regs * fuse)201*4882a593Smuzhiyun static int is_production_mode_fuse_set(struct fuse_regs *fuse)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun 	return readl(&fuse->production_mode);
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun 
is_odm_production_mode_fuse_set(struct fuse_regs * fuse)206*4882a593Smuzhiyun static int is_odm_production_mode_fuse_set(struct fuse_regs *fuse)
207*4882a593Smuzhiyun {
208*4882a593Smuzhiyun 	return readl(&fuse->security_mode);
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun 
is_failure_analysis_mode(struct fuse_regs * fuse)211*4882a593Smuzhiyun static int is_failure_analysis_mode(struct fuse_regs *fuse)
212*4882a593Smuzhiyun {
213*4882a593Smuzhiyun 	return readl(&fuse->fa);
214*4882a593Smuzhiyun }
215*4882a593Smuzhiyun 
ap20_is_odm_production_mode(void)216*4882a593Smuzhiyun static int ap20_is_odm_production_mode(void)
217*4882a593Smuzhiyun {
218*4882a593Smuzhiyun 	struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE;
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun 	if (!is_failure_analysis_mode(fuse) &&
221*4882a593Smuzhiyun 	    is_odm_production_mode_fuse_set(fuse))
222*4882a593Smuzhiyun 		return 1;
223*4882a593Smuzhiyun 	else
224*4882a593Smuzhiyun 		return 0;
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun 
ap20_is_production_mode(void)227*4882a593Smuzhiyun static int ap20_is_production_mode(void)
228*4882a593Smuzhiyun {
229*4882a593Smuzhiyun 	struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE;
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun 	if (get_major_version() == 0)
232*4882a593Smuzhiyun 		return 1;
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun 	if (!is_failure_analysis_mode(fuse) &&
235*4882a593Smuzhiyun 	    is_production_mode_fuse_set(fuse) &&
236*4882a593Smuzhiyun 	    !is_odm_production_mode_fuse_set(fuse))
237*4882a593Smuzhiyun 		return 1;
238*4882a593Smuzhiyun 	else
239*4882a593Smuzhiyun 		return 0;
240*4882a593Smuzhiyun }
241*4882a593Smuzhiyun 
fuse_get_operation_mode(void)242*4882a593Smuzhiyun static enum fuse_operating_mode fuse_get_operation_mode(void)
243*4882a593Smuzhiyun {
244*4882a593Smuzhiyun 	u32 chip_id;
245*4882a593Smuzhiyun 	struct apb_misc_gp_ctlr *gp =
246*4882a593Smuzhiyun 		(struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun 	chip_id = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >>
249*4882a593Smuzhiyun 			HIDREV_CHIPID_SHIFT;
250*4882a593Smuzhiyun 	if (chip_id == CHIPID_TEGRA20) {
251*4882a593Smuzhiyun 		if (ap20_is_odm_production_mode()) {
252*4882a593Smuzhiyun 			printf("!! odm_production_mode is not supported !!\n");
253*4882a593Smuzhiyun 			return MODE_UNDEFINED;
254*4882a593Smuzhiyun 		} else
255*4882a593Smuzhiyun 			if (ap20_is_production_mode())
256*4882a593Smuzhiyun 				return MODE_PRODUCTION;
257*4882a593Smuzhiyun 			else
258*4882a593Smuzhiyun 				return MODE_UNDEFINED;
259*4882a593Smuzhiyun 	}
260*4882a593Smuzhiyun 	return MODE_UNDEFINED;
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun 
determine_crypto_options(int * is_encrypted,int * is_signed,int * use_zero_key)263*4882a593Smuzhiyun static void determine_crypto_options(int *is_encrypted, int *is_signed,
264*4882a593Smuzhiyun 				     int *use_zero_key)
265*4882a593Smuzhiyun {
266*4882a593Smuzhiyun 	switch (fuse_get_operation_mode()) {
267*4882a593Smuzhiyun 	case MODE_PRODUCTION:
268*4882a593Smuzhiyun 		*is_encrypted = 0;
269*4882a593Smuzhiyun 		*is_signed = 1;
270*4882a593Smuzhiyun 		*use_zero_key = 1;
271*4882a593Smuzhiyun 		break;
272*4882a593Smuzhiyun 	case MODE_UNDEFINED:
273*4882a593Smuzhiyun 	default:
274*4882a593Smuzhiyun 		*is_encrypted = 0;
275*4882a593Smuzhiyun 		*is_signed = 0;
276*4882a593Smuzhiyun 		*use_zero_key  = 0;
277*4882a593Smuzhiyun 		break;
278*4882a593Smuzhiyun 	}
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun 
sign_wb_code(u32 start,u32 length,int use_zero_key)281*4882a593Smuzhiyun static int sign_wb_code(u32 start, u32 length, int use_zero_key)
282*4882a593Smuzhiyun {
283*4882a593Smuzhiyun 	int err;
284*4882a593Smuzhiyun 	u8 *source;		/* Pointer to source */
285*4882a593Smuzhiyun 	u8 *hash;
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun 	/* Calculate AES block parameters. */
288*4882a593Smuzhiyun 	source = (u8 *)(start + offsetof(struct wb_header, random_aes_block));
289*4882a593Smuzhiyun 	length -= offsetof(struct wb_header, random_aes_block);
290*4882a593Smuzhiyun 	hash = (u8 *)(start + offsetof(struct wb_header, hash));
291*4882a593Smuzhiyun 	err = sign_data_block(source, length, hash);
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun 	return err;
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun 
warmboot_prepare_code(u32 seg_address,u32 seg_length)296*4882a593Smuzhiyun int warmboot_prepare_code(u32 seg_address, u32 seg_length)
297*4882a593Smuzhiyun {
298*4882a593Smuzhiyun 	int err = 0;
299*4882a593Smuzhiyun 	u32 length;			/* length of the signed/encrypt code */
300*4882a593Smuzhiyun 	struct wb_header *dst_header;	/* Pointer to dest WB header */
301*4882a593Smuzhiyun 	int is_encrypted;		/* Segment is encrypted */
302*4882a593Smuzhiyun 	int is_signed;			/* Segment is signed */
303*4882a593Smuzhiyun 	int use_zero_key;		/* Use key of all zeros */
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun 	/* Determine crypto options. */
306*4882a593Smuzhiyun 	determine_crypto_options(&is_encrypted, &is_signed, &use_zero_key);
307*4882a593Smuzhiyun 
308*4882a593Smuzhiyun 	/* Get the actual code limits. */
309*4882a593Smuzhiyun 	length = roundup(((u32)wb_end - (u32)wb_start), 16);
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 	/*
312*4882a593Smuzhiyun 	 * The region specified by seg_address must be in SDRAM and must be
313*4882a593Smuzhiyun 	 * nonzero in length.
314*4882a593Smuzhiyun 	 */
315*4882a593Smuzhiyun 	if (seg_length == 0 || seg_address < NV_PA_SDRAM_BASE ||
316*4882a593Smuzhiyun 		seg_address + seg_length >= NV_PA_SDRAM_BASE + gd->ram_size) {
317*4882a593Smuzhiyun 		err = -EFAULT;
318*4882a593Smuzhiyun 		goto fail;
319*4882a593Smuzhiyun 	}
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun 	/* Things must be 16-byte aligned. */
322*4882a593Smuzhiyun 	if ((seg_length & 0xF) || (seg_address & 0xF)) {
323*4882a593Smuzhiyun 		err = -EINVAL;
324*4882a593Smuzhiyun 		goto fail;
325*4882a593Smuzhiyun 	}
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	/* Will the code fit? (destination includes wb_header + wb code) */
328*4882a593Smuzhiyun 	if (seg_length < (length + sizeof(struct wb_header))) {
329*4882a593Smuzhiyun 		err = -EINVAL;
330*4882a593Smuzhiyun 		goto fail;
331*4882a593Smuzhiyun 	}
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun 	dst_header = (struct wb_header *)seg_address;
334*4882a593Smuzhiyun 	memset((char *)dst_header, 0, sizeof(struct wb_header));
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 	/* Populate the random_aes_block as requested. */
337*4882a593Smuzhiyun 	{
338*4882a593Smuzhiyun 		u32 *aes_block = (u32 *)&(dst_header->random_aes_block);
339*4882a593Smuzhiyun 		u32 *end = (u32 *)(((u32)aes_block) +
340*4882a593Smuzhiyun 				   sizeof(dst_header->random_aes_block));
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun 		do {
343*4882a593Smuzhiyun 			*aes_block++ = 0;
344*4882a593Smuzhiyun 		} while (aes_block < end);
345*4882a593Smuzhiyun 	}
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun 	/* Populate the header. */
348*4882a593Smuzhiyun 	dst_header->length_insecure = length + sizeof(struct wb_header);
349*4882a593Smuzhiyun 	dst_header->length_secure = length + sizeof(struct wb_header);
350*4882a593Smuzhiyun 	dst_header->destination = NV_WB_RUN_ADDRESS;
351*4882a593Smuzhiyun 	dst_header->entry_point = NV_WB_RUN_ADDRESS;
352*4882a593Smuzhiyun 	dst_header->code_length = length;
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun 	if (is_encrypted) {
355*4882a593Smuzhiyun 		printf("!!!! Encryption is not supported !!!!\n");
356*4882a593Smuzhiyun 		dst_header->length_insecure = 0;
357*4882a593Smuzhiyun 		err = -EACCES;
358*4882a593Smuzhiyun 		goto fail;
359*4882a593Smuzhiyun 	} else
360*4882a593Smuzhiyun 		/* copy the wb code directly following dst_header. */
361*4882a593Smuzhiyun 		memcpy((char *)(dst_header+1), (char *)wb_start, length);
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun 	if (is_signed)
364*4882a593Smuzhiyun 		err = sign_wb_code(seg_address, dst_header->length_insecure,
365*4882a593Smuzhiyun 				   use_zero_key);
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun fail:
368*4882a593Smuzhiyun 	if (err)
369*4882a593Smuzhiyun 		printf("Warning: warmboot code copy failed (error=%d)\n", err);
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun 	return err;
372*4882a593Smuzhiyun }
373