Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some bug fix and improvement #26

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3786c9e
[arm64] fix minor issue in the interrupt function
xiaoxiang781216 Oct 13, 2014
97f625e
[arm64] implement fiq arch function
xiaoxiang781216 Oct 13, 2014
87d0bf0
[arm64] always use gcc builtin atomic operation
xiaoxiang781216 Oct 13, 2014
25f84f6
[arm] don't use strexeq which is arm only inst in atomic_cmpxchg
xiaoxiang781216 Oct 13, 2014
a05d6c5
[kernel] move spinlock out of arch/arm/include/arch/arch_ops.h
xiaoxiang781216 Oct 13, 2014
144dc4d
[arm_gic] remove arm 32bit specific code
xiaoxiang781216 Oct 15, 2014
dbbc331
[arm64] fix minor issue in the interrupt function
xiaoxiang781216 Oct 13, 2014
251ce80
[arm64] implement fiq arch function
xiaoxiang781216 Oct 13, 2014
fb61b20
[arm64] always use gcc builtin atomic operation
xiaoxiang781216 Oct 13, 2014
e7d8ba9
[arm] don't use strexeq which is arm only inst in atomic_cmpxchg
xiaoxiang781216 Oct 13, 2014
a3c1cf3
[kernel] move spinlock out of arch/arm/include/arch/arch_ops.h
xiaoxiang781216 Oct 13, 2014
0f60ee8
[arm_gic] remove arm 32bit specific code
xiaoxiang781216 Oct 15, 2014
436c0de
Revert "[app][aboot] remove some old Google code that hasn't been use…
xiaoxiang781216 Oct 8, 2014
3373133
[lib][partition] put partition related code into one folder
xiaoxiang781216 Oct 13, 2014
1a22e1d
[lib][ptable] support access table entry by index
xiaoxiang781216 Oct 14, 2014
7e8cec0
[app][aboot] port to the new ptable interface
xiaoxiang781216 Oct 14, 2014
5519935
[time] support mdelay and udelay function
xiaoxiang781216 Oct 15, 2014
8703775
provide linux-style read[w|b]()/write[w|b]() in reg.h
xiaoxiang781216 Oct 15, 2014
46a8618
[vm] add vaddr_to_paddr function
xiaoxiang781216 Oct 16, 2014
13e43e3
[arch] move the common code from arch_chain_load to chain_load
xiaoxiang781216 Oct 16, 2014
d3b4bfc
[arch] support chain_load with arguments(max 4)
xiaoxiang781216 Oct 16, 2014
2c3fdcc
[vm] remove __MMU_INITIAL_MAPPING_XXXX_OFFSET and related STATIC_ASSERT
xiaoxiang781216 Oct 17, 2014
e9789e0
[app][aboot] ensure aboot work well for no identity mapping
xiaoxiang781216 Oct 16, 2014
d2a62c9
[arch][arm] don't change V bit for pre armv7
xiaoxiang781216 Oct 17, 2014
d54159d
[arch][arm] make WITH_KERNEL_VM selectable
xiaoxiang781216 Oct 18, 2014
128c5e5
[arch][arm] support compile cortex-a7
xiaoxiang781216 Oct 17, 2014
212f5a8
[lib][heap] heap_grow reduce grow size when memory nearly exhaust
xiaoxiang781216 Oct 19, 2014
1a6d9d6
[lib][heap] fill the delayed free block with FREE_FILL
xiaoxiang781216 Oct 19, 2014
a8c679f
[lib][heap] make the heap usable as soon as possible
xiaoxiang781216 Oct 19, 2014
6dd1432
[arch][arm] ARM_CPU support cortex-a7-neon and cortex-a8-neon
xiaoxiang781216 Oct 21, 2014
7940351
[dev] define device_class for each class
xiaoxiang781216 Oct 20, 2014
4a1420c
[dev] device driver support the init order
xiaoxiang781216 Oct 21, 2014
32c61d5
[dev] add device_find for dynamic device search
xiaoxiang781216 Oct 21, 2014
eff3731
[dev] add the generic 16550 uart driver
xiaoxiang781216 Oct 21, 2014
6fb5802
[dev][timer][arm_generic] fix fixed_point.h can't find compiler error
xiaoxiang781216 Oct 22, 2014
5b112f3
[dev][timer][arm_generic] add arm_generic_timer_init_freq
xiaoxiang781216 Oct 22, 2014
5efcb33
[lib][sysparam] add sysparam_add_nosave function
xiaoxiang781216 Oct 23, 2014
1921230
[app][aboot] implement cmd_getvar base on sysparam
xiaoxiang781216 Oct 23, 2014
1d59d43
[vm] allocate vm_page array from self when heap exhaust
xiaoxiang781216 Oct 24, 2014
c7c2e2d
[vm] fix address calculation beyond 4G issue
xiaoxiang781216 Oct 25, 2014
f79ab98
[dev] add device_init_range to init device in [first, last]
xiaoxiang781216 Oct 24, 2014
32f7b94
[dev][16550] add reserved state in config structure
xiaoxiang781216 Oct 24, 2014
450fe80
Merge branch 'master' of https://github.com/xiaoxiang-xiaomi/lk
xiaoxiang781216 Oct 26, 2014
9be54e0
[dev] move dev to next for each loop in device_find
xiaoxiang781216 Oct 27, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
327 changes: 327 additions & 0 deletions app/aboot/aboot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,327 @@
/*
* Copyright (c) 2009, Google Inc.
* Copyright (c) 2014, Xiaomi Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google, Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include <app.h>
#include <debug.h>
#include <dev/udc.h>
#include <string.h>
#include <kernel/thread.h>
#include <kernel/vm.h>

#include <dev/flash.h>
#include <lib/ptable.h>
#include <dev/keys.h>

#include "bootimg.h"
#include "fastboot.h"

#define DEFAULT_CMDLINE "mem=50M console=null";

static struct udc_device surf_udc_device = {
.vendor_id = 0x18d1,
.product_id = 0x0001,
.version_id = 0x0100,
.manufacturer = "Google",
.product = "Android",
};

struct atag_ptbl_entry {
char name[16];
unsigned offset;
unsigned size;
unsigned flags;
};

static void ptentry_to_tag(unsigned **ptr, struct ptable_entry *ptn)
{
struct atag_ptbl_entry atag_ptn;

memcpy(atag_ptn.name, ptn->name, 16);
atag_ptn.name[15] = '\0';
atag_ptn.offset = ptn->offset;
atag_ptn.size = ptn->length;
atag_ptn.flags = ptn->flags;
memcpy(*ptr, &atag_ptn, sizeof(struct atag_ptbl_entry));
*ptr += sizeof(struct atag_ptbl_entry) / sizeof(unsigned);
}

void boot_linux(void *kernel, unsigned *tags,
const char *cmdline, unsigned machtype,
void *ramdisk, unsigned ramdisk_size)
{
unsigned *ptr = tags;
int count;

/* CORE */
*ptr++ = 2;
*ptr++ = 0x54410001;

if (ramdisk_size) {
*ptr++ = 4;
*ptr++ = 0x54420005;
*ptr++ = vaddr_to_paddr(ramdisk);
*ptr++ = ramdisk_size;
}

count = ptable_get_count();
if (count != 0) {
int i;
*ptr++ = 2 + (count * (sizeof(struct atag_ptbl_entry) /
sizeof(unsigned)));
*ptr++ = 0x4d534d70;
for (i = 0; i < count; ++i) {
struct ptable_entry entry;
bzero(&entry, sizeof(entry));
ptable_get(i, &entry);
ptentry_to_tag(&ptr, &entry);
}
}

if (cmdline && cmdline[0]) {
unsigned n;
/* include terminating 0 and round up to a word multiple */
n = (strlen(cmdline) + 4) & (~3);
*ptr++ = (n / 4) + 2;
*ptr++ = 0x54410009;
memcpy(ptr, cmdline, n);
ptr += (n / 4);
}

/* END */
*ptr++ = 0;
*ptr++ = 0;

dprintf(INFO, "booting linux @ %p, ramdisk @ %p (%d)\n",
kernel, ramdisk, ramdisk_size);
if (cmdline)
dprintf(INFO, "cmdline: %s\n", cmdline);

chain_load3(kernel, 0, machtype, vaddr_to_paddr(tags));
}

#define PAGE_MASK 2047

#define ROUND_TO_PAGE(x) (((x) + PAGE_MASK) & (~PAGE_MASK))

static unsigned char buf[2048];

int boot_linux_from_flash(void)
{
struct boot_img_hdr *hdr = (void*) buf;
unsigned n;
struct ptable_entry entry;
struct ptable_entry *ptn = &entry;
unsigned offset = 0;
const char *cmdline;
void *kernel;
void *ramdisk;

if (ptable_find("boot", ptn) != 0) {
dprintf(CRITICAL, "ERROR: No boot partition found\n");
return -1;
}

if (flash_read(ptn, offset, buf, 2048)) {
dprintf(CRITICAL, "ERROR: Cannot read boot image header\n");
return -1;
}
offset += 2048;

if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
dprintf(CRITICAL, "ERROR: Invaled boot image heador\n");
return -1;
}

n = ROUND_TO_PAGE(hdr->kernel_size);
kernel = paddr_to_kvaddr(hdr->kernel_addr);
if (flash_read(ptn, offset, kernel, n)) {
dprintf(CRITICAL, "ERROR: Cannot read kernel image\n");
return -1;
}
offset += n;

n = ROUND_TO_PAGE(hdr->ramdisk_size);
ramdisk = paddr_to_kvaddr(hdr->ramdisk_addr);
if (flash_read(ptn, offset, ramdisk, n)) {
dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n");
return -1;
}
offset += n;

dprintf(INFO, "\nkernel @ %x (%d bytes)\n", hdr->kernel_addr,
hdr->kernel_size);
dprintf(INFO, "ramdisk @ %x (%d bytes)\n", hdr->ramdisk_addr,
hdr->ramdisk_size);

if (hdr->cmdline[0]) {
cmdline = (char*) hdr->cmdline;
} else {
cmdline = DEFAULT_CMDLINE;
}
dprintf(INFO, "cmdline = '%s'\n", cmdline);

/* TODO: create/pass atags to kernel */

dprintf(INFO, "\nBooting Linux\n");
boot_linux(kernel, paddr_to_kvaddr(hdr->tags_addr),
(const char *)cmdline, LINUX_MACHTYPE,
ramdisk, hdr->ramdisk_size);

return 0;
}

void cmd_boot(const char *arg, void *data, unsigned sz)
{
unsigned kernel_actual;
unsigned ramdisk_actual;
static struct boot_img_hdr hdr;
char *ptr = ((char*) data);
void *kernel;
void *ramdisk;

if (sz < sizeof(hdr)) {
fastboot_fail("invalid bootimage header");
return;
}

memcpy(&hdr, data, sizeof(hdr));

/* ensure commandline is terminated */
hdr.cmdline[BOOT_ARGS_SIZE-1] = 0;

kernel_actual = ROUND_TO_PAGE(hdr.kernel_size);
ramdisk_actual = ROUND_TO_PAGE(hdr.ramdisk_size);

if (2048 + kernel_actual + ramdisk_actual < sz) {
fastboot_fail("incomplete bootimage");
return;
}

kernel = paddr_to_kvaddr(hdr.kernel_addr);
memmove(kernel, ptr + 2048, hdr.kernel_size);

ramdisk = paddr_to_kvaddr(hdr.ramdisk_addr);
memmove(ramdisk, ptr + 2048 + kernel_actual, hdr.ramdisk_size);

fastboot_okay("");
udc_stop();


boot_linux(kernel, paddr_to_kvaddr(hdr.tags_addr),
(const char*) hdr.cmdline, LINUX_MACHTYPE,
ramdisk, hdr.ramdisk_size);
}

void cmd_erase(const char *arg, void *data, unsigned sz)
{
struct ptable_entry entry;
struct ptable_entry *ptn = &entry;

if (ptable_find(arg, ptn) != 0) {
fastboot_fail("unknown partition name");
return;
}

if (flash_erase(ptn)) {
fastboot_fail("failed to erase partition");
return;
}
fastboot_okay("");
}

void cmd_flash(const char *arg, void *data, unsigned sz)
{
struct ptable_entry entry;
struct ptable_entry *ptn = &entry;
unsigned extra = 0;

if (ptable_find(arg, ptn) != 0) {
fastboot_fail("unknown partition name");
return;
}

if (!strcmp((char *)ptn->name, "boot") || !strcmp((char *)ptn->name, "recovery")) {
if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
fastboot_fail("image is not a boot image");
return;
}
}

if (!strcmp((char *)ptn->name, "system") || !strcmp((char *)ptn->name, "userdata"))
extra = 64;
else
sz = ROUND_TO_PAGE(sz);

dprintf(INFO, "writing %d bytes to '%s'\n", sz, ptn->name);
if (flash_write(ptn, extra, data, sz)) {
fastboot_fail("flash write failure");
return;
}
dprintf(INFO, "partition '%s' updated\n", ptn->name);
fastboot_okay("");
}

void cmd_continue(const char *arg, void *data, unsigned sz)
{
fastboot_okay("");
udc_stop();

boot_linux_from_flash();
}

void aboot_init(const struct app_descriptor *app)
{
if (keys_get_state(KEY_BACK) != 0)
goto fastboot;

boot_linux_from_flash();
dprintf(CRITICAL, "ERROR: Could not do normal boot. Reverting "
"to fastboot mode.\n");

fastboot:
udc_init(&surf_udc_device);

fastboot_register("boot", cmd_boot);
fastboot_register("erase:", cmd_erase);
fastboot_register("flash:", cmd_flash);
fastboot_register("continue", cmd_continue);
fastboot_publish("product", "swordfish");
fastboot_publish("kernel", "lk");

fastboot_init((void*) 0x10100000, 100 * 1024 * 1024);
udc_start();
}

APP_START(aboot)
.init = aboot_init,
APP_END

Loading