2 * (C) Copyright 2014 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.
21 #include <fdt_support.h>
24 #include <linux/list.h>
26 #include <jffs2/load_kernel.h>
31 #ifdef CONFIG_MAX_DTB_SIZE
32 #define MAX_DTB_SIZE CONFIG_MAX_DTB_SIZE
34 #define MAX_DTB_SIZE SZ_64K
37 DECLARE_GLOBAL_DATA_PTR;
39 int karo_load_nand_part(const char *part, void *addr, size_t len)
42 struct mtd_device *dev;
43 struct part_info *part_info;
47 debug("Initializing mtd_parts\n");
48 ret = mtdparts_init();
52 debug("Trying to find NAND partition '%s'\n", part);
53 ret = find_dev_and_part(part, &dev, &part_num, &part_info);
55 printf("Failed to find flash partition '%s': %d\n",
60 debug("Found partition '%s': offset=%08x size=%08x\n",
61 part, part_info->offset, part_info->size);
62 if (part_info->size < len) {
63 printf("Warning: partition '%s' smaller than requested size: %u; truncating data to %u byte\n",
64 part, len, part_info->size);
65 len = part_info->size;
67 debug("Reading NAND partition '%s' to %p\n", part, addr);
68 ret = nand_read_skip_bad(&nand_info[0], part_info->offset, &len,
71 printf("Failed to load partition '%s' to %p\n", part, addr);
75 printf("Read only %u of %u bytes due to bad blocks\n",
78 debug("Read %u byte from partition '%s' @ offset %08x\n",
79 len, part, part_info->offset);
83 #ifdef CONFIG_SPLASH_SCREEN_
84 static int erase_flash(loff_t offs, size_t len)
86 nand_erase_options_t nand_erase_options;
88 memset(&nand_erase_options, 0, sizeof(nand_erase_options));
89 nand_erase_options.length = len;
90 nand_erase_options.offset = offs;
92 return nand_erase_opts(&nand_info[0], &nand_erase_options);
95 int do_fbdump(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
98 size_t fbsize = calc_fbsize();
99 const char *part = "logo";
100 struct mtd_device *dev;
101 struct part_info *part_info;
103 u_char *addr = (u_char *)gd->fb_base;
107 return CMD_RET_USAGE;
113 printf("fb address unknown\n");
114 return CMD_RET_FAILURE;
117 debug("Initializing mtd_parts\n");
118 ret = mtdparts_init();
122 debug("Trying to find NAND partition '%s'\n", part);
123 ret = find_dev_and_part(part, &dev, &part_num,
126 printf("Failed to find flash partition '%s': %d\n",
131 debug("Found partition '%s': offset=%08x size=%08x\n",
132 part, part_info->offset, part_info->size);
133 if (part_info->size < fbsize) {
134 printf("Error: partition '%s' smaller than frame buffer size: %u\n",
136 return CMD_RET_FAILURE;
138 debug("Writing framebuffer %p to NAND partition '%s'\n",
141 ret = erase_flash(part_info->offset, fbsize);
143 printf("Failed to erase partition '%s'\n", part);
144 return CMD_RET_FAILURE;
147 ret = nand_write_skip_bad(&nand_info[0], part_info->offset,
148 &fbsize, &actual, part_info->size,
149 addr, WITH_DROP_FFS);
151 printf("Failed to write partition '%s'\n", part);
155 printf("Wrote only %u of %u bytes due to bad blocks\n",
158 debug("Wrote %u byte from %p to partition '%s' @ offset %08x\n",
159 fbsize, addr, part, part_info->offset);
161 return CMD_RET_SUCCESS;
164 U_BOOT_CMD(fbdump, 2, 0, do_fbdump, "dump framebuffer contents to flash",
166 " default partition name: 'logo'\n");