]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/fb_mmc.c
ARM: tegra: Enable non-cached memory
[people/ms/u-boot.git] / common / fb_mmc.c
CommitLineData
c0aebb33
SR
1/*
2 * Copyright 2014 Broadcom Corporation.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <fb_mmc.h>
9#include <part.h>
e5bf9878
SR
10#include <aboot.h>
11#include <sparse_format.h>
c0aebb33
SR
12
13/* The 64 defined bytes plus the '\0' */
14#define RESPONSE_LEN (64 + 1)
15
16static char *response_str;
17
e5bf9878 18void fastboot_fail(const char *s)
c0aebb33 19{
e5bf9878
SR
20 strncpy(response_str, "FAIL", 4);
21 strncat(response_str, s, RESPONSE_LEN - 4 - 1);
22}
23
24void fastboot_okay(const char *s)
25{
26 strncpy(response_str, "OKAY", 4);
27 strncat(response_str, s, RESPONSE_LEN - 4 - 1);
c0aebb33
SR
28}
29
30static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
31 const char *part_name, void *buffer,
32 unsigned int download_bytes)
33{
34 lbaint_t blkcnt;
35 lbaint_t blks;
36
37 /* determine number of blocks to write */
38 blkcnt = ((download_bytes + (info->blksz - 1)) & ~(info->blksz - 1));
39 blkcnt = blkcnt / info->blksz;
40
41 if (blkcnt > info->size) {
42 error("too large for partition: '%s'\n", part_name);
e5bf9878 43 fastboot_fail("too large for partition");
c0aebb33
SR
44 return;
45 }
46
47 puts("Flashing Raw Image\n");
48
49 blks = dev_desc->block_write(dev_desc->dev, info->start, blkcnt,
50 buffer);
51 if (blks != blkcnt) {
52 error("failed writing to device %d\n", dev_desc->dev);
e5bf9878 53 fastboot_fail("failed writing to device");
c0aebb33
SR
54 return;
55 }
56
57 printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
58 part_name);
e5bf9878 59 fastboot_okay("");
c0aebb33
SR
60}
61
62void fb_mmc_flash_write(const char *cmd, void *download_buffer,
63 unsigned int download_bytes, char *response)
64{
65 int ret;
66 block_dev_desc_t *dev_desc;
67 disk_partition_t info;
68
69 /* initialize the response buffer */
70 response_str = response;
71
72 dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
73 if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
74 error("invalid mmc device\n");
e5bf9878 75 fastboot_fail("invalid mmc device");
c0aebb33
SR
76 return;
77 }
78
79 ret = get_partition_info_efi_by_name(dev_desc, cmd, &info);
80 if (ret) {
81 error("cannot find partition: '%s'\n", cmd);
e5bf9878 82 fastboot_fail("cannot find partition");
c0aebb33
SR
83 return;
84 }
85
e5bf9878
SR
86 if (is_sparse_image(download_buffer))
87 write_sparse_image(dev_desc, &info, cmd, download_buffer,
88 download_bytes);
89 else
90 write_raw_image(dev_desc, &info, cmd, download_buffer,
91 download_bytes);
c0aebb33 92}