diff options
author | Jaewon Lee <jaewon.lee@xilinx.com> | 2019-07-22 17:03:36 -0700 |
---|---|---|
committer | Sai Hari Chandana Kalluri <chandana.kalluri@xilinx.com> | 2019-12-13 13:27:17 -0800 |
commit | b24c7727082c671140cf5029a7082649f037d4cd (patch) | |
tree | ace309e407bf3ac7332aff49b49a3f516a0d1971 | |
parent | 88b23d48026a49f2b6966832ec90651aa0f26af6 (diff) | |
download | meta-xilinx-b24c7727082c671140cf5029a7082649f037d4cd.tar.gz |
flashstrip utility: Build and ship flash strip utility needed for qemu
Building and shipping flash strip utility needed for qemu:
flash_strip
flash_strip_bw
flash_unstrip
flash_unstrip_bw
From the QEMU flash strip utilities wiki:
QSPI Controllers implement byte/bit strip logic. Which mean's when an
image is flashed, its stripped bit/byte wise into two flashes. User can
use u-boot or Linux apps to flash the image after boot. By using flash
strip utilities, we can flash the image without using u-boot.
Signed-off-by: Jaewon Lee <jaewon.lee@xilinx.com>
Signed-off-by: Manjukumar Matha <manjukumar.harthikote-matha@xilinx.com>
-rw-r--r-- | meta-xilinx-bsp/recipes-devtools/qemu/files/flash_stripe.c | 176 | ||||
-rw-r--r-- | meta-xilinx-bsp/recipes-devtools/qemu/flashstrip_1.0.bb | 25 |
2 files changed, 201 insertions, 0 deletions
diff --git a/meta-xilinx-bsp/recipes-devtools/qemu/files/flash_stripe.c b/meta-xilinx-bsp/recipes-devtools/qemu/files/flash_stripe.c new file mode 100644 index 00000000..a9a6e76a --- /dev/null +++ b/meta-xilinx-bsp/recipes-devtools/qemu/files/flash_stripe.c | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Stripe a flash image across multiple files. | ||
3 | * | ||
4 | * Copyright (C) 2019 Xilinx, Inc. All rights reserved. | ||
5 | * | ||
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | * of this software and associated documentation files (the "Software"), to deal | ||
8 | * in the Software without restriction, including without limitation the rights | ||
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | * copies of the Software, and to permit persons to whom the Software is | ||
11 | * furnished to do so, subject to the following conditions: | ||
12 | * | ||
13 | * The above copyright notice and this permission notice shall be included in all | ||
14 | * copies or substantial portions of the Software. | ||
15 | * | ||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
22 | * SOFTWARE. | ||
23 | */ | ||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <stdint.h> | ||
28 | #include <stdbool.h> | ||
29 | #include <unistd.h> | ||
30 | #include <sys/types.h> | ||
31 | #include <sys/stat.h> | ||
32 | #include <fcntl.h> | ||
33 | #include <string.h> | ||
34 | |||
35 | /* N way (num) in place bit striper. Lay out row wise bits column wise | ||
36 | * (from element 0 to N-1). num is the length of x, and dir reverses the | ||
37 | * direction of the transform. be determines the bit endianess scheme. | ||
38 | * false to lay out bits LSB to MSB (little endian) and true for big endian. | ||
39 | * | ||
40 | * Best illustrated by examples: | ||
41 | * Each digit in the below array is a single bit (num == 3, be == false): | ||
42 | * | ||
43 | * {{ 76543210, } ----- stripe (dir == false) -----> {{ FCheb630, } | ||
44 | * { hgfedcba, } { GDAfc741, } | ||
45 | * { HGFEDCBA, }} <---- upstripe (dir == true) ----- { HEBgda52, }} | ||
46 | * | ||
47 | * Same but with be == true: | ||
48 | * | ||
49 | * {{ 76543210, } ----- stripe (dir == false) -----> {{ 741gdaFC, } | ||
50 | * { hgfedcba, } { 630fcHEB, } | ||
51 | * { HGFEDCBA, }} <---- upstripe (dir == true) ----- { 52hebGDA, }} | ||
52 | */ | ||
53 | |||
54 | static inline void stripe8(uint8_t *x, int num, bool dir, bool be) | ||
55 | { | ||
56 | uint8_t r[num]; | ||
57 | memset(r, 0, sizeof(uint8_t) * num); | ||
58 | int idx[2] = {0, 0}; | ||
59 | int bit[2] = {0, be ? 7 : 0}; | ||
60 | int d = dir; | ||
61 | |||
62 | for (idx[0] = 0; idx[0] < num; ++idx[0]) { | ||
63 | for (bit[0] = be ? 7 : 0; bit[0] != (be ? -1 : 8); bit[0] += be ? -1 : 1) { | ||
64 | r[idx[!d]] |= x[idx[d]] & 1 << bit[d] ? 1 << bit[!d] : 0; | ||
65 | idx[1] = (idx[1] + 1) % num; | ||
66 | if (!idx[1]) { | ||
67 | bit[1] += be ? -1 : 1; | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | memcpy(x, r, sizeof(uint8_t) * num); | ||
72 | } | ||
73 | |||
74 | int main (int argc, char *argv []) { | ||
75 | #ifdef UNSTRIPE | ||
76 | bool unstripe = true; | ||
77 | #else | ||
78 | bool unstripe = false; | ||
79 | #endif | ||
80 | |||
81 | #ifdef FLASH_STRIPE_BE | ||
82 | bool be = true; | ||
83 | #else | ||
84 | bool be = false; | ||
85 | #endif | ||
86 | |||
87 | int i; | ||
88 | |||
89 | const char *exe_name = argv[0]; | ||
90 | argc--; | ||
91 | argv++; | ||
92 | |||
93 | if (argc < 2) { | ||
94 | fprintf(stderr, "ERROR: %s requires at least two args\n", exe_name); | ||
95 | return 1; | ||
96 | } | ||
97 | |||
98 | const char *single_f = argv[0]; | ||
99 | int single; | ||
100 | |||
101 | if (unstripe) { | ||
102 | single = creat(single_f, 0644); | ||
103 | } else { | ||
104 | single = open(single_f, 0); | ||
105 | } | ||
106 | if (single == -1) { | ||
107 | perror(argv[0]); | ||
108 | return 1; | ||
109 | } | ||
110 | |||
111 | argv++; | ||
112 | argc--; | ||
113 | |||
114 | int multiple[argc]; | ||
115 | |||
116 | for (i = 0; i < argc; ++i) { | ||
117 | if (unstripe) { | ||
118 | multiple[i] = open(argv[i], 0); | ||
119 | } else { | ||
120 | multiple[i] = creat(argv[i], 0644); | ||
121 | } | ||
122 | if (multiple[i] == -1) { | ||
123 | perror(argv[i]); | ||
124 | return 1; | ||
125 | } | ||
126 | } | ||
127 | |||
128 | while (true) { | ||
129 | uint8_t buf[argc]; | ||
130 | for (i = 0; i < argc; ++i) { | ||
131 | switch (read(!unstripe ? single : multiple[ | ||
132 | #if defined(FLASH_STRIPE_BW) && defined (FLASH_STRIPE_BE) | ||
133 | argc - 1 - | ||
134 | #endif | ||
135 | i], &buf[i], 1)) { | ||
136 | case 0: | ||
137 | if (i == 0) { | ||
138 | goto done; | ||
139 | } else if (!unstripe) { | ||
140 | fprintf(stderr, "WARNING:input file %s is not multiple of " | ||
141 | "%d bytes, padding with garbage byte\n", single_f, | ||
142 | argc); | ||
143 | } | ||
144 | break; | ||
145 | case -1: | ||
146 | perror(unstripe ? argv[i] : single_f); | ||
147 | return 1; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | #ifndef FLASH_STRIPE_BW | ||
152 | stripe8(buf, argc, unstripe, be); | ||
153 | #endif | ||
154 | |||
155 | for (i = 0; i < argc; ++i) { | ||
156 | switch (write(unstripe ? single : multiple[ | ||
157 | #if defined(FLASH_STRIPE_BW) && defined (FLASH_STRIPE_BE) | ||
158 | argc - 1 - | ||
159 | #endif | ||
160 | i], &buf[i], 1)) { | ||
161 | case -1: | ||
162 | perror(unstripe ? single_f : argv[i]); | ||
163 | return 1; | ||
164 | case 0: | ||
165 | i--; /* try again */ | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | |||
170 | done: | ||
171 | close(single); | ||
172 | for (i = 0; i < argc; ++i) { | ||
173 | close(multiple[argc]); | ||
174 | } | ||
175 | return 0; | ||
176 | } | ||
diff --git a/meta-xilinx-bsp/recipes-devtools/qemu/flashstrip_1.0.bb b/meta-xilinx-bsp/recipes-devtools/qemu/flashstrip_1.0.bb new file mode 100644 index 00000000..eec7b2da --- /dev/null +++ b/meta-xilinx-bsp/recipes-devtools/qemu/flashstrip_1.0.bb | |||
@@ -0,0 +1,25 @@ | |||
1 | SUMMARY = "Building and installing flash strip utility" | ||
2 | DESCRIPTION = "Building and installing flash strip utility" | ||
3 | |||
4 | LICENSE = "MIT" | ||
5 | LIC_FILES_CHKSUM = "file://../flash_stripe.c;beginline=1;endline=23;md5=abb859d98b7c4eede655e1b71824125a" | ||
6 | |||
7 | B = "${WORKDIR}/build" | ||
8 | |||
9 | SRC_URI += "file://flash_stripe.c" | ||
10 | |||
11 | TARGET_CC_ARCH += "${LDFLAGS}" | ||
12 | |||
13 | do_compile() { | ||
14 | ${CC} ${WORKDIR}/flash_stripe.c -o flash_strip | ||
15 | ${CC} ${WORKDIR}/flash_stripe.c -o flash_unstrip | ||
16 | ${CC} ${WORKDIR}/flash_stripe.c -o flash_strip_bw -DFLASH_STRIPE_BW | ||
17 | ${CC} ${WORKDIR}/flash_stripe.c -o flash_unstrip_bw -DUNSTRIP -DFLASH_STRIPE_BW | ||
18 | } | ||
19 | |||
20 | do_install() { | ||
21 | install -d ${D}${bindir} | ||
22 | install -Dm 0755 ${B}/* ${D}${bindir}/ | ||
23 | } | ||
24 | |||
25 | FILES_${PN} = "${bindir}/*" | ||