2 * (C) Copyright 2012 Lothar Waßmann <LW@KARO-electronics.de>
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
22 #include <jffs2/load_kernel.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 static int karo_load_part(const char *part, void *addr, size_t len)
29 struct mtd_device *dev;
30 struct part_info *part_info;
33 debug("Initializing mtd_parts\n");
34 ret = mtdparts_init();
38 debug("Trying to find NAND partition '%s'\n", part);
39 ret = find_dev_and_part(part, &dev, &part_num,
42 printf("Failed to find flash partition '%s': %d\n",
47 debug("Found partition '%s': offset=%08x size=%08x\n",
48 part, part_info->offset, part_info->size);
49 if (part_info->size < len) {
50 printf("Warning: partition '%s' smaller than requested size: %u; truncating data to %u byte\n",
51 part, len, part_info->size);
52 len = part_info->size;
54 debug("Reading NAND partition '%s' to %p\n", part, addr);
55 ret = nand_read_skip_bad(&nand_info[0], part_info->offset, &len, addr);
57 printf("Failed to load partition '%s' to %p\n", part, addr);
60 debug("Read %u byte from partition '%s' @ offset %08x\n",
61 len, part, part_info->offset);
65 static ulong calc_fbsize(void)
67 return panel_info.vl_row * panel_info.vl_col *
68 NBITS(panel_info.vl_bpix) / 8;
71 int karo_load_splashimage(int mode)
74 int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
75 unsigned long la = gd->fb_base;
76 char *splashimage = getenv("splashimage");
77 ulong fbsize = calc_fbsize();
80 if (!la || !splashimage)
83 if ((simple_strtoul(splashimage, &end, 16) != 0) &&
87 la = simple_strtoul(splashimage, NULL, 16);
88 splashimage = "logo.bmp";
96 ret = karo_load_part(splashimage, (void *)la, fbsize);
98 printf("Failed to load logo from '%s': %d\n", splashimage, ret);
104 static int erase_flash(loff_t offs, size_t len)
106 nand_erase_options_t nand_erase_options;
108 memset(&nand_erase_options, 0, sizeof(nand_erase_options));
109 nand_erase_options.length = len;
110 nand_erase_options.offset = offs;
112 return nand_erase_opts(&nand_info[0], &nand_erase_options);
115 int do_fbdump(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
118 size_t fbsize = calc_fbsize();
119 const char *part = "logo";
120 struct mtd_device *dev;
121 struct part_info *part_info;
123 u_char *addr = (u_char *)gd->fb_base;
126 return CMD_RET_USAGE;
132 printf("fb address unknown\n");
133 return CMD_RET_FAILURE;
136 debug("Initializing mtd_parts\n");
137 ret = mtdparts_init();
141 debug("Trying to find NAND partition '%s'\n", part);
142 ret = find_dev_and_part(part, &dev, &part_num,
145 printf("Failed to find flash partition '%s': %d\n",
150 debug("Found partition '%s': offset=%08x size=%08x\n",
151 part, part_info->offset, part_info->size);
152 if (part_info->size < fbsize) {
153 printf("Error: partition '%s' smaller than frame buffer size: %u\n",
155 return CMD_RET_FAILURE;
157 debug("Writing framebuffer %p to NAND partition '%s'\n",
160 ret = erase_flash(part_info->offset, fbsize);
162 printf("Failed to erase partition '%s'\n", part);
163 return CMD_RET_FAILURE;
166 ret = nand_write_skip_bad(&nand_info[0], part_info->offset,
167 &fbsize, addr, WITH_DROP_FFS);
169 printf("Failed to write partition '%s'\n", part);
172 debug("Wrote %u byte from %p to partition '%s' @ offset %08x\n",
173 fbsize, addr, part, part_info->offset);
175 return CMD_RET_SUCCESS;
178 U_BOOT_CMD(fbdump, 2, 0, do_fbdump, "dump framebuffer contents to flash",
180 " default partition name: 'logo'\n");