Commit bef63db9 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Grzegorz Daniluk

dev/ep-pfilter: removed another special linker section and changed for an…

dev/ep-pfilter: removed another special linker section and changed for an autogenerated header. Makefile needs to be fixed, though!
parent 0038dbd7
......@@ -71,14 +71,10 @@ arch-files-$(CONFIG_LM32) = $(OUTPUT).bram $(OUTPUT).vhd $(OUTPUT).mif
# packet-filter rules: for CONFIG_VLAN we use both sets
pfilter-y := rules-novlan.bin
pfilter-$(CONFIG_VLAN) += rules-vlan.bin
pfilter-y := include/dev/pfilter-rules-novlan.h
pfilter-$(CONFIG_VLAN) += include/dev/pfilter-rules-vlan.h
export pfilter-y
# sdbfs image
sdbfsimg-y := sdbfs-default.bin
export sdbfsimg-y
all:
include boards/boards.mk
......
......@@ -67,8 +67,4 @@ SECTIONS
/* This may be missing, according to .config */
PROVIDE(fifo_log = 0);
/* A vlan rule-set may be missing (if no CONFIG_VLAN) */
PROVIDE(_binary_rules_vlan_bin_start = 0);
PROVIDE(_binary_rules_vlan_bin_end = 0);
}
......@@ -50,16 +50,10 @@ obj-$(CONFIG_FAKE_TEMPERATURES) += dev/fake-temp.o
# Filter rules are selected according to configuration, but we may
# have more than one. Note: the filename is reflected in symbol names,
# so they are hardwired in ../Makefile (and ../tools/pfilter-builder too)
obj-y += $(pfilter-y:.bin=.o)
rules-%.o: rules-%.bin
$(OBJCOPY) -I binary $(OBJCOPY-TARGET-y) $< $@
# sdbfs image
obj-y += $(sdbfsimg-y:.bin=.o)
sdbfs-default.o: tools/sdbfs-default.bin
$(OBJCOPY) -I binary $(OBJCOPY-TARGET-y) $< $@
$(pfilter-y): tools
tools/pfilter-builder
./tools/pfilter-builder include/dev/
sleep 1
#dev/ep_pfilter.o: $(pfilter-y)
#@echo Building packet filter assemblies...
\ No newline at end of file
......@@ -20,21 +20,27 @@
#include <dev/endpoint.h>
#include <hw/endpoint_regs.h>
extern uint32_t _binary_rules_novlan_bin_start[];
extern uint32_t _binary_rules_novlan_bin_end[];
extern uint32_t _binary_rules_vlan_bin_start[];
extern uint32_t _binary_rules_vlan_bin_end[];
static const uint32_t pfilter_rules_novlan[] =
{
#include "dev/pfilter-rules-novlan.h"
};
static const uint32_t pfilter_rules_vlan[] =
{
#include "dev/pfilter-rules-vlan.h"
};
struct rule_set {
uint32_t *ini;
uint32_t *end;
const uint32_t *ini;
int size;
} rule_sets[2] = {
{
_binary_rules_novlan_bin_start,
_binary_rules_novlan_bin_end,
pfilter_rules_novlan,
ARRAY_SIZE(pfilter_rules_novlan)
}, {
_binary_rules_vlan_bin_start,
_binary_rules_vlan_bin_end,
pfilter_rules_vlan,
ARRAY_SIZE(pfilter_rules_vlan)
}
};
......@@ -69,8 +75,10 @@ void pfilter_init_default(void)
pp_printf("no pfilter rule-set!\n");
return;
}
pp_printf("vini %p size %d\n", vini, s->size);
vini = s->ini;
vend = s->end;
vend = s->ini + s->size;
/*
* The array of words starts with 0x11223344 so we
......
......@@ -335,40 +335,61 @@ static void pfilter_logic3(int rd, int ra, pfilter_op_t op, int rb,
}
/* Terminates the microcode, creating the output file */
static void pfilter_output(char *fname)
static void pfilter_output(char *dir, char *fname, int is_binary)
{
uint32_t v1, v2;
int i;
FILE *f;
char path[1024];
snprintf(path, sizeof(path), "%s/%s", dir, fname );
code_buf[code_pos++] = (1ULL << 35); // insert FIN instruction
f = fopen(fname, "w");
f = fopen(path, "w");
if (!f) {
fprintf(stderr, "%s: %s: %s\n", prgname, fname, strerror(errno));
exit(1);
}
printf("Writing: %s\n", path);
/* First write a magic word, so the target can check endianness */
v1 = 0x11223344;
fwrite(&v1, sizeof(v1), 1, f);
pfilter_dbg("Writing \"%s\"\n", fname);
for (i = 0; i < code_pos; i++) {
pfilter_dbg(" pos %02i: %x.%08x\n", i,
(uint32_t)(code_buf[i] >> 32),
(uint32_t)(code_buf[i]));
/* Explicitly write the LSB first */
v1 = code_buf[i];
v2 = code_buf[i] >> 32;
if(is_binary)
{
v1 = 0x11223344;
fwrite(&v1, sizeof(v1), 1, f);
fwrite(&v2, sizeof(v2), 1, f);
pfilter_dbg("Writing \"%s\"\n", fname);
for (i = 0; i < code_pos; i++) {
pfilter_dbg(" pos %02i: %x.%08x\n", i,
(uint32_t)(code_buf[i] >> 32),
(uint32_t)(code_buf[i]));
/* Explicitly write the LSB first */
v1 = code_buf[i];
v2 = code_buf[i] >> 32;
fwrite(&v1, sizeof(v1), 1, f);
fwrite(&v2, sizeof(v2), 1, f);
}
} else {
v1 = 0x11223344;
fprintf(f, "// generated by tools/pfilter-builder. don't hand-edit unless you know what you're doing...\n");
fprintf(f, "0x%08x, // magic ID\n", v1);\
for (i = 0; i < code_pos; i++) {
v1 = code_buf[i];
v2 = code_buf[i] >> 32;
fprintf(f, "0x%08x,\n", v1 );
fprintf(f, "0x%08x%c\n", v2, i == (code_pos - 1) ? ' ' : ',' );
}
fprintf(f, "\n\n");
}
fclose(f);
}
void pfilter_init_novlan(char *fname)
void pfilter_init_novlan(char *dir, char *fname, int is_binary)
{
pfilter_new();
pfilter_nop();
......@@ -452,11 +473,11 @@ void pfilter_init_novlan(char *fname)
* 0xebd0 go to the fabric by being part of the "anything else" choice".
*/
pfilter_output(fname);
pfilter_output(dir, fname, is_binary);
}
void pfilter_init_vlan(char *fname)
void pfilter_init_vlan(char *dir, char *fname, int is_binary)
{
pfilter_new();
pfilter_nop();
......@@ -523,14 +544,20 @@ void pfilter_init_vlan(char *fname)
pfilter_cmp(7, CONFIG_VLAN_FOR_CLASS6, 0x0fff, MOV, FRAME_OUR_VLAN);
pfilter_logic2(R_CLASS(6), R_TMP, AND, FRAME_OUR_VLAN);
pfilter_output(fname);
pfilter_output(dir, fname, is_binary);
}
int main(int argc, char **argv) /* no arguments used currently */
{
prgname = argv[0];
pfilter_init_novlan("rules-novlan.bin");
pfilter_init_vlan("rules-vlan.bin");
if( argc < 2 )
{
printf("usage: %s target_directory\n", prgname);
return -1;
}
pfilter_init_novlan(argv[1], "pfilter-rules-novlan.h", 0);
pfilter_init_vlan(argv[1], "pfilter-rules-vlan.h", 0);
exit(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