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;
46 debug("Initializing mtd_parts\n");
47 ret = mtdparts_init();
51 debug("Trying to find NAND partition '%s'\n", part);
52 ret = find_dev_and_part(part, &dev, &part_num, &part_info);
54 printf("Failed to find flash partition '%s': %d\n",
59 debug("Found partition '%s': offset=%08llx size=%08llx\n",
60 part, (u64)part_info->offset, (u64)part_info->size);
62 if (part_info->size < len)
63 len = part_info->size;
65 debug("Reading NAND partition '%s' to %p\n", part, addr);
66 ret = nand_read_skip_bad(&nand_info[0], part_info->offset, &len,
67 NULL, part_info->size, addr);
69 printf("Failed to load partition '%s' to %p\n", part, addr);
73 debug("Read %u byte from partition '%s' @ offset %08llx\n",
74 len, part, (u64)part_info->offset);
78 #if defined(CONFIG_SPLASH_SCREEN) && defined(CONFIG_MTDPARTS)
79 static int erase_flash(loff_t offs, size_t len)
81 nand_erase_options_t nand_erase_options;
83 memset(&nand_erase_options, 0, sizeof(nand_erase_options));
84 nand_erase_options.length = len;
85 nand_erase_options.offset = offs;
87 return nand_erase_opts(&nand_info[0], &nand_erase_options);
90 int do_fbdump(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
93 size_t fbsize = calc_fbsize();
94 const char *part = "logo";
95 struct mtd_device *dev;
96 struct part_info *part_info;
98 u_char *addr = (u_char *)gd->fb_base;
101 return CMD_RET_USAGE;
107 printf("fb address unknown\n");
108 return CMD_RET_FAILURE;
111 debug("Initializing mtd_parts\n");
112 ret = mtdparts_init();
114 return CMD_RET_FAILURE;
116 debug("Trying to find NAND partition '%s'\n", part);
117 ret = find_dev_and_part(part, &dev, &part_num,
120 printf("Failed to find flash partition '%s': %d\n",
122 return CMD_RET_FAILURE;
124 debug("Found partition '%s': offset=%08x size=%08x\n",
125 part, part_info->offset, part_info->size);
126 if (part_info->size < fbsize) {
127 printf("Error: partition '%s' smaller than frame buffer size: %u\n",
129 return CMD_RET_FAILURE;
131 debug("Writing framebuffer %p to NAND partition '%s'\n",
134 ret = erase_flash(part_info->offset, fbsize);
136 printf("Failed to erase partition '%s'\n", part);
137 return CMD_RET_FAILURE;
140 ret = nand_write_skip_bad(&nand_info[0], part_info->offset,
141 &fbsize, NULL, part_info->size,
142 addr, WITH_DROP_FFS);
144 printf("Failed to write partition '%s'\n", part);
145 return CMD_RET_FAILURE;
148 debug("Wrote %u byte from %p to partition '%s' @ offset %08x\n",
149 fbsize, addr, part, part_info->offset);
151 return CMD_RET_SUCCESS;
154 U_BOOT_CMD(fbdump, 2, 0, do_fbdump, "dump framebuffer contents to flash",
156 " default partition name: 'logo'\n");