Deleted Added
full compact
copy.c (283505) copy.c (294685)
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/copy.c 283505 2015-05-25 01:06:55Z ian $");
29__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/copy.c 294685 2016-01-24 22:00:36Z ian $");
30#include <sys/param.h>
31
32#include <stand.h>
33#include <stdint.h>
34
35#include "api_public.h"
36#include "glue.h"
37#include "libuboot.h"

--- 26 unchanged lines hidden (view full) ---

64 *
65 * On subsequent calls the addr will be non-zero, and we just round it up so
66 * that each object begins on a page boundary.
67 */
68uint64_t
69uboot_loadaddr(u_int type, void *data, uint64_t addr)
70{
71 struct sys_info *si;
30#include <sys/param.h>
31
32#include <stand.h>
33#include <stdint.h>
34
35#include "api_public.h"
36#include "glue.h"
37#include "libuboot.h"

--- 26 unchanged lines hidden (view full) ---

64 *
65 * On subsequent calls the addr will be non-zero, and we just round it up so
66 * that each object begins on a page boundary.
67 */
68uint64_t
69uboot_loadaddr(u_int type, void *data, uint64_t addr)
70{
71 struct sys_info *si;
72 uintptr_t sblock, eblock, subldr, eubldr;
73 uintptr_t biggest_block, this_block;
74 size_t biggest_size, this_size;
72 uint64_t sblock, eblock, subldr, eubldr;
73 uint64_t biggest_block, this_block;
74 uint64_t biggest_size, this_size;
75 int i;
75 int i;
76 char * envstr;
76 char *envstr;
77
78 if (addr == 0) {
79 /*
80 * If the loader_kernaddr environment variable is set, blindly
81 * honor it. It had better be right. We force interpretation
82 * of the value in base-16 regardless of any leading 0x prefix,
83 * because that's the U-Boot convention.
84 */

--- 11 unchanged lines hidden (view full) ---

96 * optimistically assume that we won't run into it up there.
97 */
98 if ((si = ub_get_sys_info()) == NULL)
99 panic("could not retrieve system info");
100
101 biggest_block = 0;
102 biggest_size = 0;
103 subldr = rounddown2((uintptr_t)_start, KERN_ALIGN);
77
78 if (addr == 0) {
79 /*
80 * If the loader_kernaddr environment variable is set, blindly
81 * honor it. It had better be right. We force interpretation
82 * of the value in base-16 regardless of any leading 0x prefix,
83 * because that's the U-Boot convention.
84 */

--- 11 unchanged lines hidden (view full) ---

96 * optimistically assume that we won't run into it up there.
97 */
98 if ((si = ub_get_sys_info()) == NULL)
99 panic("could not retrieve system info");
100
101 biggest_block = 0;
102 biggest_size = 0;
103 subldr = rounddown2((uintptr_t)_start, KERN_ALIGN);
104 eubldr = roundup2(uboot_heap_end, KERN_ALIGN);
104 eubldr = roundup2((uint64_t)uboot_heap_end, KERN_ALIGN);
105 for (i = 0; i < si->mr_no; i++) {
106 if (si->mr[i].flags != MR_ATTR_DRAM)
107 continue;
105 for (i = 0; i < si->mr_no; i++) {
106 if (si->mr[i].flags != MR_ATTR_DRAM)
107 continue;
108 sblock = roundup2(si->mr[i].start, KERN_ALIGN);
109 eblock = rounddown2(si->mr[i].start + si->mr[i].size,
108 sblock = roundup2((uint64_t)si->mr[i].start,
110 KERN_ALIGN);
109 KERN_ALIGN);
110 eblock = rounddown2((uint64_t)si->mr[i].start +
111 si->mr[i].size, KERN_ALIGN);
111 if (biggest_size == 0)
112 sblock += KERN_MINADDR;
113 if (subldr >= sblock && subldr < eblock) {
114 if (subldr - sblock > eblock - eubldr) {
115 this_block = sblock;
116 this_size = subldr - sblock;
117 } else {
118 this_block = eubldr;
119 this_size = eblock - eubldr;
120 }
121 }
122 if (biggest_size < this_size) {
123 biggest_block = this_block;
124 biggest_size = this_size;
125 }
126 }
127 if (biggest_size == 0)
128 panic("Not enough DRAM to load kernel\n");
129#if 0
112 if (biggest_size == 0)
113 sblock += KERN_MINADDR;
114 if (subldr >= sblock && subldr < eblock) {
115 if (subldr - sblock > eblock - eubldr) {
116 this_block = sblock;
117 this_size = subldr - sblock;
118 } else {
119 this_block = eubldr;
120 this_size = eblock - eubldr;
121 }
122 }
123 if (biggest_size < this_size) {
124 biggest_block = this_block;
125 biggest_size = this_size;
126 }
127 }
128 if (biggest_size == 0)
129 panic("Not enough DRAM to load kernel\n");
130#if 0
130 printf("Loading kernel into region 0x%08x-0x%08x (%u MiB)\n",
131 biggest_block, biggest_block + biggest_size - 1,
132 biggest_size / 1024 / 1024);
131 printf("Loading kernel into region 0x%08jx-0x%08jx (%ju MiB)\n",
132 (uintmax_t)biggest_block,
133 (uintmax_t)biggest_block + biggest_size - 1,
134 (uintmax_t)biggest_size / 1024 / 1024);
133#endif
134 return (biggest_block);
135 }
136 return roundup2(addr, PAGE_SIZE);
137}
138
139ssize_t
140uboot_copyin(const void *src, vm_offset_t dest, const size_t len)

--- 17 unchanged lines hidden ---
135#endif
136 return (biggest_block);
137 }
138 return roundup2(addr, PAGE_SIZE);
139}
140
141ssize_t
142uboot_copyin(const void *src, vm_offset_t dest, const size_t len)

--- 17 unchanged lines hidden ---