📄 loader.c
字号:
/* * Copyright (C) 2006-2007 Pawel Kolodziejski * * Some defines are from linux 2.6 kernel sources * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "types.h"#include "setup.h"#include "pxa-regs.h"#include "gpio.h"#define KEY_NONE 0#define KEY_POWER 1#define KEY_HOME 4#define KEY_CALENDAR 8#define KEY_TASKS 16#define KEY_CONTACTS 32void *malloc(unsigned long size);void free(void *block);void _start(void) { setCoreClock(); TurnOnICache(); gpo_init(); init_pm(); malloc_init(); clear_screen(); display_on(); //blue_led_on(); menu(); clear_screen(); pxafb_disable();}static void drawMenuLines(int menuId) { drawText(0,14, " 1. Boot from SD/MMC - ext2 - ", 1 == menuId, 0x0000); drawText(0,15, " 2. Boot from CF - ext2 - ", 2 == menuId, 0x0000); drawText(0,16, " 3. Boot from SD/MMC - fat - ", 3 == menuId, 0x0000); drawText(0,17, " 4. Boot from CF - fat - ", 4 == menuId, 0x0000); drawText(0,18, " 5. Start Wince ", 5 == menuId, 0x0000);}int menu(void) { drawText(0, 2, " ---------------------------- ", 0, 0x0000); drawText(0, 3, " ", 0, 0x0000); drawText(0, 4, " Bootloader menu ", 0, 0x0000); drawText(0, 5, " 2008-03-23 ", 0, 0x0000); drawText(0, 6, " ---------------------------- ", 0, 0x0000); drawText(0, 8, " 'Home' - Up ", 0, 0x0000); drawText(0, 9, " 'Calendar' - Down ", 0, 0x0000); drawText(0,10, " 'Tasks' - Action ", 0, 0x0000); drawText(0,12, " Select from menu: ", 0, 0x0000); unsigned long keys; int menuId = 0; int res = 0; for (;;) { drawMenuLines(menuId); mdelay(200); keys = waitForKey(); if (((keys & KEY_TASKS) == KEY_TASKS) && menuId != 0) break; if (((keys & KEY_HOME) == KEY_HOME) && menuId > 1) menuId--; if (((keys & KEY_CALENDAR) == KEY_CALENDAR) && menuId < 5) menuId++; } if ((menuId == 1)) linloader_sd(0); if ((menuId == 2)) linloader_cf(0); if ((menuId == 3)) linloader_sd(1); if ((menuId == 4)) linloader_cf(1); return 0;}int updateBar1(int progress) { char string[32]; sprintf(string, "Progress: %d % ", progress); drawText(2, 18, string, 0, 0x0000);}int linloader_sd(int fs_type) { char string[32]; char cmdline[256]; char *default_params = "console=tty0 root=/dev/mmcblk0p2", *params, *t_params; unsigned long i, l, state; u32 kernel_blocks, initrd_size = 0; u8 *kernel_image = (u8 *)0xA3208000; // kernel image address u8 *initrd_image = (u8 *)0xA3500000; // initrd image address clear_screen(); drawText(0, 2, " ---------------------------- ", 0, 0x0000); drawText(0, 3, " | | ", 0, 0x0000); drawText(0, 4, " | SD/MMC Linux Loader | ", 0, 0x0000); drawText(0, 5, " | | ", 0, 0x0000); drawText(0, 6, " ---------------------------- ", 0, 0x0000); int blocksBegin = 1; drawText(2, 14, "Init SD/MMC card...", 0, 0x003f); state = sd_check_inserted(); if (state != 0) { drawText(2, 17, "SD/MMC card not inserted...", 0, 0xf800); drawText(26, 14, "Fail", 0, 0xf800); goto failed; } sd_turn_on(); state = sd_card_init(); if (state != 0) drawText(26, 14, "OK", 0, 0x0700); else { drawText(26, 14, "Fail", 0, 0xf800); goto failed; } sd_setup_for_transfer(state); drawText(2, 16, "Loading zImage ", 0, 0x003f); drawText(2, 17, "Please wait... ", 0, 0x003f); state = read_file("/boot/zImage", kernel_image, fs_type, 0, 0); if (state == 0) { drawText(2, 16, "No /boot/zImage found ", 0, 0xf800); drawText(2, 17, " ", 0, 0x003f); goto failed; } t_params = malloc(1024); memset(t_params, 0, 1024); state = read_file("/boot/params_a716_sd", t_params, fs_type, 0, 0); if (state == 0) { drawText(2, 16, "No /boot/params_a716_sd ", 0, 0xf800); drawText(2, 17, "Using defaults ", 0, 0x003f); params = default_params; } else { params = t_params; } sd_turn_off(); drawText(2, 19, "Jump to Linux kernel...", 0, 0x003f); setup_linux_params((u32)0xA3500000, initrd_size, params); free(t_params); JumpLoader();failed: drawText(2, 19, "Press hardreset to restart", 0, 0xf800); goto end;end: for (;;) { }}int linloader_cf(int fs_type) { char string[32]; char cmdline[256]; char *default_params = "console=tty0 root=/dev/hda2", *params, *t_params;// char *default_params = "console=tty0 init=/linuxrc script_id=boot_cf root=/dev/ram0", *params; unsigned long i, l, state; u32 tag, version, kernel_blocks, initrd_size = 0; u8 *kernel_image = (u8 *)0xA3208000; // kernel image address u8 *initrd_image = (u8 *)0xA3500000; // initrd image address clear_screen(); drawText(0, 2, " ---------------------------- ", 0, 0x0000); drawText(0, 3, " | | ", 0, 0x0000); drawText(0, 4, " | CF Linux Loader | ", 0, 0x0000); drawText(0, 5, " | | ", 0, 0x0000); drawText(0, 6, " ---------------------------- ", 0, 0x0000); int blocksBegin = 1; drawText(2, 14, "Init CF card...", 0, 0x003f); state = cf_check_inserted(); if (state != 0) { drawText(2, 17, "CF card not inserted...", 0, 0xf800); drawText(26, 14, "Fail", 0, 0xf800); goto failed; } state = cf_card_init(); if (state == 0) drawText(26, 14, "OK", 0, 0x0700); else { drawText(26, 14, "Fail", 0, 0xf800); goto failed; } drawText(2, 16, "Loading zImage ", 0, 0x003f); drawText(2, 17, "Please wait... ", 0, 0x003f); state = read_file("/boot/zImage", kernel_image, fs_type, 1, 0); if (state == 0) { drawText(2, 16, "No zImage found in /boot ", 0, 0xf800); drawText(2, 17, " ", 0, 0x003f); goto failed; }/* drawText(2, 16, "Loading initrd.gz ", 0, 0x003f); drawText(2, 17, "Please wait... ", 0, 0x003f); state = read_file("/boot/initrd.gz", initrd_image, fs_type, 1, 0); if (state == 0) { drawText(2, 16, "No initrd.gz found in /boot ", 0, 0xf800); drawText(2, 17, " ", 0, 0x003f); goto failed; } initrd_size = state;*/ t_params = malloc(1024); memset(t_params, 0, 1024); state = read_file("/boot/params_a716_cf", t_params, fs_type, 1, 0); if (state == 0) { drawText(2, 16, "No /boot/params_a716_cf ", 0, 0xf800); drawText(2, 17, "Using defaults ", 0, 0x003f); params = default_params; } else { params = t_params; } cf_turn_off(); drawText(2, 19, "Jump to Linux kernel...", 0, 0x003f); setup_linux_params((u32)0xA3500000, initrd_size, params); free(t_params); JumpLoader();failed: drawText(2, 19, "Press hardreset to restart", 0, 0xf800); goto end;end: for (;;) {}}int setup_linux_params(u32 initrd_addr, u32 initrd_size, const char *cmdline) { struct tag *tag; tag = (struct tag *)(0xA3200100); tag->hdr.tag = ATAG_CORE; tag->hdr.size = tag_size(tag_core); tag->u.core.flags = 0; tag->u.core.pagesize = 0x00001000; tag->u.core.rootdev = 0x0000; tag = tag_next(tag); tag->hdr.tag = ATAG_CMDLINE; tag->hdr.size = (strlen(cmdline) + 3 + 1 + sizeof(struct tag_header)) >> 2; strcpy(tag->u.cmdline.cmdline, cmdline); tag = tag_next(tag); tag->hdr.tag = ATAG_MEM; tag->hdr.size = tag_size(tag_mem32); tag->u.mem.start = 0xA0000000; tag->u.mem.size = 64 * 1024 * 1024; tag = tag_next(tag); if (initrd_size != 0) { tag->hdr.tag = ATAG_INITRD2; tag->hdr.size = tag_size(tag_initrd); tag->u.initrd.start = initrd_addr; tag->u.initrd.size = initrd_size; tag = tag_next(tag); } tag->hdr.tag = ATAG_NONE; tag->hdr.size = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -