Commit 4e0064bc authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

Simple code in tools/lcd/blob for building/running blob in lcd.

After building and installing kernel, and building/inserting lcd
modules, update assembly in blob.S, and exec make in tools/lcd/blob.
This will build blob.S, create the appropriate format and size
image, and run it in an lcd.
parent 7934847d
run: blob-run blob
./blob-run blob $(python blob-size.py blob.bin -o)
blob-run: blob-run.c
gcc $^ -o $@
blob: blob.S
as blob.S -o blob.bin &&
objdump --output-target=binary \
--pad-to=$(python blob-size.py blob.bin -s) blob.bin blob
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/lcd-domains.h>
int do_mmap(FILE *f, size_t order, unsigned char **blob_addr_out)
{
void *ret;
size_t len;
len = (1 << size) * PAGE_SIZE;
ret = mmap(NULL, len,
PROT_EXEC | PROT_READ | PROT_WRITE,
MAP_ANONYMOUS, fileno(f), 0);
if (ret == MAP_FAILED) {
return -1;
}
*blob_addr_out = (unsigned char *)ret;
return 0;
}
void usage(void)
{
fprintf(stderr, "blob: usage: ./blob <blob fname> <blob order>\n");
fprintf(stderr, " blob should be 2^(blob order) pages\n");
exit(1);
}
int main(int argc, char *argv[])
{
int ret;
struct lcd_blob_info bi;
char *fname;
int order;
FILE *f;
/*
* Get blob file name
*/
if (argc != 3) {
usage();
}
fname = argv[1];
order = atoi(argv[2]);
/*
* Open and map blob
*/
f = fopen(fname, "r");
if (!f) {
fprintf(stderr, "blob: error opening file %s\n",
fname);
exit(-1);
}
if (do_mmap(f, size, &(bi.blob))) {
fprintf(stderr, "blob: error mapping file %s\n",
fname);
fclose(f);
exit(-1);
}
bi.blob_order = order;
/*
* Run in lcd
*/
ret = ioctl(LCD_MINOR, LCD_RUN_BLOB, &bi);
if (ret) {
printf("blob: ioctl returned error %d\n", ret);
return -1;
}
return 0;
}
# quick script for calc of final blob size with padding to proper number
# of pages
import sys
import shutil
import math
import os
if len(sys.argv) != 3:
sys.stderr.write("blob-size.py: usage: python blob-size.py <blob fname> -{s,o}\n use s for size in bytes, o for order (the output file will be 2^o pages)")
sys.exit(-1)
bfname = sys.argv[1]
npages = (os.path.getsize(bfname) + 4095) / 4096
order = int(math.log(npages, 2))
if 2 ** order != npages:
order += 1
if sys.argv[2] == "-s":
print str(int((2 ** order) * 4096))
else if sys.argv[2] == "-o":
print str(int(order))
else:
sys.stderr.write("blob-size.py: unexpected second option " + sys.argv[2] + "\n")
exit(-1)
.text
;; code goes here
;; no mem accesses allowed for now
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/lcd-domains.h>
int do_mmap(FILE *f, size_t order, unsigned char **blob_addr_out)
{
void *ret;
size_t len;
len = (1 << size) * PAGE_SIZE;
ret = mmap(NULL, len,
PROT_EXEC | PROT_READ | PROT_WRITE,
MAP_ANONYMOUS, fileno(f), 0);
if (ret == MAP_FAILED) {
return -1;
}
*blob_addr_out = (unsigned char *)ret;
return 0;
}
void usage(void)
{
fprintf(stderr, "blob: usage: ./blob <blob fname> <blob order>\n");
fprintf(stderr, " blob should be 2^(blob order) pages\n");
exit(1);
}
int main(int argc, char *argv[])
{
int ret;
struct lcd_blob_info bi;
char *fname;
int order;
FILE *f;
/*
* Get blob file name
*/
if (argc != 3) {
usage();
}
fname = argv[1];
order = atoi(argv[2]);
/*
* Open and map blob
*/
f = fopen(fname, "r");
if (!f) {
fprintf(stderr, "blob: error opening file %s\n",
fname);
exit(-1);
}
if (do_mmap(f, size, &(bi.blob))) {
fprintf(stderr, "blob: error mapping file %s\n",
fname);
fclose(f);
exit(-1);
}
bi.blob_order = order;
/*
* Run in lcd
*/
ret = ioctl(LCD_MINOR, LCD_RUN_BLOB, &bi);
if (ret) {
printf("blob: ioctl returned error %d\n", ret);
return -1;
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment