/** Allocate from a fixed heap. * @param heap Heap to allocate from. * @param size Size of allocation to make. * @return Pointer to allocation, or NULL if no space left. */ void *fixed_heap_alloc(fixed_heap_t *heap, size_t size) { fixed_heap_tag_t *tag, *other; size_t total; if(!size) return NULL; /* Minimum size and alignment of 8 bytes. */ total = round_up(size, 8) + sizeof(fixed_heap_tag_t); /* Search for a free segment. */ for(tag = heap->tags; tag; tag = tag->next) { if(tag_allocated(tag) || tag_size(tag) < total) continue; /* Found a suitable segment, chop it up if necessary (and if * there's enough room to do so). */ if(tag_size(tag) > total && (tag_size(tag) - total) > (sizeof(fixed_heap_tag_t) + 8)) { other = (fixed_heap_tag_t *)((ptr_t)tag + total); other->next = tag->next; other->data = tag_size(tag) - total; tag->next = other; tag->data = total; } /* Mark as allocated. */ tag->data |= (1<<0); return (void *)((ptr_t)tag + sizeof(fixed_heap_tag_t)); } return NULL; }
void EAX_Decryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "Have the tag as part of final input"); const size_t remaining = sz - tag_size(); if(remaining) { m_cmac->update(buf, remaining); m_ctr->cipher(buf, buf, remaining); } const byte* included_tag = &buf[remaining]; secure_vector<byte> mac = m_cmac->final(); mac ^= m_nonce_mac; mac ^= m_ad_mac; if(!same_mem(mac.data(), included_tag, tag_size())) throw Integrity_Failure("EAX tag check failed"); buffer.resize(offset + remaining); }
/* * .KB_C_FN_DEFINITION_START * void InitTagList(char*, void *) * This global function populates a linux-boot style tag list from the * string passed in the pointer at the location specified. * .KB_C_FN_DEFINITION_END */ void InitTagList(char *parms, void *output) { char *src, *dst; struct tag *tagList = (struct tag*)output; tagList->hdr.size = tag_size(tag_core); tagList->hdr.tag = ATAG_CORE; tagList->u.core.flags = 1; tagList->u.core.pagesize = PAGE_SIZE; tagList->u.core.rootdev = 0xff; tagList = tag_next(tagList); tagList->hdr.size = tag_size(tag_mem32); tagList->hdr.tag = ATAG_MEM; tagList->u.mem.size = MEM_SIZE; tagList->u.mem.start = PHYS_OFFSET; tagList = tag_next(tagList); tagList->hdr.size = tag_size(tag_cmdline); tagList->hdr.tag = ATAG_CMDLINE; src = parms; dst = tagList->u.cmdline.cmdline; while (*src) { *dst++ = *src++; } *dst = 0; tagList->hdr.size += ((unsigned)(src - parms) + 1) / sizeof(unsigned); tagList = tag_next(tagList); tagList->hdr.size = 0; tagList->hdr.tag = ATAG_NONE; }
static void __init fixup_p720t(struct machine_desc *desc, struct tag *tag, char **cmdline, struct meminfo *mi) { /* * Our bootloader doesn't setup any tags (yet). */ if (tag->hdr.tag != ATAG_CORE) { tag->hdr.tag = ATAG_CORE; tag->hdr.size = tag_size(tag_core); tag->u.core.flags = 0; tag->u.core.pagesize = PAGE_SIZE; tag->u.core.rootdev = 0x0100; tag = tag_next(tag); tag->hdr.tag = ATAG_MEM; tag->hdr.size = tag_size(tag_mem32); tag->u.mem.size = 4096; tag->u.mem.start = PHYS_OFFSET; tag = tag_next(tag); tag->hdr.tag = ATAG_NONE; tag->hdr.size = 0; } }
/* * boot and execute the linux kernel * r0 = must contain a zero or else the kernel loops * r1 = architecture type * r2 = physical address of tagged list in system ram */ static int bootlinux(int argc, char ** argv) { s32_t ret; s32_t linux_mach_type, linux_kernel, linux_tag_placement; struct machine * mach = get_machine(); struct tag * params; s8_t *p; s32_t i; if(argc != 5) { printk("usage:\r\n bootlinux <KERNEL ADDR> <PARAM ADDR> <MACH TYPE> <COMMAND LINE>\r\n"); return -1; } if(!mach) { printk("can not get machine information.\r\n"); return -1; } linux_kernel = strtoul((const char *)argv[1], NULL, 0); linux_tag_placement = strtoul((const char *)argv[2], NULL, 0); linux_mach_type = strtoul((const char *)argv[3], NULL, 0); /* setup linux kernel boot params */ params = (struct tag *)linux_tag_placement; /* first tag */ params->hdr.tag = ATAG_CORE; params->hdr.size = tag_size(tag_core); params->u.core.flags = 0; params->u.core.pagesize = 0; params->u.core.rootdev = 0; params = tag_next(params); /* memory tags */ for(i = 0; i < ARRAY_SIZE(mach->res.mem_banks); i++) { if( (mach->res.mem_banks[i].start == 0) && (mach->res.mem_banks[i].end == 0) ) break; params->hdr.tag = ATAG_MEM; params->hdr.size = tag_size(tag_mem32); params->u.mem.start = (u32_t)mach->res.mem_banks[i].start; params->u.mem.size = (u32_t)(mach->res.mem_banks[i].end - mach->res.mem_banks[i].start + 1); params = tag_next(params); } /* command line tags */ p = (s8_t *)argv[4]; if(p && strlen((const char *)p)) { params->hdr.tag = ATAG_CMDLINE; params->hdr.size = (sizeof (struct tag_header) + strlen((char *)p) + 1 + 4) >> 2; strcpy((char *)(params->u.cmdline.cmdline), (char *)p); params = tag_next (params); }
void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); const size_t sz = buffer.size() - offset; byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "We have the tag"); const secure_vector<byte>& ad = ad_buf(); BOTAN_ASSERT(ad.size() % BS == 0, "AD is block size multiple"); const BlockCipher& E = cipher(); secure_vector<byte> T(BS); E.encrypt(format_b0(sz - tag_size()), T); for(size_t i = 0; i != ad.size(); i += BS) { xor_buf(T.data(), &ad[i], BS); E.encrypt(T); } secure_vector<byte> C = format_c0(); secure_vector<byte> S0(BS); E.encrypt(C, S0); inc(C); secure_vector<byte> X(BS); const byte* buf_end = &buf[sz - tag_size()]; while(buf != buf_end) { const size_t to_proc = std::min<size_t>(BS, buf_end - buf); E.encrypt(C, X); xor_buf(buf, X.data(), to_proc); inc(C); xor_buf(T.data(), buf, to_proc); E.encrypt(T); buf += to_proc; } T ^= S0; if(!same_mem(T.data(), buf_end, tag_size())) throw Integrity_Failure("CCM tag check failed"); buffer.resize(buffer.size() - tag_size()); }
void setup_board_tags(struct tag **tmp) { struct tag *params = *tmp; struct tag_asv_margin *t; char *p = getenv("margin"); char *s = p; int value = 0; int minus = 0, percent = 0; s = strchr(s, '-'); if (s) minus = true; else s = strchr(s, '+'); if (!s) s = p; else s++; if (strchr(p, '%')) percent = 1; value = simple_strtol(s, NULL, 10); printf("ASV Margin:%s%d%s\n", minus?"-":"+", value, percent?"%":"mV"); /* set ARM margin */ params->hdr.tag = ATAG_ARM_MARGIN; params->hdr.size = tag_size(tag_asv_margin); t = (struct tag_asv_margin *)¶ms->u; t->value = value; t->minus = minus; t->percent = percent; params = tag_next(params); *tmp = params; /* set ARM margin */ params = *tmp; params->hdr.tag = ATAG_CORE_MARGIN; params->hdr.size = tag_size(tag_asv_margin); t = (struct tag_asv_margin *)¶ms->u; t->value = value; t->minus = minus; t->percent = percent; params = tag_next(params); *tmp = params; }
/* * build_params -- set up parameters for the kernel uImage */ static void build_params(char *cmdline, struct tag *params) { char *p; /* * set up the core tag */ params->hdr.tag = ATAG_CORE; params->hdr.size = tag_size(tag_core); params->u.core.flags = 0; params->u.core.pagesize = 0; params->u.core.rootdev = 0; params = tag_next(params); /* * set up the memory tags * Note: there should be one ATAG_MEM per memory bank, we have only one * bank at this time. */ params->hdr.tag = ATAG_MEM; params->hdr.size = tag_size(tag_mem32); params->u.mem.start = SDRAM_START; params->u.mem.size = SDRAM_SIZE; params = tag_next(params); /* * set up the kernel command line tag */ if(cmdline == 0) goto END_TAG; /* eat leading spaces */ for(p = cmdline; *p == ' '; p++); if(*p == '\0') goto END_TAG; params->hdr.tag = ATAG_CMDLINE; params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2; strcpy(params->u.cmdline.cmdline, p); params = tag_next(params); /* * set up the end tag */ END_TAG: params->hdr.tag = ATAG_NONE; params->hdr.size = 0; }
static void setup_videolfb_tag (gd_t *gd) { /* An ATAG_VIDEOLFB node tells the kernel where and how large * the framebuffer for video was allocated (among other things). * Note that a _physical_ address is passed ! * * We only use it to pass the address and size, the other entries * in the tag_videolfb are not of interest. */ params->hdr.tag = ATAG_VIDEOLFB; params->hdr.size = tag_size (tag_videolfb); if(g_boot_mode == FACTORY_BOOT) { params->u.videolfb.lfb_base = (u32) gd->fb_base - 0x9600000; memcpy((char *)(params->u.videolfb.lfb_base), (char *)gd->fb_base, mt65xx_disp_get_vram_size()); printf("[UBOOT Factory]fb addr = %x\n", params->u.videolfb.lfb_base); } else { params->u.videolfb.lfb_base = (u32) gd->fb_base; } /* Fb size is calculated according to parameters for our panel */ //params->u.videolfb.lfb_size = calc_fbsize(); params->u.videolfb.lfb_size = mt65xx_disp_get_vram_size(); params = tag_next (params); }
void *atag_build() { struct memory_image image; struct tag *tag = (struct tag*)ATAG_BASE_ADDR; printf("building atags\n"); 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); if (image_find(IMG_CMDLINE, &image) != NULL) { char *atag_cmdline = tag->u.cmdline.cmdline; tag->hdr.tag = ATAG_CMDLINE; tag->hdr.size = (sizeof(struct tag_header) + image.size + 1 + 3) >> 2; memcpy(atag_cmdline, image.data, image.size); if (atag_cmdline[image.size-1] == '\xa') { atag_cmdline[image.size-1] = '\0'; } else { atag_cmdline[image.size] = '\0'; } printf("cmdline found[%s]\n", atag_cmdline); tag = tag_next(tag); }
/* productid tag (alphanumeric strings) */ void setup_productid_tag(struct tag **in_params) { #ifdef CONFIG_ENABLE_IDME char pid_buf[IDME_MAX_PRODUCT_ID_LEN+1]; unsigned long count = 0; memset(pid_buf, 0, IDME_MAX_PRODUCT_ID_LEN+1); if (idme_get_var("pid", pid_buf, sizeof(pid_buf))){ printf("Error, failed to get the pid\n"); return; } printf("pid: %s\n",pid_buf); params->hdr.tag = ATAG_PRODUCTID; params->hdr.size = tag_size (tag_productid); memcpy (params->u.productid.pid, pid_buf, sizeof params->u.productid.pid); params = tag_next (params); #endif }
static void *make_taglist(int initrd_size) { void *taglist; struct tag *t; int i; unsigned long mem_start = 0x30000000; unsigned long mem_size = 0x01000000; //(unsigned long)__virt_to_phys(high_memory); if (!(t = taglist = kmalloc(MIN_SEGMENT_SIZE, GFP_KERNEL))) panic("make_taglist: Out of memory\n"); t->hdr.tag = ATAG_CORE; t->hdr.size = tag_size(tag_core); t->u.core.flags = 1; t->u.core.pagesize = PAGE_SIZE; t->u.core.rootdev = 0x0; //0x00010000lu; printk("CMDLINE: %s\n", cmdline); t = tag_next(t); i = strlen(cmdline)+1; t->hdr.size = (sizeof(struct tag_header) + i+3) >> 2; t->hdr.tag = ATAG_CMDLINE; strcpy(t->u.cmdline.cmdline, cmdline); printk("MEM: start %08lx size %luMB\n", mem_start, mem_size >> 20); t = tag_next(t); t->hdr.size = tag_size(tag_mem32); t->hdr.tag = ATAG_MEM; t->u.mem.size = mem_size; t->u.mem.start = mem_start; if (initrd_size > 0) { printk("INITRD: start %08lx size %d\n", 0x30400000lu, initrd_size); t = tag_next(t); t->hdr.size = tag_size(tag_initrd); t->hdr.tag = ATAG_INITRD2; t->u.initrd.start = 0x30400000; t->u.initrd.size = initrd_size; } t = tag_next(t); t->hdr.size = 0; t->hdr.tag = ATAG_NONE; return taglist; }
static void setup_modelid_tag(struct tag **in_params) { u32 modelid = get_modelid(); params->hdr.tag = ATAG_MODELID; params->hdr.size = tag_size (tag_modelid); params->u.modelid.id = modelid; params = tag_next (params); }
unsigned *target_atag_boot(unsigned *ptr) { *ptr++ = tag_size(tag_boot); *ptr++ = ATAG_BOOT; *ptr++ = g_boot_mode; return ptr; }
static void __init fixup_cep(struct machine_desc *desc, struct param_struct *params, char **cmdline, struct meminfo *mi) { struct tag *t = (struct tag *)params; /* * Apparantly bootldr uses a param_struct. Groan. */ if (t->hdr.tag != ATAG_CORE) convert_to_tag_list(params, 1); if (t->hdr.tag != ATAG_CORE) { t->hdr.tag = ATAG_CORE; t->hdr.size = tag_size(tag_core); t->u.core.flags = 0; t->u.core.pagesize = PAGE_SIZE; t->u.core.rootdev = RAMDISK_MAJOR << 8 | 0; t = tag_next(t); t->hdr.tag = ATAG_MEM; t->hdr.size = tag_size(tag_mem32); t->u.mem.start = 0xc0000000; t->u.mem.size = 32 * 1024 * 1024; t = tag_next(t); t->hdr.tag = ATAG_RAMDISK; t->hdr.size = tag_size(tag_ramdisk); t->u.ramdisk.flags = 1; t->u.ramdisk.size = 8192; t->u.ramdisk.start = 0; t = tag_next(t); t->hdr.tag = ATAG_INITRD; t->hdr.size = tag_size(tag_initrd); t->u.initrd.start = 0xc0800000; t->u.initrd.size = 3 * 1024 * 1024; t = tag_next(t); t->hdr.tag = ATAG_NONE; t->hdr.size = 0; } }
static void setup_modelid_tag(struct tag **in_params) { u32 modelid = 99; params->hdr.tag = ATAG_MODELID; SEC_ENTRY_Std_Ppa_Call ( PPA_SERV_HAL_BN_MODELID , 1 , &modelid ); params->hdr.size = tag_size (tag_modelid); params->u.modelid.id = modelid; params = tag_next (params); }
void setup_boot_tag (BOOTMODE boot_mode) { params->hdr.tag = ATAG_BOOT; params->hdr.size = tag_size (tag_boot); params->u.boot.bootmode = boot_mode; params = tag_next (params); printf("boot mode = %d\n",boot_mode); }
static struct tag *setup_boardinfo_tag(struct tag *params) { params->hdr.tag = ATAG_BOARDINFO; params->hdr.size = tag_size(tag_boardinfo); params->u.boardinfo.board_number = gd->bd->bi_board_number; return tag_next(params); }
static void setup_tag_revision(u32 rev) { params->hdr.tag = ATAG_REVISION; params->hdr.size = tag_size(tag_revision); params->u.revision.rev = rev; params = tag_next(params); }
static struct tag * __init memtag(struct tag *tag, unsigned long start, unsigned long size) { tag = tag_next(tag); tag->hdr.tag = ATAG_MEM; tag->hdr.size = tag_size(tag_mem32); tag->u.mem.size = size; tag->u.mem.start = start; return tag; }
void EAX_Encryption::finish(secure_vector<byte>& buffer, size_t offset) { update(buffer, offset); secure_vector<byte> data_mac = m_cmac->final(); xor_buf(data_mac, m_nonce_mac, data_mac.size()); xor_buf(data_mac, m_ad_mac, data_mac.size()); buffer += std::make_pair(data_mac.data(), tag_size()); }
void setup_memory_tags(void) { params->hdr.tag = ATAG_MEM; params->hdr.size = tag_size(tag_mem32); params->u.mem.start = 0x30000000; params->u.mem.size = 64*1024*1024; params = tag_next(params); }
static void setup_serialnr_tag(u32 hdrtag, u32 low, u32 high) { params->hdr.tag = hdrtag; params->hdr.size = tag_size(tag_serialnr); params->u.serialnr.low = low; params->u.serialnr.high = high; params = tag_next(params); }
static void setup_initrd_tag(u32 start, u32 size) { params->hdr.tag = ATAG_INITRD2; params->hdr.size = tag_size(tag_initrd); params->u.initrd.start = start; params->u.initrd.size = size; params = tag_next(params); }
static void setup_mem_tag(u32 hdrtag, u32 start, u32 len) { params->hdr.tag = hdrtag; params->hdr.size = tag_size(tag_mem32); params->u.mem.start = start; params->u.mem.size = len; params = tag_next(params); }
unsigned *target_atag_meta(unsigned *ptr) { *ptr++ = tag_size(tag_meta_com); *ptr++ = ATAG_META_COM; *ptr++ = g_boot_arg->meta_com_type; *ptr++ = g_boot_arg->meta_com_id; printf("meta com type = %d\n", g_boot_arg->meta_com_type); printf("meta com id = %d\n", g_boot_arg->meta_com_id); return ptr; }
void setup_mem_tag() { pCurTag->hdr.tag = ATAG_MEM; pCurTag->hdr.size = tag_size(tag_mem32); pCurTag->u.mem.start = SDRAM_ADDR_START; pCurTag->u.mem.size = SDRAM_TOTAL_SIZE; pCurTag = tag_next(pCurTag); }
static void setup_marvell_tag (void) { params->hdr.tag = ATAG_MARVELL; params->hdr.size = tag_size (tag_mv_uboot); params->u.mv_uboot.uboot_version = VER_NUM; memcpy(&(params->u.mv_uboot.mv_dram_init), &mv_dram_init, sizeof(MV_DRAM_INIT)); params = tag_next (params); }
static void setup_mem_tag(uint32 start, uint32 len) { params->hdr.tag = ATAG_MEM; /* Memory tag */ params->hdr.size = tag_size(atag_mem); /* size tag */ params->u.mem.start = start; /* Start of memory area (physical address) */ params->u.mem.size = len; /* Length of area */ params = tag_next(params); /* move pointer to next tag */ }
void setup_mem_tag() { params->hdr.size = tag_size(tag_mem32); params->hdr.tag = ATAG_MEM; //表示内存 params->u.mem.start = 0x20000000; //内存起始地址 params->u.mem.size = 1024*1024*1024; params = tag_next(params); }