aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/srecimage.pl
blob: b9e2a843bfcf7b862474dd37e438fc0636184649 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env perl
#
# srecimage.pl - script to convert a binary image into srec
# Copyright (c) 2015 - Jo-Philipp Wich <jo@mein.io>
#
# This script is in the public domain.

use strict;

my ($input, $output, $offset) = @ARGV;

if (!defined($input) || !-f $input || !defined($output) ||
    !defined($offset) || $offset !~ /^(0x)?[a-fA-F0-9]+$/) {
	die "Usage: $0 <input file> <output file> <load address>\n";
}

sub srec
{
	my ($type, $addr, $data, $len) = @_;
	my @addrtypes = qw(%04X %04X %06X %08X %08X %04X %06X %08X %06X %04X);
	my $addrstr = sprintf $addrtypes[$type], $addr;

	$len = length($data) if ($len <= 0);
	$len += 1 + (length($addrstr) / 2);

	my $sum = $len;

	foreach my $byte (unpack('C*', pack('H*', $addrstr)), unpack('C*', $data))
	{
		$sum += $byte;
	}

	return sprintf "S%d%02X%s%s%02X\r\n",
	       $type, $len, $addrstr, uc(unpack('H*', $data)), ~($sum & 0xFF) & 0xFF;
}


open(IN, '<:raw', $input) || die "Unable to open $input: $!\n";
open(OUT, '>:raw', $output) || die "Unable to open $output: $!\n";

my ($basename) = $output =~ m!([^/]+)$!;

print OUT srec(0, 0, $basename, 0);

my $off = hex($offset);
my $len;

while (defined($len = read(IN, my $buf, 16)) && $len > 0)
{
	print OUT srec(3, $off, $buf, $len);
	$off += $len;
}

print OUT srec(7, hex($offset), "", 0);

close OUT;
close IN;
mod->name); } +#endif /* Set up license info based on the info section */ set_license(mod, get_modinfo(info, "license")); --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1740,7 +1740,9 @@ static void read_symbols(char *modname) symname = info.strtab + sym->st_name; handle_modversions(mod, &info, sym, symname); +#ifndef CONFIG_MODULE_STRIPPED handle_moddevtable(mod, &info, sym, symname); +#endif } if (!is_vmlinux(modname) || (is_vmlinux(modname) && vmlinux_section_warnings)) @@ -1884,7 +1886,9 @@ static void add_header(struct buffer *b, buf_printf(b, "#include <linux/vermagic.h>\n"); buf_printf(b, "#include <linux/compiler.h>\n"); buf_printf(b, "\n"); +#ifndef CONFIG_MODULE_STRIPPED buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); +#endif buf_printf(b, "\n"); buf_printf(b, "struct module __this_module\n"); buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n"); @@ -1901,16 +1905,20 @@ static void add_header(struct buffer *b, static void add_intree_flag(struct buffer *b, int is_intree) { +#ifndef CONFIG_MODULE_STRIPPED if (is_intree) buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); +#endif } static void add_staging_flag(struct buffer *b, const char *name) { +#ifndef CONFIG_MODULE_STRIPPED static const char *staging_dir = "drivers/staging"; if (strncmp(staging_dir, name, strlen(staging_dir)) == 0) buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); +#endif } /** @@ -2003,11 +2011,13 @@ static void add_depends(struct buffer *b static void add_srcversion(struct buffer *b, struct module *mod) { +#ifndef CONFIG_MODULE_STRIPPED if (mod->srcversion[0]) { buf_printf(b, "\n"); buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", mod->srcversion); } +#endif } static void write_if_changed(struct buffer *b, const char *fname) @@ -2233,7 +2243,9 @@ int main(int argc, char **argv) add_staging_flag(&buf, mod->name); err |= add_versions(&buf, mod); add_depends(&buf, mod, modules); +#ifndef CONFIG_MODULE_STRIPPED add_moddevtable(&buf, mod); +#endif add_srcversion(&buf, mod); sprintf(fname, "%s.mod.c", mod->name);