mirror of
https://github.com/drasko/codezero.git
synced 2026-01-21 07:13:15 +01:00
Added the forgotten pyelf libraries
This commit is contained in:
36
tools/pyelf/lmanext.py
Normal file
36
tools/pyelf/lmanext.py
Normal file
@@ -0,0 +1,36 @@
|
||||
#! /usr/bin/env python2.6
|
||||
# -*- mode: python; coding: utf-8; -*-
|
||||
#
|
||||
# Codezero -- Virtualization microkernel for embedded systems.
|
||||
#
|
||||
# Copyright © 2009 B Labs Ltd
|
||||
#
|
||||
import os, sys
|
||||
from optparse import OptionParser
|
||||
from os.path import join
|
||||
from os import path
|
||||
import elf, sys
|
||||
|
||||
def conv_hex(val):
|
||||
hexval = hex(val)
|
||||
if hexval[-1:] == 'L':
|
||||
hexval = hexval[:-1]
|
||||
return hexval
|
||||
|
||||
def next_available_lma(srcfile):
|
||||
elffile = elf.ElfFile.from_file(srcfile)
|
||||
paddr_max = 0
|
||||
p_align = 0
|
||||
for pheader in elffile.pheaders:
|
||||
x = pheader.ai
|
||||
if str(x.p_type) == "LOAD":
|
||||
paddr = x.p_paddr + x.p_memsz
|
||||
p_align = x.p_align
|
||||
if paddr > paddr_max:
|
||||
paddr_max = paddr
|
||||
|
||||
paddr_aligned = paddr_max & ~(p_align.value - 1)
|
||||
if paddr_max & (p_align.value - 1):
|
||||
paddr_aligned += p_align.value
|
||||
return conv_hex(paddr_aligned)
|
||||
|
||||
Reference in New Issue
Block a user